restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import Foundation
|
||||
|
||||
public enum TerminalKind: String, Sendable, Equatable, CaseIterable {
|
||||
/// The top pane: a shell that runs the `claude` CLI.
|
||||
case agent
|
||||
/// The bottom pane: a plain login shell.
|
||||
case shell
|
||||
}
|
||||
|
||||
/// Executable, arguments and environment for one terminal pane.
|
||||
public struct TerminalLaunch: Sendable, Equatable {
|
||||
public var executable: String
|
||||
public var arguments: [String]
|
||||
public var environment: [String: String]
|
||||
public var workingDirectory: String
|
||||
|
||||
public init(executable: String, arguments: [String], environment: [String: String], workingDirectory: String) {
|
||||
self.executable = executable
|
||||
self.arguments = arguments
|
||||
self.environment = environment
|
||||
self.workingDirectory = workingDirectory
|
||||
}
|
||||
|
||||
/// The launch for a pane. The agent runs as `$SHELL -i -c <command>`: `-i` still sources the rc
|
||||
/// files (nvm etc.) but leaves no prompt line or echoed command behind.
|
||||
public static func make(kind: TerminalKind, config: HelderConfig, projectRoot: String?, environment base: [String: String]) -> TerminalLaunch {
|
||||
let shell = config.terminal.shell ?? base["SHELL"] ?? "/bin/zsh"
|
||||
let args = kind == .agent && config.ai.autoLaunch ? ["-i", "-c", config.ai.command] : []
|
||||
let cwd = projectRoot ?? base["HOME"] ?? "/"
|
||||
return TerminalLaunch(executable: shell, arguments: args, environment: environment(from: base), workingDirectory: cwd)
|
||||
}
|
||||
|
||||
/// The child environment. A GUI launch inherits no locale and no COLORTERM, which turns
|
||||
/// multibyte output into mojibake and shifts the CLI's 24-bit colours; npm's prefix
|
||||
/// variables make nvm refuse to load.
|
||||
public static func environment(from base: [String: String]) -> [String: String] {
|
||||
var env = base
|
||||
env["npm_config_prefix"] = nil
|
||||
env["npm_config_globalconfig"] = nil
|
||||
if env["LC_ALL"] == nil && env["LC_CTYPE"] == nil && env["LANG"] == nil { env["LANG"] = "en_US.UTF-8" }
|
||||
if env["COLORTERM"] == nil { env["COLORTERM"] = "truecolor" }
|
||||
env["TERM"] = "xterm-256color"
|
||||
return env
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user