mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00

This makes it so `zig build run` can take arguments such as `--config-default-files=false` or any other configuration. Previously, it only accepted commands such as `+version`. Incidentally, this also makes it so that the app in general can now take configuration arguments via the CLI if it is launched as a new instance via `open`. For example: open -n Ghostty.app --args --config-default-files=false This previously didn't work. This is kind of cool. To make this work, the libghostty C API was modified so that initialization requires the CLI args, and there is a new C API to try to execute an action if it was set.
34 lines
1.3 KiB
Swift
34 lines
1.3 KiB
Swift
import AppKit
|
|
import Cocoa
|
|
import GhosttyKit
|
|
|
|
// Initialize Ghostty global state. We do this once right away because the
|
|
// CLI APIs require it and it lets us ensure it is done immediately for the
|
|
// rest of the app.
|
|
if ghostty_init(UInt(CommandLine.argc), CommandLine.unsafeArgv) != GHOSTTY_SUCCESS {
|
|
Ghostty.logger.critical("ghostty_init failed")
|
|
|
|
// We also write to stderr if this is executed from the CLI or zig run
|
|
switch Ghostty.launchSource {
|
|
case .cli, .zig_run:
|
|
let stderrHandle = FileHandle.standardError
|
|
stderrHandle.write(
|
|
"Ghostty failed to initialize! If you're executing Ghostty from the command line\n" +
|
|
"then this is usually because an invalid action or multiple actions were specified.\n" +
|
|
"Actions start with the `+` character.\n\n" +
|
|
"View all available actions by running `ghostty +help`.\n")
|
|
exit(1)
|
|
|
|
case .app:
|
|
// For the app we exit immediately. We should handle this case more
|
|
// gracefully in the future.
|
|
exit(1)
|
|
}
|
|
}
|
|
|
|
// This will run the CLI action and exit if one was specified. A CLI
|
|
// action is a command starting with a `+`, such as `ghostty +boo`.
|
|
ghostty_cli_try_action();
|
|
|
|
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
|