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

pacman animation interrupted #21

Closed
yousefvand opened this issue Jul 6, 2020 · 1 comment
Closed

pacman animation interrupted #21

yousefvand opened this issue Jul 6, 2020 · 1 comment

Comments

@yousefvand
Copy link
Owner

Handle interruption by user to restore cursor:

# Usage: pac_man inputString interval pad
# Example: pacman "Hello World" 0.5 "*"
function pac_man () {
  local string="$1"
  local interval="$2"
  : "${interval:=0.2}"
  local pad="$3"
  : "${pad:=.}"
  local length=${#string}
  local padding=""

  # Comment out next two lines if you are using CTRL+C event handler.
  trap 'tput cnorm; echo' EXIT
  trap 'exit 127' HUP INT TERM

  tput civis # hide cursor
  tput sc # save cursor position

  for((i=0;i<=length;i++)); do
    tput rc
    echo "$padding"c"${string:i:length}"
    sleep "$interval"
    tput rc
    echo "$padding"C"${string:i:length}"
    sleep "$interval"
    padding+="$pad"
  done

  tput cnorm
  tput rc
  echo "$padding"
}
yousefvand added a commit that referenced this issue Jul 7, 2020
@yousefvand
Copy link
Owner Author

Fixed by commit 9679b49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant