Skip to content

Commit

Permalink
consistentcy for commands.deprecated
Browse files Browse the repository at this point in the history
second part of 4ee1fa4 to maintain renames
  • Loading branch information
balupton committed Oct 23, 2024
1 parent d99a9a6 commit a37639d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 67 deletions.
3 changes: 3 additions & 0 deletions commands.deprecated/choose-menu
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ function choose_menu() (
source "$DOROTHY/sources/bash.bash"
dorothy-warnings add --code='choose-menu ...' --bold=' has been deprecated in favor of ' --code='choose --index ...'

# =====================================
# Action

choose --index "$@"
)

Expand Down
3 changes: 3 additions & 0 deletions commands.deprecated/choose-option
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ function choose_option() (
source "$DOROTHY/sources/bash.bash"
dorothy-warnings add --code='choose-option ...' --bold=' has been deprecated in favor of ' --code='choose ...'

# =====================================
# Action

choose "$@"
)

Expand Down
68 changes: 1 addition & 67 deletions commands.deprecated/echo-clear-line
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,10 @@ function echo_clear_line() (
source "$DOROTHY/sources/bash.bash"
dorothy-warnings add --code='echo-clear-line' --bold=' has been deprecated in favor of ' --code='echo-clear-lines' --bold=' or ' --code='echo-style --no-trail --delete-line'

# =====================================
# Arguments

function help {
cat <<-EOF >/dev/stderr
ABOUT:
Deletes the last outputted line, regardless of whether has a trailing line or not.
USAGE:
echo-clear-line
EOF
if test "$#" -ne 0; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}

# process
local item
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done

# =====================================
# Action

# echo $'one\ntwo\nthree'; echo-clear-line; echo $'four\nfive'
# outputs:
# one
# two
# four
# five

# https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences

# $'\u001b' = $'\e' = ESC (Escape Key)

# ESC [ = 0x9B = CSI (Control Sequence Introducer)
# Starts most of the useful sequences, terminated by a byte in the range 0x40 through 0x7E.[5]: 5.4

# CSI n A = CUU (Cursor Up)
# Moves the cursor n (default 1) cells in the given direction. If the cursor is already at the edge of the screen, this has no effect.

# CSI n J = ED (Erase in Display
# Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).

# CSI n K = EL (Erase in Line)
# Erases part of the line. If n is 0 (or missing), clear from cursor to the end of the line. If n is 1, clear from cursor to beginning of the line. If n is 2, clear entire line. Cursor position does not change.

# CSI n F = CPL (Cursor Previous Line)
# Moves cursor to beginning of the line n (default 1) lines up. (not ANSI.SYS)

# CSI n G = CHA (Cursor Horizontal Absolute)
# Moves the cursor to column n (default 1). (not ANSI.SYS)

# \e[A = move the cursor up 1 line
# \e[1K = clear from cursor to beginning of the line
# \e[2K = clear entire line
# \e[G = moves the cursor to column 1

# \e[F = Moves cursor to beginning of 1 lines up
# \e[J = clear from cursor to end of screen
printf '\e[F\e[J' # set cursor to the start of the prior line, and delete everything from there
# ^ correctly leaves no whitespace when no trailing line present
__print_string $'\e[F\e[J' # set cursor to the start of the prior line, and delete everything from there
)

# fire if invoked standalone
Expand Down

0 comments on commit a37639d

Please sign in to comment.