瀏覽代碼

os specific ctrl-z (#1420)

Bruce MacDonald 1 年之前
父節點
當前提交
7a1b37ac64
共有 3 個文件被更改,包括 25 次插入8 次删除
  1. 1 8
      readline/readline.go
  2. 18 0
      readline/readline_unix.go
  3. 6 0
      readline/readline_windows.go

+ 1 - 8
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 != "" {

+ 18 - 0
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
+}

+ 6 - 0
readline/readline_windows.go

@@ -0,0 +1,6 @@
+package readline
+
+func handleCharCtrlZ(fd int, state *State) (string, error) {
+	// not supported
+	return "", nil
+}