ShellCraftKit
ShellCraftKit is a small command engine for demos and sandboxed tools. It feeds a Ghostty terminal through InMemoryTerminalSession and executes Swift closures for commands.
Define a shell
import ShellCraftKit
let shell = ShellDefinition(
prompt: "demo$ ",
welcomeMessage: "\r\nGhosttyKit demo\r\n\r\n"
) {
ShellCommand("date", summary: "Print the current date") { _ in
.output(Date().description + "\r\n")
}
ShellCommand("clear", summary: "Clear the screen") { _ in
.clear
}
}
Command result
A command returns one of three results: output, clear, or exit. CommandContext gives the parsed command name, arguments, username, and current terminal size.
ShellCommand("size", summary: "Print terminal size") { context in
.output("\(context.terminalSize.columns)x\(context.terminalSize.rows)\r\n")
}
Attach to Ghostty
let shellSession = ShellSession(shell: shell)
shellSession.start()
terminal.configuration = TerminalSurfaceOptions(
backend: .inMemory(shellSession.terminalSession)
)