

has_typed_input() {
  # https://zsh.org/mla/users/2022/msg00062.html
  emulate -L zsh
  zmodload zsh/zselect

  # Back up stty settings prior to disabling canonical mode
  # Consider that no input can be typed if stty fails
  # (this might happen if stdin is not a terminal)
  set -- termios
  # termios=$(stty --save 2>/dev/null) || return 1
  termios=$(stty --save 2>/dev/null)
  # shellcheck disable=SC2249
  case "${termios}" in
    0) return 1 ;;
    1)
      # disable canonical mode so that typed input counts
      # regardless of whether Enter was pressed
      stty -icanon
      # poll stdin (fd 0) for data ready to be read
      zselect -t 0 -r 0
      return $? ;;
  esac
    # always {
    # restore stty settings
    stty "${termios}"
    # }
}
