restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -0,0 +1,291 @@
import Foundation
/// The view a changed file opens in. Raw values are what config files on disk hold;
/// an unknown value, such as an older config's "original", falls back to `.updated`.
public enum DefaultDiffMode: String, Codable, Sendable, CaseIterable {
case updated
case diff
}
/// Soft wrap of long lines: never, always, or only in Markdown files.
public enum WordWrap: String, Codable, Sendable, CaseIterable {
case off
case on
case markdown
}
public enum TerminalCursorStyle: String, Codable, Sendable, CaseIterable {
case bar
case block
case underline
}
/// The terminal colour table. Every value is a CSS colour string; only the selection entries may carry alpha.
public struct TerminalTheme: Codable, Sendable, Equatable {
public var background = "#101720"
public var foreground = "#E4E7E6"
public var cursor = "#E8913A"
public var cursorAccent = "#101720"
public var selectionBackground = "rgba(232,145,58,0.22)"
public var selectionInactiveBackground = "rgba(232,145,58,0.12)"
public var black = "#232C39"
public var red = "#C4741F"
public var green = "#8FBFB4"
public var yellow = "#F0B476"
public var blue = "#8FA9C4"
public var magenta = "#C3A6CE"
public var cyan = "#8FC4C4"
public var white = "#BAC0C0"
public var brightBlack = "#6C7783"
public var brightRed = "#E8913A"
public var brightGreen = "#A6D2C7"
public var brightYellow = "#F5C79A"
public var brightBlue = "#A9BFD6"
public var brightMagenta = "#D6BFDF"
public var brightCyan = "#A9D6D6"
public var brightWhite = "#F4F5F4"
public init() {}
/// The sixteen ANSI colours in SGR order (black … brightWhite).
public var ansi: [String] {
[black, red, green, yellow, blue, magenta, cyan, white,
brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite]
}
}
/// Effective project settings: `.helder/config.json` merged key by key over these defaults.
public struct HelderConfig: Codable, Sendable, Equatable {
public struct AI: Codable, Sendable, Equatable {
public var command = "claude"
public var autoLaunch = true
public init() {}
}
public struct Editor: Codable, Sendable, Equatable {
public var autoSave = false
public var tabSize = 4
public var wordWrap = WordWrap.markdown
public init() {}
}
public struct Git: Codable, Sendable, Equatable {
public var confirmDiscard = true
public var confirmStage = false
public var confirmUnstage = false
public var defaultDiffMode = DefaultDiffMode.updated
/// Milliseconds between git status polls; 0 disables the poll.
public var refreshInterval = 10_000
public init() {}
}
public struct Files: Codable, Sendable, Equatable {
/// Extra ripgrep globs to leave out of the tree and the search.
public var exclude: [String] = []
/// False on purpose: the tree and the search show git-ignored files such as `.env` unless a project opts in.
public var followGitignore = false
public init() {}
}
public struct Terminal: Codable, Sendable, Equatable {
/// Login shell for both panes; nil means `$SHELL`.
public var shell: String?
/// nil means the bundled IBM Plex Mono.
public var fontFamily: String?
/// nil means the Typography default for terminals.
public var fontSize: Double?
public var lineHeight = 1.7
public var letterSpacing = 0.0
public var cursorStyle = TerminalCursorStyle.bar
public var cursorBlink = true
/// Off keeps bold text in its own hue, so a CLI's bold labels do not wash out.
public var boldIsBright = false
public var scrollback = 8000
/// Needed for a CLI's ⌥↵ binding, but it stops Option from typing accents, hence off.
public var optionIsMeta = false
public var theme = TerminalTheme()
public init() {}
}
public struct Session: Codable, Sendable, Equatable {
public var restoreOnLaunch = true
public init() {}
}
public var ai = AI()
public var editor = Editor()
public var git = Git()
public var files = Files()
public var terminal = Terminal()
public var session = Session()
public init() {}
public static let defaults = HelderConfig()
}
// MARK: - Tolerant decoding
//
// A key that is missing, null or of the wrong type keeps its default, so a
// sparse or half-broken config.json never throws the whole file away.
extension KeyedDecodingContainer {
fileprivate func value<T: Decodable>(_ key: Key, _ fallback: T) -> T {
(try? decodeIfPresent(T.self, forKey: key)) ?? fallback
}
/// For optional settings, where an explicit `null` means "use the default behaviour".
fileprivate func optional<T: Decodable>(_ key: Key, _ fallback: T?) -> T? {
guard contains(key) else { return fallback }
if (try? decodeNil(forKey: key)) == true { return nil }
return (try? decode(T.self, forKey: key)) ?? fallback
}
}
extension HelderConfig {
private enum CodingKeys: String, CodingKey { case ai, editor, git, files, terminal, session }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = HelderConfig.defaults
ai = c.value(.ai, d.ai)
editor = c.value(.editor, d.editor)
git = c.value(.git, d.git)
files = c.value(.files, d.files)
terminal = c.value(.terminal, d.terminal)
session = c.value(.session, d.session)
}
}
extension HelderConfig.AI {
private enum CodingKeys: String, CodingKey { case command, autoLaunch }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = Self()
command = c.value(.command, d.command)
autoLaunch = c.value(.autoLaunch, d.autoLaunch)
}
}
extension HelderConfig.Editor {
private enum CodingKeys: String, CodingKey { case autoSave, tabSize, wordWrap }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = Self()
autoSave = c.value(.autoSave, d.autoSave)
tabSize = c.value(.tabSize, d.tabSize)
wordWrap = c.value(.wordWrap, d.wordWrap)
}
}
extension HelderConfig.Git {
private enum CodingKeys: String, CodingKey {
case confirmDiscard, confirmStage, confirmUnstage, defaultDiffMode, refreshInterval
}
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = Self()
confirmDiscard = c.value(.confirmDiscard, d.confirmDiscard)
confirmStage = c.value(.confirmStage, d.confirmStage)
confirmUnstage = c.value(.confirmUnstage, d.confirmUnstage)
defaultDiffMode = c.value(.defaultDiffMode, d.defaultDiffMode)
refreshInterval = c.value(.refreshInterval, d.refreshInterval)
}
}
extension HelderConfig.Files {
private enum CodingKeys: String, CodingKey { case exclude, followGitignore }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = Self()
exclude = c.value(.exclude, d.exclude)
followGitignore = c.value(.followGitignore, d.followGitignore)
}
}
extension HelderConfig.Terminal {
private enum CodingKeys: String, CodingKey {
case shell, fontFamily, fontSize, lineHeight, letterSpacing, cursorStyle
case cursorBlink, boldIsBright, scrollback, optionIsMeta, theme
}
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = Self()
shell = c.optional(.shell, d.shell)
fontFamily = c.optional(.fontFamily, d.fontFamily)
fontSize = c.optional(.fontSize, d.fontSize)
lineHeight = c.value(.lineHeight, d.lineHeight)
letterSpacing = c.value(.letterSpacing, d.letterSpacing)
cursorStyle = c.value(.cursorStyle, d.cursorStyle)
cursorBlink = c.value(.cursorBlink, d.cursorBlink)
boldIsBright = c.value(.boldIsBright, d.boldIsBright)
scrollback = c.value(.scrollback, d.scrollback)
optionIsMeta = c.value(.optionIsMeta, d.optionIsMeta)
theme = c.value(.theme, d.theme)
}
/// Writes explicit nulls, because config.default.json documents every key.
public func encode(to encoder: Encoder) throws {
var c = encoder.container(keyedBy: CodingKeys.self)
try c.encode(shell, forKey: .shell)
try c.encode(fontFamily, forKey: .fontFamily)
try c.encode(fontSize, forKey: .fontSize)
try c.encode(lineHeight, forKey: .lineHeight)
try c.encode(letterSpacing, forKey: .letterSpacing)
try c.encode(cursorStyle, forKey: .cursorStyle)
try c.encode(cursorBlink, forKey: .cursorBlink)
try c.encode(boldIsBright, forKey: .boldIsBright)
try c.encode(scrollback, forKey: .scrollback)
try c.encode(optionIsMeta, forKey: .optionIsMeta)
try c.encode(theme, forKey: .theme)
}
}
extension HelderConfig.Session {
private enum CodingKeys: String, CodingKey { case restoreOnLaunch }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
restoreOnLaunch = c.value(.restoreOnLaunch, Self().restoreOnLaunch)
}
}
extension TerminalTheme {
private enum CodingKeys: String, CodingKey {
case background, foreground, cursor, cursorAccent, selectionBackground, selectionInactiveBackground
case black, red, green, yellow, blue, magenta, cyan, white
case brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite
}
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = Self()
background = c.value(.background, d.background)
foreground = c.value(.foreground, d.foreground)
cursor = c.value(.cursor, d.cursor)
cursorAccent = c.value(.cursorAccent, d.cursorAccent)
selectionBackground = c.value(.selectionBackground, d.selectionBackground)
selectionInactiveBackground = c.value(.selectionInactiveBackground, d.selectionInactiveBackground)
black = c.value(.black, d.black)
red = c.value(.red, d.red)
green = c.value(.green, d.green)
yellow = c.value(.yellow, d.yellow)
blue = c.value(.blue, d.blue)
magenta = c.value(.magenta, d.magenta)
cyan = c.value(.cyan, d.cyan)
white = c.value(.white, d.white)
brightBlack = c.value(.brightBlack, d.brightBlack)
brightRed = c.value(.brightRed, d.brightRed)
brightGreen = c.value(.brightGreen, d.brightGreen)
brightYellow = c.value(.brightYellow, d.brightYellow)
brightBlue = c.value(.brightBlue, d.brightBlue)
brightMagenta = c.value(.brightMagenta, d.brightMagenta)
brightCyan = c.value(.brightCyan, d.brightCyan)
brightWhite = c.value(.brightWhite, d.brightWhite)
}
}