-
Notifications
You must be signed in to change notification settings - Fork 349
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
[Bug] After exiting the program, ctrl+c is invalid #233
Comments
I am having the same issue. Using the example from the readme, if i press In linux, |
Same issue - VSCode running a remote shell on Linux (VSCode itself is running in Big Sur, M1 flavour). Tested on a Linux shell (without using VSCode), same result. This happens whether the program crashes or exits gracefully. UPDATE: running "reset" seems to fix the issue for me. |
I saw similar behaviour but also that I could not type commands, like #228 . The solution given by @nodauf there works for me. If one's terminal is stuck in this state, type |
It appears it may be a better call do downgrade based on #228 (comment) for now. None of us has mentioned windows here yet, but there might be issues there also, and executing |
same issue here, use |
This bug is introduced by 20e0658. Saving a *unix.Termios and then modifying it in SetRaw() makes the saved state useless. By restoring saveTermios type from *unix.Termios to unix.Termios, SetRaw() no longer influences the saved termios. This should fix c-bata#228 and c-bata#233 . Signed-off-by: Xiami <[email protected]>
This bug is introduced by 20e0658. Saving a *unix.Termios and then modifying it in SetRaw() makes the saved state useless. By restoring saveTermios type from *unix.Termios to unix.Termios, SetRaw() no longer influences the saved termios. This should fix c-bata#228 and c-bata#233 . Signed-off-by: Xiami <[email protected]>
Can confirm, downgrading to 0.2.5 fixes it Is there a reason to capture ctrl+c by default at all ? Doing that by default will just cause problems if apps panic or something and term doesn't get reset to the normal settings |
Can confirm this also. |
I'm also finding that after running the binary, enter isn't being detected on applications, but is on the shell. For example, ssh-add won't accept my passphrase until I hit control Z for end of file, whereas before the binary I can just hit enter. go version go1.16.2 linux/amd64 |
Another solution is to save terminal state and restore terminal state before exiting.
package main
import (
"fmt"
"os"
prompt "github.com/c-bata/go-prompt"
"golang.org/x/term"
)
var termState *term.State
func saveTermState() {
oldState, err := term.GetState(int(os.Stdin.Fd()))
if err != nil {
return
}
termState = oldState
}
func restoreTermState() {
if termState != nil {
term.Restore(int(os.Stdin.Fd()), termState)
}
}
func completer(in prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "users", Description: "Store the username and age"},
{Text: "articles", Description: "Store the article text posted by user"},
{Text: "comments", Description: "Store the text commented to articles"},
{Text: "groups", Description: "Combine users with specific rules"},
}
return prompt.FilterHasPrefix(s, in.GetWordBeforeCursor(), true)
}
func main() {
saveTermState()
in := prompt.Input(">>> ", completer,
prompt.OptionTitle("sql-prompt"),
prompt.OptionHistory([]string{"SELECT * FROM users;"}),
prompt.OptionPrefixTextColor(prompt.Yellow),
prompt.OptionPreviewSuggestionTextColor(prompt.Blue),
prompt.OptionSelectedSuggestionBGColor(prompt.LightGray),
prompt.OptionSuggestionBGColor(prompt.DarkGray))
fmt.Println("Your input: " + in)
restoreTermState()
} It works on go-prompt (v0.2.6) :
|
@WangYihang not really as your program can panic. It shouldn't really block Ctrl+c by default in the first place, if handing ctrl+c is really needed in default cli (of which I doubt, it should be an opt-in option) it should do that via intercepting SIGINT |
Thank you very much, this problem has been bothering me for a long time, it can run very well on Arch, but can't on Ubuntu. Your solution is very nice to Ubuntu! Thanks again. |
This will be fixed by #239 |
I still have this exact issue on MacOs, it's not fixable with the aforementioned functions |
Ref: - c-bata#233 - c-bata#239
Bug reports
Mac os bigsur
go version go1.16.2 darwin/amd64
go-prompt v0.2.6
iTerm2
code :
main.go
in iterm2 run
go run main.go
after exit the program,and than rungo run main2.go
ctrl+c not workcan not exit program
main2.go
open a new iterm2 tab run
go run main2.go
thanctrl+c
can exit the programThe text was updated successfully, but these errors were encountered: