Skip to content

Commit

Permalink
fix: ctrl-c not work
Browse files Browse the repository at this point in the history
  • Loading branch information
vimiix committed Oct 8, 2024
1 parent c6d49f2 commit 87f7ddb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion internal/term/raw.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package term
Expand Down Expand Up @@ -25,5 +26,5 @@ func SetRaw(fd int) error {
n.Cc[syscall.VMIN] = 1
n.Cc[syscall.VTIME] = 0

return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(n))
return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(&n))
}
11 changes: 7 additions & 4 deletions internal/term/term.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package term
Expand All @@ -10,16 +11,18 @@ import (
)

var (
saveTermios *unix.Termios
saveTermios unix.Termios
saveTermiosFD int
saveTermiosOnce sync.Once
)

func getOriginalTermios(fd int) (*unix.Termios, error) {
func getOriginalTermios(fd int) (unix.Termios, error) {
var err error
saveTermiosOnce.Do(func() {
saveTermiosFD = fd
saveTermios, err = termios.Tcgetattr(uintptr(fd))
var saveTermiosPtr *unix.Termios
saveTermiosPtr, err = termios.Tcgetattr(uintptr(fd))
saveTermios = *saveTermiosPtr
})
return saveTermios, err
}
Expand All @@ -30,5 +33,5 @@ func Restore() error {
if err != nil {
return err
}
return termios.Tcsetattr(uintptr(saveTermiosFD), termios.TCSANOW, o)
return termios.Tcsetattr(uintptr(saveTermiosFD), termios.TCSANOW, &o)
}

0 comments on commit 87f7ddb

Please sign in to comment.