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,62 @@
import Foundation
/// Which side of the window has focus; drives the fluid widths below 1600pt.
public enum FocusZone: String, Sendable, Equatable {
case neutral
case editor
case terminal
}
/// Pixel widths of the three fixed columns; the editor takes the remainder.
public struct ColumnWidths: Sendable, Equatable {
public var sourceControl: Double
public var explorer: Double
public var agent: Double
public init(sourceControl: Double, explorer: Double, agent: Double) {
self.sourceControl = sourceControl
self.explorer = explorer
self.agent = agent
}
}
public enum ColumnLayout {
/// At and above this width every column fits and focus changes nothing.
public static let roomyWidth = 1600.0
public static let minEditorWidth = 280.0
public static let splitterWidth = 1.0
public static let sourceControlRange = 160.0...460.0
public static let explorerRange = 160.0...520.0
/// Fluid widths for a window. Roomy: 13.4% · 16.4% · flex · 27.3% (the design's
/// 236 · 288 · flex · 480 on a 1760 frame). Tight: 15% · 15%, and the agent column
/// takes 30%, or 20% with the editor focused, or 50% with a terminal focused.
public static func fluid(windowWidth w: Double, focus: FocusZone) -> ColumnWidths {
if w >= roomyWidth {
return ColumnWidths(sourceControl: (w * 0.134).rounded(), explorer: (w * 0.164).rounded(), agent: (w * 0.273).rounded())
}
let agentShare = focus == .terminal ? 0.5 : focus == .editor ? 0.2 : 0.3
return ColumnWidths(sourceControl: (w * 0.15).rounded(), explorer: (w * 0.15).rounded(), agent: (w * agentShare).rounded())
}
/// Scales the fixed columns down so the editor keeps `minEditorWidth`; unchanged when they fit.
public static func fitted(_ widths: ColumnWidths, windowWidth: Double, sourceControlVisible: Bool) -> ColumnWidths {
let splitters = (sourceControlVisible ? 3.0 : 2.0) * splitterWidth
let budget = windowWidth - splitters - minEditorWidth
let total = (sourceControlVisible ? widths.sourceControl : 0) + widths.explorer + widths.agent
guard total > budget, total > 0 else { return widths }
let k = max(0, budget) / total
return ColumnWidths(
sourceControl: sourceControlVisible ? (widths.sourceControl * k).rounded(.down) : widths.sourceControl,
explorer: (widths.explorer * k).rounded(.down),
agent: (widths.agent * k).rounded(.down)
)
}
/// The widest the agent column may be dragged: until the editor would drop below its minimum.
public static func maxAgentWidth(windowWidth: Double, widths: ColumnWidths, sourceControlVisible: Bool) -> Double {
let splitters = (sourceControlVisible ? 3.0 : 2.0) * splitterWidth
let others = (sourceControlVisible ? widths.sourceControl : 0) + widths.explorer
return max(minEditorWidth, windowWidth - splitters - others - minEditorWidth)
}
}
@@ -0,0 +1,44 @@
import Foundation
/// Caret position shown in the status bar; 1-based.
public struct Cursor: Sendable, Equatable {
public var path: String
public var line: Int
public var column: Int
public init(path: String, line: Int, column: Int) {
self.path = path
self.line = line
self.column = column
}
}
/// A line-range selection in a read-only pane; `anchor` is where the drag started.
public struct LineSelection: Sendable, Equatable {
public var path: String
public var start: Int
public var end: Int
public var anchor: Int
public init(path: String, start: Int, end: Int, anchor: Int) {
self.path = path
self.start = min(start, end)
self.end = max(start, end)
self.anchor = anchor
}
public var reference: AgentReference { AgentReference(path: path, startLine: start, endLine: end) }
}
/// How a file is opened: from a git row (`side`), at a line (search hit, symbol), or straight into Diff.
public struct OpenOptions: Sendable, Equatable {
public var side: DiffSide?
public var line: Int?
public var showDiff: Bool
public init(side: DiffSide? = nil, line: Int? = nil, showDiff: Bool = false) {
self.side = side
self.line = line
self.showDiff = showDiff
}
}
@@ -0,0 +1,78 @@
/// Per-project editor session, restored on launch when `session.restoreOnLaunch` is on.
public struct SessionState: Codable, Sendable, Equatable {
public var active: String?
public var modes: [String: ViewMode]
/// Which git row opened each file; only the Diff overlay follows it.
public var sides: [String: DiffSide]
public init(active: String? = nil, modes: [String: ViewMode] = [:], sides: [String: DiffSide] = [:]) {
self.active = active
self.modes = modes
self.sides = sides
}
private enum CodingKeys: String, CodingKey {
case active
case modes = "tabMode"
case sides = "tabSide"
}
/// A stored mode this build does not know is dropped, not the whole map.
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
active = try? c.decodeIfPresent(String.self, forKey: .active)
let raw = (try? c.decodeIfPresent([String: String].self, forKey: .modes)) ?? [:]
modes = raw.compactMapValues(ViewMode.init(rawValue:))
sides = (try? c.decodeIfPresent([String: DiffSide].self, forKey: .sides)) ?? [:]
}
/// The storage key; one session per project root.
public static func key(root: String) -> String { "helder.session:" + root }
}
/// Window-wide layout that survives a restart.
public struct LayoutState: Codable, Sendable, Equatable {
/// The agent pane's share of the right column's height.
public var agentFraction: Double
public init(agentFraction: Double = LayoutState.defaultAgentFraction) {
self.agentFraction = LayoutState.clampAgentFraction(agentFraction)
}
public static let key = "helder.topFrac"
public static let defaultAgentFraction = 0.52
public static let agentFractionRange = 0.18...0.82
public static func clampAgentFraction(_ value: Double) -> Double {
min(max(value, agentFractionRange.lowerBound), agentFractionRange.upperBound)
}
}
public struct RecentProject: Codable, Sendable, Equatable, Identifiable {
public var path: String
public var name: String
public var id: String { path }
public init(path: String, name: String) {
self.path = path
self.name = name
}
}
public enum RecentLists {
/// Recent files per project, in `.helder/recent.json`.
public static let maxFiles = 100
/// Recent projects, machine-wide.
public static let maxProjects = 20
public static let recentFilesName = "recent.json"
/// Moves `path` to the front, de-duplicated and capped.
public static func pushing(_ path: String, onto list: [String], limit: Int = maxFiles) -> [String] {
Array(([path] + list.filter { $0 != path }).prefix(limit))
}
/// Moves a project to the front, keyed on its path, capped at 20.
public static func pushing(_ project: RecentProject, onto list: [RecentProject]) -> [RecentProject] {
Array(([project] + list.filter { $0.path != project.path }).prefix(maxProjects))
}
}