Skip to content

Commit

Permalink
Merge pull request #181 from synfinatic/fix-bell
Browse files Browse the repository at this point in the history
fix bell/warning when selecting items during setup
synfinatic authored Dec 16, 2021
2 parents 3c8f9e6 + f7a9ac9 commit 2d1f4f7
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
* Setup now uses a smaller cursor which doesn't hide the character
* Fix setup bug where the SSO Instance was always called `Default`
* Setup no longer accepts invalid characters for strings #178
* Fix error/bell sound on macOS when selecting options during setup #179

## [v1.5.0] - 2021-12-14

49 changes: 49 additions & 0 deletions cmd/bellskipper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

/*
* AWS SSO CLI
* Copyright (c) 2021 Aaron Turner <synfinatic at gmail dot com>
*
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or with the authors permission any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import (
"os"
)

/*
* 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#issuecomment-573814976
*/
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()
}
3 changes: 3 additions & 0 deletions cmd/setup_cmd.go
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ func setupWizard(ctx *RunContext) error {
Templates: &promptui.SelectTemplates{
Selected: fmt.Sprintf(`%s: {{ . | faint }}`, label),
},
Stdout: &bellSkipper{},
}
if _, ssoRegion, err = sel.Run(); err != nil {
return err
@@ -127,6 +128,7 @@ func setupWizard(ctx *RunContext) error {
Templates: &promptui.SelectTemplates{
Selected: fmt.Sprintf(`%s: {{ . | faint }}`, label),
},
Stdout: &bellSkipper{},
}
if _, awsRegion, err = sel.Run(); err != nil {
return err
@@ -153,6 +155,7 @@ func setupWizard(ctx *RunContext) error {
Templates: &promptui.SelectTemplates{
Selected: fmt.Sprintf(`%s: {{ . | faint }}`, label),
},
Stdout: &bellSkipper{},
}
if _, urlAction, err = sel.Run(); err != nil {
return err

0 comments on commit 2d1f4f7

Please sign in to comment.