Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #266 correctly restore terminal parameters #274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions input_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const maxReadBytes = 1024

// PosixParser is a ConsoleParser implementation for POSIX environment.
type PosixParser struct {
fd int
origTermios syscall.Termios
fd int
}

// Setup should be called before starting input
Expand Down
18 changes: 14 additions & 4 deletions internal/term/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@ import (
)

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

func getOriginalTermios(fd int) (*unix.Termios, error) {
var err error
saveTermiosOnce.Do(func() {
saveTermiosFD = fd
saveTermios, err = termios.Tcgetattr(uintptr(fd))
var v *unix.Termios
v, saveTermiosErr = termios.Tcgetattr(uintptr(fd))
if saveTermiosErr == nil {
// save a copy
saveTermios = *v
}
})
return saveTermios, err
if saveTermiosErr != nil {
return nil, saveTermiosErr
}
// return a copy
v := saveTermios
return &v, nil
}

// Restore terminal's mode.
Expand Down