diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index 7d2f5b39f..5702fd6be 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -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) diff --git a/tools/cmd/at/shell.go b/tools/cmd/at/shell.go new file mode 100644 index 000000000..a3ff1ccbb --- /dev/null +++ b/tools/cmd/at/shell.go @@ -0,0 +1,49 @@ +// License: GPLv3 Copyright: 2022, Kovid Goyal, + +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) +}