Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Claude Remote / Codex Remote9// File : Packages/ClaudeRemoteKit/Sources/ClaudeRemoteTerminal/TerminalTheme.swift10// Module : ClaudeRemoteTerminal11// Repository : https://git.spboucher.ai/claude-remote-apple12// Project Website : https://claude.spboucher.ai13// Created : 2026-11-2914// Last Modified : 2026-11-2915//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author : Simon-Pierre Boucher21// Position : Professor of Finance22// Institution : Université du Québec en Outaouais (UQO)23// Department : Département des sciences administratives24// Organization : SP Boucher25//26// Website : https://spboucher.ai27// Git : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General : info@spboucher.ai34// Professional : contact@spboucher.ai35// Direct : simon@spboucher.ai36// Research : research@spboucher.ai37// Development : dev@spboucher.ai38// Support : support@spboucher.ai39// Security/Admin : admin@spboucher.ai40// Notifications : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification : Public67// Distribution : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License : None specified (no license file in this repository)81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import ClaudeRemoteModels89import Foundation9091/// Colours of a terminal: default pair, cursor, selection and the 16 ANSI colours.92public struct TerminalTheme: Sendable, Hashable, Identifiable {93 public var id: String94 public var name: String95 public var isDark: Bool96 public var background: HexColor97 public var foreground: HexColor98 public var cursor: HexColor99 /// Colour of the glyph under a block cursor.100 public var cursorText: HexColor101 /// Selection fill (may be translucent).102 public var selection: HexColor103 /// black, red, green, yellow, blue, magenta, cyan, white, then the 8 bright variants.104 public var ansi: [HexColor]105 /// Lift low-contrast text (256 / true colour) to this ratio; 1 = leave colours untouched.106 public var minimumContrastRatio: Double107108 public init(id: String, name: String, isDark: Bool, background: UInt32, foreground: UInt32, cursor: UInt32, cursorText: UInt32? = nil,109 selection: HexColor, ansi: [UInt32], minimumContrastRatio: Double = 1) {110 precondition(ansi.count == 16, "a terminal theme has exactly 16 ANSI colours")111 self.id = id112 self.name = name113 self.isDark = isDark114 self.background = HexColor(background)115 self.foreground = HexColor(foreground)116 self.cursor = HexColor(cursor)117 self.cursorText = HexColor(cursorText ?? background)118 self.selection = selection119 self.ansi = ansi.map { HexColor($0) }120 self.minimumContrastRatio = minimumContrastRatio121 }122123 // MARK: Web palettes (apps/web/src/components/terminal/controller.ts, TERM_THEMES)124125 /// The web application's dark terminal palette (Claude accent).126 public static let claudeRemoteDark = TerminalTheme(127 id: "cr-dark", name: "Remote Dark", isDark: true, background: 0x080B10, foreground: 0xF4F7FB, cursor: 0x8F8FFF, cursorText: 0x080B10,128 selection: HexColor(0x8F8FFF, alpha: Double(0x59) / 255),129 ansi: [0x161D27, 0xED7777, 0x42C995, 0xE7B86B, 0x729FFF, 0xB692F6, 0x5CC6D6, 0xA1ADBD,130 0x7F8CA0, 0xF59C9C, 0x72DDB4, 0xF1CF95, 0x9DBCFF, 0xCDB4FA, 0x8DDCE8, 0xF4F7FB],131 minimumContrastRatio: 4.5)132133 /// The web application's light terminal palette (every ANSI colour ≥ 4.5:1 on its background).134 public static let claudeRemoteLight = TerminalTheme(135 id: "cr-light", name: "Remote Light", isDark: false, background: 0xFCFCFA, foreground: 0x1F2328, cursor: 0x5151E8, cursorText: 0xFCFCFA,136 selection: HexColor(0x5151E8, alpha: Double(0x38) / 255),137 ansi: [0x24292F, 0xC4232D, 0x116329, 0x7D4E00, 0x0860C7, 0x7C3FD6, 0x0F6E75, 0x57606A,138 0x636C76, 0xA40E26, 0x1A7F37, 0x8F5F00, 0x0550AE, 0x6639BA, 0x0B5D63, 0x3D444D],139 minimumContrastRatio: 4.5)140141 /// The web palette for a theme, with the cursor / selection accent of the instance's agent142 /// (Codex: teal instead of indigo).143 public static func web(dark: Bool, agent: AgentID = .claude) -> TerminalTheme {144 var theme = dark ? claudeRemoteDark : claudeRemoteLight145 if agent == .codex {146 theme.id = dark ? "cr-dark-codex" : "cr-light-codex"147 theme.cursor = HexColor(dark ? 0x2DD4BF : 0x0B7268)148 theme.selection = dark ? HexColor(0x2DD4BF, alpha: Double(0x4D) / 255) : HexColor(0x0B7268, alpha: Double(0x38) / 255)149 }150 return theme151 }152153 // MARK: Extras154155 public static let solarizedDark = TerminalTheme(156 id: "solarized-dark", name: "Solarized Dark", isDark: true, background: 0x002B36, foreground: 0x839496, cursor: 0x93A1A1,157 selection: HexColor(0x073642),158 ansi: [0x073642, 0xDC322F, 0x859900, 0xB58900, 0x268BD2, 0xD33682, 0x2AA198, 0xEEE8D5,159 0x586E75, 0xCB4B16, 0x93A1A1, 0x657B83, 0x839496, 0x6C71C4, 0x93A1A1, 0xFDF6E3])160161 public static let solarizedLight = TerminalTheme(162 id: "solarized-light", name: "Solarized Light", isDark: false, background: 0xFDF6E3, foreground: 0x657B83, cursor: 0x586E75,163 selection: HexColor(0xEEE8D5),164 ansi: [0x073642, 0xDC322F, 0x859900, 0xB58900, 0x268BD2, 0xD33682, 0x2AA198, 0xEEE8D5,165 0x002B36, 0xCB4B16, 0x586E75, 0x657B83, 0x839496, 0x6C71C4, 0x93A1A1, 0xFDF6E3])166167 public static let dracula = TerminalTheme(168 id: "dracula", name: "Dracula", isDark: true, background: 0x282A36, foreground: 0xF8F8F2, cursor: 0xF8F8F2,169 selection: HexColor(0x44475A),170 ansi: [0x21222C, 0xFF5555, 0x50FA7B, 0xF1FA8C, 0xBD93F9, 0xFF79C6, 0x8BE9FD, 0xF8F8F2,171 0x6272A4, 0xFF6E6E, 0x69FF94, 0xFFFFA5, 0xD6ACFF, 0xFF92DF, 0xA4FFFF, 0xFFFFFF])172173 public static let nord = TerminalTheme(174 id: "nord", name: "Nord", isDark: true, background: 0x2E3440, foreground: 0xD8DEE9, cursor: 0xD8DEE9,175 selection: HexColor(0x434C5E),176 ansi: [0x3B4252, 0xBF616A, 0xA3BE8C, 0xEBCB8B, 0x81A1C1, 0xB48EAD, 0x88C0D0, 0xE5E9F0,177 0x4C566A, 0xBF616A, 0xA3BE8C, 0xEBCB8B, 0x81A1C1, 0xB48EAD, 0x8FBCBB, 0xECEFF4])178179 public static let gitHubDark = TerminalTheme(180 id: "github-dark", name: "GitHub Dark", isDark: true, background: 0x0D1117, foreground: 0xE6EDF3, cursor: 0x2F81F7,181 selection: HexColor(0x264F78),182 ansi: [0x484F58, 0xFF7B72, 0x3FB950, 0xD29922, 0x58A6FF, 0xBC8CFF, 0x39C5CF, 0xB1BAC4,183 0x6E7681, 0xFFA198, 0x56D364, 0xE3B341, 0x79C0FF, 0xD2A8FF, 0x56D4DD, 0xFFFFFF])184185 public static let oneDark = TerminalTheme(186 id: "one-dark", name: "One Dark", isDark: true, background: 0x282C34, foreground: 0xABB2BF, cursor: 0x528BFF,187 selection: HexColor(0x3E4451),188 ansi: [0x282C34, 0xE06C75, 0x98C379, 0xE5C07B, 0x61AFEF, 0xC678DD, 0x56B6C2, 0xABB2BF,189 0x5C6370, 0xE06C75, 0x98C379, 0xE5C07B, 0x61AFEF, 0xC678DD, 0x56B6C2, 0xFFFFFF])190191 /// Every built-in theme (web palettes of both agents first).192 public static let all: [TerminalTheme] = [193 .claudeRemoteDark, .claudeRemoteLight, .web(dark: true, agent: .codex), .web(dark: false, agent: .codex),194 .solarizedDark, .solarizedLight, .dracula, .nord, .gitHubDark, .oneDark,195 ]196197 public static func theme(id: String) -> TerminalTheme? { all.first { $0.id == id } }198199 /// Theme for the shared user setting: `auto` follows the app appearance.200 public static func resolve(_ preference: TerminalThemePreference, systemIsDark: Bool, agent: AgentID = .claude) -> TerminalTheme {201 switch preference {202 case .light: return web(dark: false, agent: agent)203 case .dark: return web(dark: true, agent: agent)204 default: return web(dark: systemIsDark, agent: agent)205 }206 }207}208209public enum TerminalCursorShape: String, Sendable, Hashable, CaseIterable, Codable {210 case block, underline, bar211}212213/// Everything that decides how a terminal looks. Apply with `TerminalSessionController.apply(_:)`.214public struct TerminalAppearance: Sendable, Hashable {215 /// Preferred font family; falls back to the system monospaced font when not installed.216 public var fontName: String217 public var fontSize: Double218 /// Line height multiplier (1 = the font's natural line height; the web uses 1.15).219 public var lineSpacing: Double220 public var theme: TerminalTheme221 public var cursorShape: TerminalCursorShape222 public var cursorBlink: Bool223 /// Scrollback lines kept by the emulator.224 public var scrollback: Int225 /// Option / Alt sends ESC-prefixed characters (hardware keyboards).226 public var optionAsMeta: Bool227228 public init(fontName: String = "JetBrains Mono", fontSize: Double = 13, lineSpacing: Double = 1.15, theme: TerminalTheme = .claudeRemoteDark,229 cursorShape: TerminalCursorShape = .bar, cursorBlink: Bool = true, scrollback: Int = 5000, optionAsMeta: Bool = true) {230 self.fontName = fontName231 self.fontSize = min(max(fontSize, 6), 48)232 self.lineSpacing = min(max(lineSpacing, 0.8), 2)233 self.theme = theme234 self.cursorShape = cursorShape235 self.cursorBlink = cursorBlink236 self.scrollback = min(max(scrollback, 100), 100_000)237 self.optionAsMeta = optionAsMeta238 }239240 /// Appearance from the settings shared with the web application.241 /// - Parameter compact: phone-sized layout (uses `mobileFontSize`).242 public init(settings: UserSettings, agent: AgentID = .claude, systemIsDark: Bool, compact: Bool = false) {243 self.init(fontName: settings.terminalFont, fontSize: compact ? settings.mobileFontSize : settings.terminalFontSize,244 theme: .resolve(settings.terminalTheme, systemIsDark: systemIsDark, agent: agent), scrollback: settings.scrollback)245 }246247 /// Font families tried in order for a preferred name.248 public static func fontCandidates(preferred: String) -> [String] {249 var list = [preferred, "JetBrains Mono", "JetBrainsMono Nerd Font", "SF Mono", "Menlo"]250 list.removeAll { $0.trimmingCharacters(in: .whitespaces).isEmpty }251 var seen = Set<String>()252 return list.filter { seen.insert($0.lowercased()).inserted }253 }254}255