Start work on porting kitty shell to Go
This commit is contained in:
parent
f57832f501
commit
565526624f
@ -320,6 +320,7 @@ func EntryPoint(tool_root *cli.Command) *cli.Command {
|
||||
Usage: "[global options] [sub-command] [sub-command options] [sub-command args]",
|
||||
ShortDescription: "Control kitty remotely",
|
||||
HelpText: "Control kitty by sending it commands. Set the allow_remote_control option in :file:`kitty.conf` for this to work. When run without any sub-commands this will start an interactive shell to control kitty.",
|
||||
Run: shell_main,
|
||||
})
|
||||
add_rc_global_opts(at_root_command)
|
||||
|
||||
|
||||
49
tools/cmd/at/shell.go
Normal file
49
tools/cmd/at/shell.go
Normal file
@ -0,0 +1,49 @@
|
||||
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package at
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"kitty/tools/cli"
|
||||
"kitty/tools/cli/markup"
|
||||
"kitty/tools/tui/loop"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
var formatter *markup.Context
|
||||
|
||||
const prompt = "🐱 "
|
||||
|
||||
func shell_loop(kill_if_signaled bool) (int, error) {
|
||||
lp, err := loop.New(loop.NoAlternateScreen, loop.NoRestoreColors)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
lp.OnInitialize = func() (string, error) {
|
||||
lp.QueueWriteString(prompt)
|
||||
return "\r\n", nil
|
||||
}
|
||||
|
||||
err = lp.Run()
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
ds := lp.DeathSignalName()
|
||||
if ds != "" {
|
||||
if kill_if_signaled {
|
||||
lp.KillIfSignalled()
|
||||
return 1, nil
|
||||
}
|
||||
return 1, fmt.Errorf("Killed by signal: %s", ds)
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func shell_main(cmd *cli.Command, args []string) (int, error) {
|
||||
formatter = markup.New(true)
|
||||
fmt.Println("Welcome to the kitty shell!")
|
||||
fmt.Println("Use", formatter.Green("help"), "for assistance or", formatter.Green("exit"), "to quit.")
|
||||
return shell_loop(true)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user