charmbracelet / gum

A tool for glamorous shell scripts 🎀
MIT License
17.94k stars 339 forks source link

gum choose prints "user aborted" when you ctrl-c #563

Closed dbrockman closed 4 months ago

dbrockman commented 5 months ago

Describe the bug

If you press Ctrl-C (SIGINT) while gum is waiting on input, it now prints the string "user aborted".

This is new in 0.14.0. Before this version it didn't print anything on SIGINT.

local chosen=$(gum choose a b c)

# Before 0.14.0 you could just check if the variable was empty
if [ -z "$chosen" ]; then
  # Use aborted the prompt.
  return
fi

# But when using 0.14.0, I had to add an extra check
if [ -z "$chosen" ] || [ "$chosen" = "user aborted" ]; then
  # Use aborted the prompt.
  return
fi

# This becomes even more difficult to deal with when you ask for multiple choices

local things=("a" "b" "c")
local arr=($(gum choose --header "Select multiple:" --no-limit "${things[@]}"))
if [ "${#arr[@]}" -eq 2 ] && [ "${arr[1]}" = "user" ] && [ "${arr[2]}" = "aborted" ]; then
  # Use aborted the prompt.
  return
fi

# If `gum choose` instead printed nothing in the previous example then I could just check the length of the array:
if [ "${#arr[@]}" -eq 0 ]; then
  # Use aborted the prompt.
  return
fi

To Reproduce

  1. Run this gum choose a b c (don't make a choice)
  2. Press Ctrl-C
  3. It prints "user aborted"

Expected behavior It should not print anything if the user aborts the prompt.

Desktop (please complete the following information):

Additional context gum version 0.14.0 installed with brew

minnesjay commented 5 months ago

I use gum input | grep -v "^user aborted$" to solve this issue for now, but I would prefer if the "user aborted" error was never printed in the first place.