Skip to content

Commit

Permalink
prompt: Fix restoring terminal pass down and use fd
Browse files Browse the repository at this point in the history
fbshipit-source-id: bb28650
  • Loading branch information
joeycumines committed Sep 4, 2023
1 parent 7d668ee commit 47d2842
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion reader_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (t *PosixReader) Open() error {

// Close should be called after stopping input
func (t *PosixReader) Close() error {
if err := term.Restore(); err != nil {
if err := term.RestoreFD(t.fd); err != nil {
_ = syscall.Close(t.fd)
return err
}
Expand Down
9 changes: 7 additions & 2 deletions term/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ func getOriginalTermios(fd int) (*unix.Termios, error) {

// Restore terminal's mode.
func Restore() error {
o, err := getOriginalTermios(saveTermiosFD)
return RestoreFD(saveTermiosFD)
}

// RestoreFD restores terminal's mode for the given file descriptor.
func RestoreFD(fd int) error {
o, err := getOriginalTermios(fd)
if err != nil {
return err
}
return termios.Tcsetattr(uintptr(saveTermiosFD), termios.TCSANOW, o)
return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, o)
}

0 comments on commit 47d2842

Please sign in to comment.