Skip to content

Commit

Permalink
Merge pull request #19 from joeycumines/upstream-elk-language-pr-2
Browse files Browse the repository at this point in the history
Fix restoring terminal - pass down and use fd
  • Loading branch information
Verseth authored May 9, 2024
2 parents 7d668ee + 47d2842 commit 32b5449
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 32b5449

Please sign in to comment.