-
Notifications
You must be signed in to change notification settings - Fork 13
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
Disable terminal echo while State Tool is running. #2882
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8a4ad8f
Turn off terminal echo while progressbar is present.
mitchell-as e693344
Merge branch 'mitchell/dx-2050' into mitchell/dx-2214-2
mitchell-as 7c45563
Disable terminal echo while State Tool is running.
mitchell-as 750654a
Fixed typo.
mitchell-as File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"github.com/ActiveState/cli/internal/osutils/user" | ||
"github.com/ActiveState/cli/internal/output" | ||
"github.com/ActiveState/cli/internal/subshell/sscommon" | ||
"github.com/ActiveState/cli/internal/subshell/termecho" | ||
"github.com/ActiveState/cli/pkg/project" | ||
) | ||
|
||
|
@@ -219,3 +220,17 @@ func (v *SubShell) IsAvailable() bool { | |
} | ||
return fileutils.FileExists(rcFile) | ||
} | ||
|
||
func (v *SubShell) TurnOffEcho() { | ||
if runtime.GOOS == "windows" { | ||
return // not supported | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Windows does not have access to the termios functions needed to disable echo in emulated shells like Git Bash (which is not interactive anyway). |
||
} | ||
termecho.Off() | ||
} | ||
|
||
func (v *SubShell) TurnOnEcho() { | ||
if runtime.GOOS == "windows" { | ||
return // not supported | ||
} | ||
termecho.On() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package termecho | ||
|
||
import ( | ||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/multilog" | ||
) | ||
|
||
func Off() { | ||
err := toggle(false) | ||
if err != nil { | ||
multilog.Error("Unable to turn off terminal echoing: %v", errs.JoinMessage(err)) | ||
} | ||
} | ||
|
||
func On() { | ||
err := toggle(true) | ||
if err != nil { | ||
multilog.Error("Unable to turn off terminal echoing: %v", errs.JoinMessage(err)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package termecho | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
const ioctlReadTermios = unix.TIOCGETA | ||
const ioctlWriteTermios = unix.TIOCSETA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package termecho | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
const ioctlReadTermios = unix.TCGETS | ||
const ioctlWriteTermios = unix.TCSETS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build linux || darwin | ||
// +build linux darwin | ||
|
||
package termecho | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func toggle(on bool) error { | ||
fd := int(os.Stdin.Fd()) | ||
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) | ||
if err != nil { | ||
return errs.Wrap(err, "Could not get termios") | ||
} | ||
|
||
newState := *termios // copy | ||
if !on { | ||
newState.Lflag &^= unix.ECHO | ||
} else { | ||
newState.Lflag |= unix.ECHO | ||
} | ||
err = unix.IoctlSetTermios(fd, ioctlWriteTermios, &newState) | ||
if err != nil { | ||
return errs.Wrap(err, "Could not set termios") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package termecho | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func toggle(on bool) error { | ||
fd := windows.Handle(os.Stdin.Fd()) | ||
var mode uint32 | ||
err := windows.GetConsoleMode(fd, &mode) | ||
if err != nil { | ||
return errs.Wrap(err, "Error calling GetConsoleMode") | ||
} | ||
|
||
newMode := mode | ||
if !on { | ||
newMode &^= windows.ENABLE_ECHO_INPUT | ||
} else { | ||
newMode |= windows.ENABLE_ECHO_INPUT | ||
} | ||
err = windows.SetConsoleMode(fd, newMode) | ||
if err != nil { | ||
return errs.Wrap(err, "Error calling SetConsoleMode") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also disable ctrl+c and other similar inputs? I don't believe that's something we want to disallow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is it possible that if the state tool errors mid-execution, we could leave the user's shell in a state where they cannot echo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't see this, but in my original PR (#2768), I noted that echo is restored after ^C, so no problem there. The
defer
does its job.If there is a hard crash, echo will probably be lost, but this is the case for any terminal program that messes with termios, so the only resolution is for the user to exit this terminal and start up a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the
defer
will run even on a panic as long as it's on the function call stack so we should be good even in the event of a crash as this defer is placed ahead of the actual command logic.