-
Notifications
You must be signed in to change notification settings - Fork 336
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
Terminal bell is ringing when try to select item using up-down arrow(↑↓) keys #49
Comments
Things get worse when I turn on the 'Vim Mode', by passing At the initial state, like when I first run the program with I think this is |
Ok, finally I found the answer. The terminal bell was coming from chzyer/readline/operation.go:265-278. After commenting out the I think it'd be good to slightly modify the original Or... what about reinventing the wheel--write own key handler just for ADD: Commenting out |
Thanks for the detective work! We could propose a patch to |
Ah, optional bell that would be a great solution too. BTW, I was planning to build a relatively small packge for key handling in Go since it looks there are not. The package will not be strongly related to prompui, but I'll let you know if my package works well and can be adopted in promptui smoothly--without breaking the design goal of this package. |
Hey everyone. Has there been any update regarding this issue? The bell is really annoying :-/ |
A hacky solution for this is to override type stderr struct{}
func (s *stderr) Write(b []byte) (int, error) {
if len(b) == 1 && b[0] == 7 {
return 0, nil
}
return os.Stderr.Write(b)
}
func (s *stderr) Close() error {
return os.Stderr.Close()
}
func init() {
readline.Stdout = &stderr{}
} |
@LuizBranco: my hack above works like a charm, but it would be great to be able to be able to set custom Stdin, Stdout, and Stderr in prompts and selects, if they are not set, then use the defaults. That will probably allow promptui to switch implementations if you need to. I'm willing to provide a PR if you think that's the right approach. |
@maraino where are you putting the proposed code above? |
@danlsgiga it really does not matter, just in a package that gets initialized when the program starts. In my case, I have it on a wrapper of the promptui methods that I use, this wrapper adds some extra functionality that I need and fixes the display of prompts when the program receives data on STDIN. |
any update about this issue? thanks |
re: @maraino
This appears to be possible-(ish) now. I am currently using the following very slightly modified version of your sample code as such: // bellSkipper implements an io.WriteCloser that skips the terminal bell
// character (ASCII code 7), and writes the rest to os.Stderr. It is used to
// replace readline.Stdout, that is the package used by promptui to display the
// prompts.
//
// This is a workaround for the bell issue documented in
// https://github.com/manifoldco/promptui/issues/49.
type bellSkipper struct{}
// Write implements an io.WriterCloser over os.Stderr, but it skips the terminal
// bell character.
func (bs *bellSkipper) Write(b []byte) (int, error) {
const charBell = 7 // c.f. readline.CharBell
if len(b) == 1 && b[0] == charBell {
return 0, nil
}
return os.Stderr.Write(b)
}
// Close implements an io.WriterCloser over os.Stderr.
func (bs *bellSkipper) Close() error {
return os.Stderr.Close()
} I then pass it at struct init such as: prompt := promptui.Select{
// ...snip...
Stdout: &bellSkipper{},
} This slightly modified method allows me to avoid having to import Additionally, I believe it should now be possible to PR a modification to |
@mroth: The workaround above does not work anymore. |
It appears the terminal you are using does not support ANSI escape codes. This appears to be an altogether different problem than what is being discussed in this issue. |
That's actually not the case. After changing to bellSkipper as @maraino implemented it. I get same results as @marcauberer in powershell |
@Itshardtopickanusername Try to use func init() {
var inMode, outMode uint32
if err := windows.GetConsoleMode(windows.Stdin, &inMode); err == nil {
inMode |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT
if err := windows.SetConsoleMode(windows.Stdin, inMode); err != nil {
fmt.Fprintf(os.Stderr, "Failed to set console mode: %v", err)
}
}
if err := windows.GetConsoleMode(windows.Stdout, &outMode); err == nil {
outMode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
if err := windows.SetConsoleMode(windows.Stdout, outMode); err != nil {
fmt.Fprintf(os.Stderr, "Failed to set console mode: %v", err)
}
}
} https://docs.microsoft.com/en-us/windows/console/setconsolemode |
removed annoying bip sound, when running from Windows Terminal. Solution from: manifoldco/promptui#49 (comment)
For those looking for a less intrusive and Windows compatible workaround. Inspired by @maraino and @mroth solution. In my case, importing the import "github.com/chzyer/readline"
type noBellStdout struct{}
func (n *noBellStdout) Write(p []byte) (int, error) {
if len(p) == 1 && p[0] == readline.CharBell {
return 0, nil
}
return readline.Stdout.Write(p)
}
func (n *noBellStdout) Close() error {
return readline.Stdout.Close()
}
var NoBellStdout = &noBellStdout{} This is just a wrapper of the original prompt := promptui.Select{
// ...
Stdout: NoBellStdout,
} |
This commit adds a workaround for the bell bug with the prompt ui select widget see manifoldco/promptui#49 for more details
I'm on macOS High Sierra, using iTerm2 3.1.5, zsh 5.3, Go 1.9.2 darwin/amd64 and the latest version of promptui.
While taking a look at #41, I found that my terminal alerts me with a ringing bell when I try to select item using up-down arrow(↑↓) keys, even I'm not on the top-most or the bottom-most.
It is happening on different terminals, for instance macOS' default terminal 'Terminal.app' and different shells, like sh, bash or csh.
It's not that important problem at all, but users might get annoyed by this.
The text was updated successfully, but these errors were encountered: