Skip to content

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Dec 6, 2024

  • make ctrl+c interrupt and exit properly
  • handle timeouts with a context.Context and exit properly

Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a draft, but I looked at it

Copy link
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, few questions

Base automatically changed from huh-rev to main December 9, 2024 16:18
@bashbunni
Copy link
Member

This works great for the Gum commands, though when working with a script (e.g. demo.sh) hitting ctrl+c skips the current gum command, but it would be great to be able to quit the whole script with ctrl+d. The changes here work as expected :) would be great to hear your thoughts on how we could exit the script though without having to skip all of the remaining gum commands

@caarlos0
Copy link
Member Author

caarlos0 commented Dec 9, 2024

@bashbunni it does work, but the script might need the set -euo pipefail options, e.g.:

#!/bin/bash
set -euo pipefail
time=$(gum input --placeholder "Timeout (in minutes)")
gum spin --timeout "${time}m" --show-output -- ping -c 50 google.com
echo "Done"
  • -e: exits on non-zero status
  • -u: errors on unset variables (not necessary for this example though)
  • -o pipefail: if a command in a pipe fails, returns its status code

these options are generally good to have on any scripts as they help preventing errors.

@caarlos0 caarlos0 merged commit 4f46952 into main Dec 9, 2024
14 checks passed
@caarlos0 caarlos0 deleted the interrupt branch December 9, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants