Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve handling ctrl+c and timeouts #747

Merged
merged 1 commit into from
Dec 9, 2024
Merged

feat: improve handling ctrl+c and timeouts #747

merged 1 commit into from
Dec 9, 2024

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

choose/choose.go Outdated Show resolved Hide resolved
confirm/confirm.go Outdated Show resolved Hide resolved
pager/command.go Outdated Show resolved Hide resolved
pager/pager.go Outdated Show resolved Hide resolved
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

choose/choose.go Show resolved Hide resolved
pager/pager.go Show resolved Hide resolved
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