gum icon indicating copy to clipboard operation
gum copied to clipboard

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

Open dbrockman opened this issue 9 months ago • 1 comments

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):

  • OS: macOS

Additional context gum version 0.14.0 installed with brew

dbrockman avatar May 04 '24 06:05 dbrockman

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.

minnesjay avatar May 07 '24 03:05 minnesjay