Skip to content

Commit

Permalink
improvements related to hotkey help
Browse files Browse the repository at this point in the history
  • Loading branch information
mitranim committed Sep 4, 2023
1 parent a011645 commit c328b5b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
13 changes: 7 additions & 6 deletions gow_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
ASCII_DEVICE_CONTROL_2 = 18 // ^R
ASCII_DEVICE_CONTROL_4 = 20 // ^T
ASCII_UNIT_SEPARATOR = 31 // ^- or ^?
ASCII_DELETE = 127 // ^H on macOS
ASCII_DELETE = 127 // ^H on MacOS

// These names reflect our re-interpretation of standard codes.
CODE_INTERRUPT = ASCII_END_OF_TEXT
Expand All @@ -31,16 +31,17 @@ const (
CODE_PRINT_COMMAND = ASCII_UNIT_SEPARATOR
CODE_PRINT_HELP = ASCII_BACKSPACE
CODE_PRINT_HELP_MACOS = ASCII_DELETE
)

const HOTKEY_HELP = `Control codes / hotkeys:
hotkeyHelp = ` 3 ^C Kill subprocess with SIGINT. Repeat within 1s to kill gow.
3 ^C Kill subprocess with SIGINT. Repeat within 1s to kill gow.
18 ^R Kill subprocess with SIGTERM, restart.
20 ^T Kill subprocess with SIGTERM. Repeat within 1s to kill gow.
28 ^\ Kill subprocess with SIGQUIT. Repeat within 1s to kill gow.
31 ^- or ^? Print currently running command.
8 ^H Print this help
127 ^H (macOS) Print this help
`
)
8 ^H Print this help.
127 ^H (MacOS) Print this help.`

var (
FD_TERM = syscall.Stdin
Expand Down
6 changes: 2 additions & 4 deletions gow_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ Flags:
"Multi" flags can be passed multiple times.
Some also support comma-separated parsing.
Control codes / hotkeys:
%s
`, gg.FlagHelp[Opt](), hotkeyHelp))
%v
`, gg.FlagHelp[Opt](), HOTKEY_HELP))
}

func (self Opt) LogErr(err error) {
Expand Down
10 changes: 3 additions & 7 deletions gow_stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func (self *Stdio) OnByte(char byte) {
case CODE_STOP:
self.OnCodeStop()

case CODE_PRINT_HELP:
fallthrough
case CODE_PRINT_HELP_MACOS:
case CODE_PRINT_HELP, CODE_PRINT_HELP_MACOS:
self.OnCodePrintHelp()

default:
Expand All @@ -103,13 +101,11 @@ func (self *Stdio) OnCodeQuit() {
self.OnCodeSig(CODE_QUIT, syscall.SIGQUIT, `^\`)
}

func (self *Stdio) OnCodePrintCommand() {
func (*Stdio) OnCodePrintCommand() {
log.Printf(`current command: %q`, os.Args)
}

func (self *Stdio) OnCodePrintHelp() {
log.Printf(hotkeyHelp)
}
func (*Stdio) OnCodePrintHelp() { log.Println(HOTKEY_HELP) }

func (self *Stdio) OnCodeRestart() {
main := self.Main()
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Supported control codes with commonly associated hotkeys. Exact keys may vary be
20 ^T Kill subprocess with SIGTERM.
28 ^\ Kill subprocess with SIGQUIT.
31 ^- or ^? Print currently running command.
8 ^H Print help.
127 ^H (MacOS) Print help.
```

Other input is forwarded to the subprocess as-is.
Expand Down

0 comments on commit c328b5b

Please sign in to comment.