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

ask, choose, confirm: comprehensive support of TTY modes and capabilities #254

Merged
merged 51 commits into from
Oct 27, 2024

Conversation

balupton
Copy link
Member

@balupton balupton commented Oct 9, 2024

/close #253 #234

  • general:

    • use the correct quote/escape for the context
    • IFS='' to IFS= as they are equivalent
    • added a deprecation system with dorothy-warnings and commands.deprecated suggestions
    • change echo to either __print_line or __print_lines
    • compress multiple echo-style calls into a single call for performance
    • implement new styles where appropriate, however this is not comprehensive at all
    • rewrite quiet/verbose handling, now ignores the environment variable, which is a superior behaviour that prevents unexpected behaviour
  • docs:

    • add terminals-and-tty.md:
      • debug information from is-tty --test moved into new debug-terminal-(tty|stdin) and learnings documented in this doc file
    • add ``ansi-escape-codes.md`:
      • moved ansi escape code documentation from various commands in this doc file
    • prompts.md:
      • remove outdated information and update with latest coventions
    • readme:
  • ci:

    • dorothy-workflow.yml:
      • support testing on branches and forks
      • remove unnecessary deps
    • shellcheckrc:
      • ignore SC2016, it is always intentional
      • ignore SC2059, it is always intentional
      • add docs on all the disabled rules
  • deprecate tty.bash, choose-menu, choose-option, echo-clear-line, echo-color-enabled, echo-element, echo-quiet-enabled, echo-title, is-color-enabled, is-interactive, is-match, is-quiet-enabled, is-tty

    • refer to their source code or their warning messages for their replacements
    • is-tty --test debug information moved into debug-terminal-(stdin|tty) beta commands, and add more information
    • add get-terminal-alternative-support
    • add get-terminal-color-support:
      • if ci isn't github, continue to fail, however if dumb terminal and not ci, continue to fallback
        • this enables fallback on ssh -T ..., which does support colors
    • add get-terminal-cursor-line-and-column
    • add get-terminal-device-file
    • add get-terminal-lines-and-columns
    • add get-terminal-position-support
    • add get-terminal-quiet-support:
      • adapt for the get-terminal-color-support convention, however keep same functionality, this could be a mistake - will need to evaluate
    • add get-terminal-reactivity-support
    • add get-terminal-size-support
    • add get-terminal-title-support:
      • vscode doesn't support titles, so fail on vscode
    • add get-terminal-tty-support
  • move echo-exit-affirmative, echo-mkdir, echo-nothing-or-fail to beta commands as they are no longer (or were never) used internally

  • stdinargs.bash:

    • rewrite to use [[ ... ]] instead of test/[ to better handle edge cases, such as a trailing line containing only >
  • bash.bash:

    • remove deprecated usage of __print_line ..., use __print_lines ... instead
    • support initial -- argument in appropriate functions
    • rewrite to use [[ ... ]] instead of test/[ to better handle edge cases
    • add __substr shim, fix for cpr and echo-style
    • fix escape quoting in mapfile shim for bash v3
    • add some common helpers for performance, and use them wherever appropriate
      • add __is_brew, __command_(missing|exists), __try_sudo, __is_brew, __mkdirp, __sudo_mkdirp, __escape_shapeshifting, __is_shapeshifter, __can_read_decimal_timeout
      • I did add has_needles however it wasn't justified compared to continuing is-needle
  • zsh.zsh:

    • consistency with bash.bash changes
  • styles.bash and echo-style:

    • styles.bash:
      • check various support abilities at the begining for clarity and performance
      • add styles for various ansi escape codes, for consolidation, and to ensure correct escape codes are used based on support, including that of newline
      • change clear screen to use \e[J instead of \e[2J for reasoning documented inside the file
      • if the alternative screen buffer is not used, then adapt the screen buffer and clear screen styles to be a newline and clear screen instead, this makes it so that even if clear screen is not supported, the newline still ensures things are visually separated, which works great for GitHub Actions
      • fix broken code_notice style and replace to code-notice1
      • rejigged styles for ask, choose, and confirm to be consistent and to support no-TTY mode
      • ensure that refreshed styles have their color and no color styles set appropriately
    • echo-style:
      • support --=..., --=, -- arguments
      • echo-style --tty instead of echo-style >/dev/tty as the former can support when /dev/tty doesn't exist
  • ask, choose, confirm, read-key, is-shapeshifter, echo-count-lines, echo-clear-lines, echo-revolving-door, echo-wrap, eval-helper:

    • significant changes to support no-TTY mode and to support all known edge cases
    • consistent commentary, result, and exception styling
    • ask:
      • rewrote for modern conventions and new stdin/tty learnings, properly supports no-TTY
      • fix read failures not being output
      • if non-reactive, use alternative screen buffer
        • added --no-inline option to force usage of alternative screen buffer if supported/reactive
        • this solves the impossibility of clearing the accurate amount of lines in no-TTY mode, as ssh -T and pipe/redirect/CI result in different line counts due to ssh -T outputting the enter key as a visual new line
    • choose:
      • don't crash on unknown keys, instead flash bell
      • improve performance of legend rendering
      • don't hide/show cursor on environments that don't support it
      • don't try to update the title on environments that don't support it
      • auto-select solo required item for git-helper use case
      • fix blockquote line being a different color or breaking colors
    • confirm:
      • rewrote for no-TTY support, looks and behave differently, now being clear about all options and appropriate keys
      • also fixes a bug with --required not always enforcing requirement
      • rejig color and no-color rendering
    • eval-helper:
      • fix undefined columns
    • echo-clear-lines:
      • rewritten to support all known edge cases
      • --piped option has been removed, a new --here-string argument has been added
      • it calls echo-wrap to ensure correct behaviour
      • supports --column=* alias for --width=*, and supports --count=* option if we already know how many lines we want to clear
    • echo-count-lines:
      • note in its help that it does not wrap lines
    • echo-revolving-door:
      • rewrote to fix all known edge cases
    • echo-wrap:
      • fix help errors not showing, support --column=* alias for --width=*
    • is-shapeshifter:
      • rewrote and add tests, to fix all known edge cases
      • now uses bash.bash helpers
    • read-key:
      • went through and redid all the keys
      • add (ctrl|alt|shift)+(left|right) macos keys, add ctrl+a (all key)
      • rewrote for no-TTY support, and now supports multiple keys, as such callers need to take note
      • supporting multiple keys is essential in line buffer mode or when in bash v3 (bash v3 has a delay in which multiple keys may be sent)
      • will now output unknown keys
  • brew:

    • fix duplication in error messages and improve styling
  • brew-installed:

    • support --quiet argument
    • return exit status 46 if brew is not installed
  • (command-(exists|missing|working)|is-(brew|needle)):

    • add tests
    • command-working:
      • if the command is missing, return exit status 3 instead of 1
  • debug-network:

    • fix bad maintenance over the years
    • add comment to avoid 632e605
  • dorothy:

    • install coreutils on alpine, remove ps dependency
    • fix bad remote_name automation
    • prompt for lint upgrade before dev deps, to speed up UX
    • moved common helpers into bash.bash, and improved them
    • source the bash.bash that is appropriately local or remote
    • rejig clone and update to support slug/branch/reference/remote-name, properly enabling support for branches, PRs, and forks
    • remove update technique for legacy dorothy installations
      • turns out the modern technique was always failing due to issues in git-helper which are now resolved
      • the legacy technique is for before git-helper existed, and it has existed for a long time now, multiple years
    • add __eval_wrap helper for debug clarity
  • ask, dorothy, setup-util-bash, setup-util-gh

    • use new get-terminal-reactivity-support command instead of the deprecated is-interactive
  • dorothy, dorothy-warnings, init.*:

    • added dorothy-warnings for deprecations and other warnings
    • warnings will be output on new terminal instances if there are new warnings
  • dorothy, fs-realpath, symlink-helper:

    • detect when alpine uses busybox or coreutils and react accordingly
      • readlink on alpine's busybox doesn't support needed options
      • realpath on alpine's busybox doesn't support any options
    • move alpine's busybox implementation to fallback
    • fix alpine symlink failures
    • symlink-helper:
      • fix situation when the symlink is broken
  • echo-regexp, echo-regexp.ts:

    • fix including stdinargs.bash when it didn't need to
    • better support for character classes, supporting [[:XXX:]] and [:XXX:] forms
  • echo-file and get-terminal-theme:

    • add get-terminal-theme --ignore-cache option
    • correctly handle bat theme in cases where theme could not be detected, such as inside ssh -T
    • improve the styling of bat and plain output
  • echo-quote, echo-escape-command, echo-escape-bash, echo-lines, config-helper, dorothy-config, fs-size, mount-helper, nvm-env, setup-dns, sudo-helper, video-merge, and so on:

    • use appropriate quote format for the context
    • echo-lines and config-helper:
      • --quote= option now supports the type of quote format you want
      • in config-helper this will default to autodetection based on the filetype we are writing to
    • echo-quote:
      • add tests
      • support --single and --double arguments
  • (echo-(html|url)-coder|fs-dequarantine|get-desktop-theme|setup-util-(1password-cli|apple-(cli-tools|rosetta)|yt-dlp)):

    • fix incorrect function names
  • echo-escape-special:

    • fix everything being dumped together
  • echo-mkdir:

    • moved to beta commands as it is no longer used internally
    • fixed it never actually working
  • echo-nothing-or-fail:

    • moved to beta commands as it is no longer used internally
    • fixed it never actually working
  • echo-substr new command:

    • as command alias for __substr helper in bash.bash
  • echo-wait:

    • rejig some logic for clarity
  • expand-path-zsh renamed to expand-path.zsh:

    • also rewrote for clarity and modern conventions
  • fs-rm:

    • note when moving to trash is not available
  • get-font:

    • improve performance
  • get-installer:

    • add aliases for setup-util-ps
  • git-helper:

    • improve the way remotes and protocols are gathered
    • add verify action and step
    • fix path not sent to review action
    • correctly handle no remotes, no origin, and multiple remotes
  • is-abort:

    • remove ignore-empty option, and hardcode how it is handled
  • is-nonempty-file:

    • add help and options
  • setup-util:

    • redid the clearing functionality to implement modern conventions and support a wide range of edge cases, such as when installer outputs more than LINES, or when clear is not available, or when the installer needs interaction
    • don't remove non-xdg-bins when upgrading as that causes issues with homebrew if the homebrew-installed bin was removed but homebrew still thinks it is installed
    • improve performance by using new bash.bash helpers
    • improve performance by reducing separate echo-style calls
    • if uninstalling/upgrading the currently executing bash, output a warning
    • only output the installer output if there was output
    • improved performance by merging a few redundant calls
    • output to /dev/tty if supported and appropriate
  • setup-util-bash:

    • compact echo-style calls for performance, include setup-util --check for performance
    • improvements to clearing
    • two workarounds implemented for when uninstalling/upgrading the currently executing bash
      • we will try to reload the command with an alternative bash
      • if unable to load an alternative bash, a notice will be outputted on what to expect
  • setup-environment-commands:

    • improve performance on rubygems
    • improve performance by using new bash.bash helpers
    • add support for commands.deprecated
  • setup-mac-brew:

    • verify homebrew git repo is setup correctly with new git-helper verify action
  • setup-util-node:

    • verify nvm git repo is setup correctly with new git-helper verify action
  • add setup-util-ps

  • until-success:

    • rewrote for new TTY conventions
    • things that should be output to the terminal device file are now outputted there
    • added --delay=... alias for --interval=...
  • waiter:

    • removed vestigial --magic option
  • what-is-running:

    • support ps and procs, and install the appropriate fallback if both are missing
  • video-merge:

    • use is-headful which is appropriate, instead of the deprecated is-tty
  • oz:

    • cleanup a little bit, now that docs are elsewhere
  • new beta commands:

    • added echo-revolving-screen command that unfortunately doesn't work properly and I don't know why

merged commits:

This adds support for no-TTY, such as a CI environment, or via `ssh -T ...` to `choose`.

However, this rewrites `read-key` to support such, and there needs further work as it still sends multiple characters in a single line under certain circumstances.

However, `read-key` now does support no-TTY situations, such as pipes, or bash v3 character mashing.

The complexity with this, is that there is no way native to just read one key at a time, and escape sequences can take multiple characters, as such the approach taken is to trim known escape sequences and then split the remaining. This is fine, however it means read-key now only supports known characters, and as such is more adequate to be considered a read-keyboard-key or so, as special escape sequences will require a lot of complexity to support, as they will need say our regex handling in `echo-wrap.awk` to be trimmed.

This all means that `read-key` should be changed instead of reading one key at a time, now in an aggregate, it should just read everything and then shift the keys off.
- `read-key` and `confirm` have been rewritten
- `bash.bash`: add `__command_(missing|exists)`, `__try_sudo`, `__is_brew`, `__mkdirp`, `__sudo_mkdirp`, and `__can_read_decimal_timeout`
- `(command-(exists|missing)|is-brew)`: use the `bash.bash` functions
- `(command-(exists|missing|working)|is-brew)`: add tests
- `debug-network:` fix bad maintenance over the years
- `dorothy`:
    - move common helpers into `bash.bash`, and improve them
    - source the `bash.bash` that is appropriately local or remote
- `(echo-(html|url)-coder|fs-dequarantine|get-desktop-theme|setup-util-(1password-cli|apple-(cli-tools|rosetta)|yt-dlp))`: fix functional incorrect function names
- `expand-path-zsh` renamed to `expand-path.zsh` to follow modern conventions
- `get-font`: improve performance
- `is-tty`: remove unneeded `echo`s for modern conventions in tests
- `setup-util`: conjoined a few redundant calls
- `echo-mkdirp`: moved to beta commands as it is no longer used internally
@balupton balupton self-assigned this Oct 9, 2024
@balupton balupton force-pushed the dev/fix-253 branch 4 times, most recently from 90f75d5 to 5b8aa12 Compare October 10, 2024 02:39
/ref c7f31b1 - `option_commands` leftover in `bash.bash` helpers
/ref b60ef24 - use new `is_remote` var that is accurate
@balupton balupton force-pushed the dev/fix-253 branch 8 times, most recently from 3756222 to 1aecee3 Compare October 11, 2024 07:06
@balupton balupton force-pushed the dev/fix-253 branch 3 times, most recently from f0af795 to 555d324 Compare October 24, 2024 03:32
…ing issue when testing

get-terminal-position-support: fix crash when stdin not accessible

get-terminal-tty-support: expand debug information to look for ways to ensure ask is only clearing input if it needed to

is-interactive: simplify conditional logic

read-key, is-shapeshifter: add (ctrl|alt)+(left|right) macos keys

dorothy, dorothy-warnings: only output warnings by default if there are new warnings
@balupton balupton force-pushed the dev/fix-253 branch 5 times, most recently from bf9d37a to ef37005 Compare October 25, 2024 05:05
- add `debug-terminal-(stdin|tty)`
- simplify `get-terminal-*-support` checks
- `IFS=''` to `IFS=` as they are equivalent
- get-terminal-theme: add `--ignore-cache` option
- echo-file: correctly handle bat theme in cases where theme could not be detected, such as inside `ssh -T`
ask:
- if non-reactive, use alternative screen buffer
- add `--no-inline` option to force usage of alternative screen buffer if supported/reactive
- this solves the impossibility of clearing the accurate amount of lines in no-TTY mode, as `ssh -T` and pipe/redirect/CI result in different line counts due to `ssh -T` outputting the enter key as a visual new line

dorothy, setup-util-bash, setup-util-gh: use new `get-terminal-reactivity-support` command, and deprecate `is-interactive`

add a `terminals-and-tty.md` document with the learnings and reasoning

dorothy-warnings: prevent clearing of warnings causing warnings to be shown
/ref https://github.com/bevry/dorothy/actions/runs/11512899768

also fix `echo-regexp` including `stdinargs.bash` when it didn't need to
@balupton balupton changed the title WIP: ask, choose, confirm: better support no-TTY mode ask, choose, confirm: better support no-TTY mode Oct 26, 2024
Copy link
Member Author

@balupton balupton left a comment

Choose a reason for hiding this comment

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

all good

commands/command-working Show resolved Hide resolved
@balupton balupton marked this pull request as ready for review October 26, 2024 08:32
@balupton balupton changed the title ask, choose, confirm: better support no-TTY mode ask, choose, confirm: support no-TTY mode Oct 26, 2024
@balupton balupton changed the title ask, choose, confirm: support no-TTY mode ask, choose, confirm: appropriate support for various TTY modes and features Oct 26, 2024
@balupton balupton changed the title ask, choose, confirm: appropriate support for various TTY modes and features ask, choose, confirm: support for various TTY modes and features Oct 26, 2024
@balupton balupton changed the title ask, choose, confirm: support for various TTY modes and features ask, choose, confirm: better support for various TTY modes and capabilities Oct 26, 2024
@balupton balupton changed the title ask, choose, confirm: better support for various TTY modes and capabilities ask, choose, confirm: comprehensive support for TTY modes and capabilities Oct 26, 2024
@balupton balupton changed the title ask, choose, confirm: comprehensive support for TTY modes and capabilities ask, choose, confirm: comprehensive support of TTY modes and capabilities Oct 26, 2024
@balupton balupton merged commit c4d1e1f into master Oct 27, 2024
23 checks passed
@balupton balupton deleted the dev/fix-253 branch October 27, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Bug: choose without TTY (paging unsupported) will not render properly
1 participant