~proycon/asciinema-rec_script

65e54e9195ed2438177e1fa1731d461699a8c436 — Maarten van Gompel 1 year, 28 days ago fc72d11
use countdown everywhere and simplify it
1 files changed, 12 insertions(+), 31 deletions(-)

M bin/asciinema-rec_script
M bin/asciinema-rec_script => bin/asciinema-rec_script +12 -31
@@ 27,12 27,14 @@ build_augmented_script() { local script="$1"
      ;;
      *)
        echo "${COMMENT}$(echo "${1}" | $MARKDOWN)"
        if [[ ${#1} -gt 100 ]]; then
            sleep 5
        elif [[ ${#1} -lt 10 ]]; then
            sleep 3
        if [[ ${#1} -lt 12 ]]; then
            countdown 2
        elif [[ ${#1} -gt 100 ]]; then
            countdown 10
        elif [[ ${#1} -lt 30 ]]; then
            countdown 3
        else
            sleep 4
            countdown 4
        fi
      ;;
    esac


@@ 44,7 46,7 @@ build_augmented_script() { local script="$1"

    # A pause can be added between typing out characters in
    # the command to simulate typing
    TYPING_PAUSE=${TYPING_PAUSE:-0.001}
    TYPING_PAUSE=${TYPING_PAUSE:-0.025}

    type_out() { local text="$1"
      sleep "$PROMPT_PAUSE"


@@ 96,34 98,13 @@ build_augmented_script() { local script="$1"
    echo "(Powered by https://github.com/zechris/asciinema-rec_script)"
  }

  countdown() { local sleep_time=$1
    digit() {
      DIGITS=(0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ )
      echo "${DIGITS[$((($1 + 10) % 10))]} "
    }

    min() {
      m0=$(((i / 60 / 10 )))
      m1=$(((i / 60 % 10)))
      echo "$(digit $m0)$(digit $m1)"
    }

    sec() {
      s0=$(((i % 60 / 10)))
      s1=$(((i % 60 % 10)))
      echo "$(digit $s0)$(digit $s1)"
    }

    counter() { local sleep_time=$1
      if [[ $sleep_time -gt 59 ]]; then
        echo "$(min "$i")${COLON:-▫️ }$(sec "$i")"
      else
        sec "$i"
      fi
  countdown() {
    counter() {
        echo "($1)"
    }

    for i in $(seq "$1" -1 1); do
      printf "\r%s" "$(counter "$sleep_time")"
      printf "\r🕐  %ss" "$i"
      sleep 1
    done
    printf "\r           \r"