Skip to content

Commit

Permalink
Fix input reading, banner touch up
Browse files Browse the repository at this point in the history
  • Loading branch information
curusarn committed Mar 25, 2023
1 parent a692aae commit e076add
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
20 changes: 9 additions & 11 deletions internal/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,18 @@ func promptForName(out *output.Output, fpath string) (string, error) {
return "", fmt.Errorf("could not get hostname (prompt default): %w", err)
}
hostStub := strings.Split(host, ".")[0]
fmt.Printf("\nPlease choose a short name for this device (default: '%s'): ", hostStub)
var input string
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
input = scanner.Text()
}
if err = scanner.Err(); err != nil {
return "", fmt.Errorf("scanner error: %w", err)
reader := bufio.NewReader(os.Stdin)
fmt.Printf("\nChoose a short name for this device (default: '%s'): ", hostStub)
input, err := reader.ReadString('\n')
name := strings.TrimRight(input, "\n")
if err != nil {
return "", fmt.Errorf("reader error: %w", err)
}
if input == "" {
if name == "" {
out.Info("Got no input - using default ...")
input = hostStub
name = hostStub
}
out.Info(fmt.Sprintf("Device name set to '%s'", input))
out.Info(fmt.Sprintf("Device name set to '%s'", name))
fmt.Printf("You can change the device name at any time by editing '%s' file\n", fpath)
return input, nil
}
10 changes: 5 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ printf '

# Show banner if RESH is not loaded in the terminal
if [ -z "${__RESH_VERSION-}" ]; then printf '
##############################################################
# #
# Finish the installation by RESTARTING this terminal! #
# #
##############################################################
┌────────────────────────────────────────────────────────────┐
Finish the installation by RESTARTING this terminal!
└────────────────────────────────────────────────────────────┘
'
fi

0 comments on commit e076add

Please sign in to comment.