From 7a1b37ac64f0fb0585e279a0a840707843511ed3 Mon Sep 17 00:00:00 2001 From: Bruce MacDonald Date: Mon, 11 Dec 2023 10:48:14 -0500 Subject: [PATCH] os specific ctrl-z (#1420) --- readline/readline.go | 9 +-------- readline/readline_unix.go | 18 ++++++++++++++++++ readline/readline_windows.go | 6 ++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 readline/readline_unix.go create mode 100644 readline/readline_windows.go diff --git a/readline/readline.go b/readline/readline.go index 781ac8a3..c4c73520 100644 --- a/readline/readline.go +++ b/readline/readline.go @@ -192,14 +192,7 @@ func (i *Instance) Readline() (string, error) { case CharCtrlW: buf.DeleteWord() case CharCtrlZ: - if err := UnsetRawMode(fd, termios); err != nil { - return "", err - } - - syscall.Kill(0, syscall.SIGSTOP) - - // on resume... - return "", nil + return handleCharCtrlZ(fd, termios) case CharEnter: output := buf.String() if output != "" { diff --git a/readline/readline_unix.go b/readline/readline_unix.go new file mode 100644 index 00000000..a1e34d27 --- /dev/null +++ b/readline/readline_unix.go @@ -0,0 +1,18 @@ +//go:build !windows + +package readline + +import ( + "syscall" +) + +func handleCharCtrlZ(fd int, termios *Termios) (string, error) { + if err := UnsetRawMode(fd, termios); err != nil { + return "", err + } + + syscall.Kill(0, syscall.SIGSTOP) + + // on resume... + return "", nil +} diff --git a/readline/readline_windows.go b/readline/readline_windows.go new file mode 100644 index 00000000..c8178903 --- /dev/null +++ b/readline/readline_windows.go @@ -0,0 +1,6 @@ +package readline + +func handleCharCtrlZ(fd int, state *State) (string, error) { + // not supported + return "", nil +}