Skip to content

Commit

Permalink
echo-clear-lines: prep for improvements
Browse files Browse the repository at this point in the history
also revert broken WIP echo-clear-lines argument usage, with correct `< <(...)` usage
  • Loading branch information
balupton committed Oct 23, 2024
1 parent e8a0640 commit 713322d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
23 changes: 20 additions & 3 deletions commands/echo-clear-lines
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,33 @@ function echo_clear_lines() (
Deletes as many lines as it received.
USAGE:
... | echo-clear-lines [...options]
echo-clear-lines[...options] < ...
echo-clear-lines [...options] [--] ...<input>
echo-lines ...<input> | echo-clear-lines [...options]
OPTIONS:
--piped
If piping, provide this, otherwise don't.
--count=<count>
If provided, use this many lines rather than erasing lines as they happen.
$(stdinargs_options_help --)
EXAMPLE:
echo 'sup'
printf 'a\nb\nc'
echo-clear-lines -- $'a\nb\nc'
# ^ retains: sup
# ^ Note that the argument technique should be discouraged, as can cause [Argument list too long] error:
# https://github.com/bevry/dorothy/actions/runs/7622089094/job/20759535555#step:4:3259
echo 'sup'
printf 'a\nb\nc'
echo-clear-lines --stdin < <(printf 'a\nb\nc')
# ^ retains: sup
# ^ Use this instead of the arguments otpion, and do not use <<< as it prints a trailing newline, which would erase 'sup'.
echo 'sup'
printf 'a\nb\nc' | echo-clear-lines --piped
# ^ retains: sup
Expand All @@ -39,7 +55,7 @@ function echo_clear_lines() (
}

# process our own arguments, delegate everything else to stdinargs
local item option_piped='no' option_args=()
local item option_piped='no' option_count='' option_args=()
while test "$#" -ne 0; do
item="$1"
shift
Expand All @@ -48,6 +64,7 @@ function echo_clear_lines() (
'--no-piped'* | '--piped'*)
option_piped="$(get-flag-value --affirmative --fallback="$option_piped" -- "$item")"
;;
'--count='*) option_count="${item#*=}" ;;
# forward to stdinargs, however support mixing and matching of our options, with stdinarg options
'--')
option_args+=("$item" "$@")
Expand Down
2 changes: 1 addition & 1 deletion commands/eval-helper
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function eval_helper() (
export INSIDE_REVOLVING_DOOR="$INSIDE_REVOLVING_DOOR_original"

# clear header, we can re-add them later if needed
echo-clear-lines -- "$header" >"$terminal_device_file"
echo-clear-lines --stdin < <(__print_string "$header") >"$terminal_device_file"

# generate output
if test "$option_quiet" = 'no' -o "$cmd_status" -ne 0; then
Expand Down
5 changes: 2 additions & 3 deletions commands/setup-util
Original file line number Diff line number Diff line change
Expand Up @@ -3709,9 +3709,8 @@ function setup_util() (
if test "$run_status" -eq 0; then
# if is to fix: [is-internet-working; setup-util-bash --quiet] from clearning extra lines
if test -n "$run_output" -a "$option_quiet" != 'no'; then
# don't use arguments, as can result in: Argument list too long
# https://github.com/bevry/dorothy/actions/runs/7622089094/job/20759535555#step:4:3259
echo-clear-lines --stdin <<<"$run_output" >/dev/stderr # if the output is longer than $LINES then output beyond $LINES will not be cleared, the only way around that is to use tty_start and tty_finish however that incurs a signficant performance penalty, perhaps doing [2> (echo-revolving-door > /dev/stderr)] or something akin to this would work, however it had too many artifacts with [setup-util-warp --uninstall; setup-util-warp --install] with cask usage that uses sudo
# if the output is longer than $LINES then output beyond $LINES will not be cleared, the only way around that is to use tty_start and tty_finish however that incurs a signficant performance penalty, perhaps doing [2> (echo-revolving-door > /dev/stderr)] or something akin to this would work, however it had too many artifacts with [setup-util-warp --uninstall; setup-util-warp --install] with cask usage that uses sudo
echo-clear-lines --stdin < <(__print_string "$run_output") >/dev/stderr
fi
had_success='yes'
log_success "$method"
Expand Down
3 changes: 2 additions & 1 deletion commands/until-success
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function until_success() (
if test "$option_forever" = 'yes' -o "$attempt_status" -ne 0; then
waiter "$option_interval" --message="$(echo-style --notice='Next attempt in %s...')"
if test "$option_clear" = 'yes'; then
echo-clear-lines -- $'\n'"$attempt_output"$'\n' >"$terminal_device_file" # clear the header, output, and footer
# clear the header, output, and footer
echo-clear-lines --stdin < <(__print_string $'\n'"$attempt_output"$'\n') >"$terminal_device_file"
fi
attempt "$@"
fi
Expand Down

0 comments on commit 713322d

Please sign in to comment.