diff --git a/README.md b/README.md index 62aa51ff2..58ae7e3f6 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,7 @@ Stable commands: - [`bash.bash`](https://github.com/bevry/dorothy/tree/master/sourcces/bash.bash) for a Bash strict mode that actually works, and various shims/polyfills - [`ask`](https://github.com/bevry/dorothy/tree/master/commands/ask), [`confirm`](https://github.com/bevry/dorothy/tree/master/commands/confirm), and [`choose`](https://github.com/bevry/dorothy/tree/master/commands/choose) for prompting the user for input - - [`echo-style`](https://github.com/bevry/dorothy/tree/master/commands/echo-style), [`echo-segment`](https://github.com/bevry/dorothy/tree/master/commands/echo-segment), [`echo-element`](https://github.com/bevry/dorothy/tree/master/commands/echo-element), [`echo-error`](https://github.com/bevry/dorothy/tree/master/commands/echo-error), [`echo-verbose`](https://github.com/bevry/dorothy/tree/master/commands/echo-verbose), and [`eval-helper`](https://github.com/bevry/dorothy/tree/master/commands/eval-helper) for output styling + - [`echo-style`](https://github.com/bevry/dorothy/tree/master/commands/echo-style), [`echo-error`](https://github.com/bevry/dorothy/tree/master/commands/echo-error), [`echo-verbose`](https://github.com/bevry/dorothy/tree/master/commands/echo-verbose), and [`eval-helper`](https://github.com/bevry/dorothy/tree/master/commands/eval-helper) for output styling - Dozens of `echo-*`, `fs-*`, `get-*`, and `is-*` helpers Beta commands: diff --git a/commands.beta/eject-all b/commands.beta/eject-all index c29b14b64..b083372bf 100755 --- a/commands.beta/eject-all +++ b/commands.beta/eject-all @@ -35,11 +35,11 @@ function eject_all() ( # ===================================== # Action - echo-segment --h1='eject-all' + echo-style --h1='eject-all' - echo-segment --h2='before' + echo-style --h2='before' ls /Volumes - echo-segment --g2='before' + echo-style --g2='before' eval-helper --quiet \ --pending="$(echo-style --bold='Ejecting...')" \ @@ -47,11 +47,11 @@ function eject_all() ( --failure="$(echo-style --error='Failed to eject.')" \ -- osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)' - echo-segment --h2='after' + echo-style --h2='after' ls /Volumes - echo-segment --g2='after' + echo-style --g2='after' - echo-segment --h1='eject-all' + echo-style --h1='eject-all' ) # fire if invoked standalone diff --git a/commands.beta/itunes-owners b/commands.beta/itunes-owners index 96a2aff5d..034658aed 100755 --- a/commands.beta/itunes-owners +++ b/commands.beta/itunes-owners @@ -47,24 +47,24 @@ function itunes_owners() ( owner_list="$(fs-temp --directory='itunes-owners' --file='owner.txt' --touch)" missing_list="$(fs-temp --directory='itunes-owners' --file='missing.txt' --touch)" database="$HOME/Music/iTunes/iTunes Music Library.xml" - echo-style --h2="Reading $database" + echo-style --header2="Reading $database" # fetch songs local song_count=0 function fetch_songs { - echo-style --h2="Fetching songs to $song_list" + echo-style --header2="Fetching songs to $song_list" rg --only-matching --regexp='file://(.+)' --replace='$1' <"$database" | echo-url-decode --stdin | echo-html-decode --stdin >"$song_list" song_count="$(wc -l <"$song_list" | xargs)" - echo-style --g2="...found $song_count media files." + echo-style --good2="...found $song_count media files." } fetch_songs # @todo use eval-helper # fetch owners function fetch_owners { local song owner - echo-style --h2="Fetching owners to $owner_list" + echo-style --header2="Fetching owners to $owner_list" while read -r song; do # check if test ! -f "$song"; then @@ -93,15 +93,15 @@ function itunes_owners() ( owner_count="$(__print_line "$owners" | wc -l | xargs)" owned_count="$(wc -l <"$owner_list" | xargs)" - echo-style --h2="$owner_count UNIQUE OWNERS:" + echo-style --header2="$owner_count UNIQUE OWNERS:" __print_line "$owners" echo - echo-style --h2="$owned_count OWNED MEDIA:" + echo-style --header2="$owned_count OWNED MEDIA:" sort <"$owner_list" | column -t -s $'\t' echo - echo-style --h2="$(wc -l <"$missing_list" | xargs) MISSING MEDIA:" + echo-style --header2="$(wc -l <"$missing_list" | xargs) MISSING MEDIA:" sort <"$missing_list" echo ) diff --git a/commands.beta/macos-state b/commands.beta/macos-state index fd27cfc9c..920483fc3 100755 --- a/commands.beta/macos-state +++ b/commands.beta/macos-state @@ -271,7 +271,7 @@ function macos_state() ( function process { local title="$1" paths=("${@:1}") path='' - echo-segment --h1 "$title" + echo-style --h1 "$title" if confirm --linger --bool --ppid=$$ -- "Do you want to $action $title"; then for path in "${paths[@]}"; do if test "$action" = 'backup'; then @@ -283,7 +283,7 @@ function macos_state() ( else echo-style --dim="Skipped..." fi - echo-segment --g1 "$title" + echo-style --g1 "$title" } # =============== diff --git a/commands.beta/setup-server b/commands.beta/setup-server index 46d1e81c2..4dca4dcfb 100755 --- a/commands.beta/setup-server +++ b/commands.beta/setup-server @@ -21,9 +21,9 @@ function setup_server() ( local DRIVE_MOUNT=() VAULT_MOUNT=() SAMBA_MOUNT=() local PLEX_HOME='' SYNCTHING_HOME='' TRANSMISSION_HOME='' local NORDVPN_TOKEN='' NORDVPN_DNS='' # 1.1.1.1 or 192.168.5.20 or whatever - echo-segment --h2='server configuration' + echo-style --h2='server configuration' load_dorothy_config 'server.bash' - echo-segment --g2='server configuration' + echo-style --g2='server configuration' # ------------------------------------- # Adjustments diff --git a/commands/ask b/commands/ask index c5b136efe..4880e000d 100755 --- a/commands/ask +++ b/commands/ask @@ -2,7 +2,7 @@ function ask_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='default response -confirm' --stdout='a default response' \ -- ask --skip-default --question='What is your response?' --default='a default response' @@ -82,7 +82,7 @@ function ask_test() ( # @todo add tests for timout - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function ask_() ( diff --git a/commands/choose b/commands/choose index 32137711c..5797ee85a 100755 --- a/commands/choose +++ b/commands/choose @@ -12,7 +12,7 @@ function choose_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" ## choose-menu ## @@ -131,7 +131,7 @@ function choose_test() ( } | eval-tester --name='abort response via escape' \ -- choose --question='abort response via escape' -- a b c - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function choose_() ( @@ -284,179 +284,117 @@ function choose_() ( help 'No s provided.' fi - # styles for items: - # one hollow circle: ⚬ ○ ◯ ❍ - # two hollow circles: ◎ ⦾ ⊚ - # one hollow, one full: ☉ ⦿ ◉ - # one full: ● - # ▣ ▢ □ ⊡ - # ☑ ☒ ⌧ - # ✓ ✔ ✖ ✗ ✘ - # - # conclusions for cursor: - # doesn't space correctly in Terminal: ⸻ - # too small: → ☞ ➡ - # too unclear: ► - # gets turned into an emoji: ➡️ - # other options: ▶▷▸▹⏵⯈ - local \ - _temp \ - color_reset \ - color_bold \ - color_dim \ - color_underline \ - color_invert \ - color_framed \ - color_background_intense_white \ - color_background_white \ - color_disable_background \ - color_disable_foreground \ - color_disable_framed \ - color_disable_intensity \ - color_disable_invert \ - color_foreground_black \ - color_foreground_green \ - color_foreground_intense_white \ - color_foreground_intense_green \ - color_foreground_intense_magenta \ - color_foreground_intense_yellow \ - color_foreground_white \ - color_foreground_yellow \ - icon_active \ - icon_default \ - icon_standard \ - style_count_more_begin \ - style_count_more_end \ - style_count_default_begin \ - style_count_default_end \ - style_count_selected_begin \ - style_count_selected_end \ - style_help_begin \ - style_help_end \ - style_key_begin \ - style_key_begin \ - style_key_end \ - style_key_end \ - style_key_indent=' ' \ - style_active_line \ - style_selected_line \ - style_default_line - if test "$use_colors" = 'no'; then - color_reset='' - color_bold='' - color_dim='' - color_underline='' - color_disable_intensity='' - color_invert='' - color_framed='' - color_disable_background='' - color_disable_foreground='' - color_disable_framed='' - color_disable_invert='' - color_foreground_black='' - color_foreground_green='' - color_foreground_intense_white='' - color_foreground_intense_black='' - color_foreground_intense_green='' - color_foreground_intense_magenta='' - color_foreground_intense_yellow='' - color_foreground_white='' - color_foreground_yellow='' - style_help_begin='' - style_help_end='' - style_key_begin='[' - style_key_end=']' - style_active_line='' - style_selected_line='' - style_default_line='' - else - color_reset=$'\e[0m' - color_bold=$'\e[1m' - color_dim=$'\e[2m' - color_underline=$'\e[4m' - color_disable_intensity=$'\e[22m' - color_invert=$'\e[7m' - color_framed=$'\e[51m' - color_disable_background=$'\e[49m' - color_disable_foreground=$'\e[39m' - color_disable_framed=$'\e[54m' - color_disable_invert=$'\e[27m' - color_foreground_black=$'\e[30m' - color_foreground_green=$'\e[32m' - color_foreground_intense_white=$'\e[97m' - color_foreground_intense_black=$'\e[90m' - color_foreground_intense_green=$'\e[92m' - color_foreground_intense_magenta=$'\e[95m' - color_foreground_intense_yellow=$'\e[93m' - color_foreground_white=$'\e[37m' - color_foreground_yellow=$'\e[33m' - color_background_white=$'\e[47m' - color_background_intense_white=$'\e[107m' - style_active_line="$color_invert" - style_count_default_begin="$color_foreground_yellow" - style_count_selected_begin="$color_foreground_green" - if test "$(get-terminal-theme || :)" = 'dark'; then - style_count_more_begin="$color_foreground_white" - style_count_more_end="$color_disable_foreground" - style_help_begin="$color_dim" # dim is better than white, nice separation - style_key_begin="${color_foreground_black}${color_background_white} " - style_default_line="$color_foreground_intense_yellow" - style_selected_line="$color_foreground_intense_green" - else - # style_count_more_begin="$color_foreground_black" # same as the items, too confusing - # style_count_more_end="$color_disable_foreground" - style_count_more_begin="$color_foreground_intense_black" # not enough distinction from the items, however, dim is too dim - style_count_more_end="$color_disable_foreground" - # style_count_more_begin="$color_dim" # not readable enough - # style_count_more_end="$color_disable_intensity" - style_help_begin="$color_foreground_intense_black" - style_key_begin="${color_background_intense_white} " # foreground default black, background intense white - # for count and selected, intense is too bright, dim is too light - style_default_line="$color_foreground_yellow" - style_selected_line="$color_foreground_green" - fi - style_count_default_end="$color_disable_foreground" - style_count_selected_end="$color_disable_foreground" - style_help_end="$color_reset" - style_key_end=" $color_reset" - fi + # ===================================== + # Styles + + source "$DOROTHY/sources/config.sh" + + # styles.bash provides: + # all style variables + load_dorothy_config 'styles.bash' + + # select icons if test "$option_multi" = 'yes'; then - icon_selected='▣' - icon_default='⊡' - icon_active='⊡' - icon_standard='□' + style__icon_selected="$style__icon_multi_selected" + style__icon_default="$style__icon_multi_default" + style__icon_active="$style__icon_multi_active" + style__icon_standard="$style__icon_multi_standard" else - icon_selected='⦿' # only used in confirmation and linger - icon_default='⦾' + style__icon_selected="$style__icon_single_selected" + style__icon_default="$style__icon_single_default" if test "$option_required" = 'yes'; then - icon_active='◉' + style__icon_active="$style__icon_single_active_required" else - icon_active='⦿' + style__icon_active="$style__icon_single_active_optional" fi - icon_standard='○' + style__icon_standard="$style__icon_single_standard" fi - function render_key { - local result - result="${style_help_begin}$1${style_help_end} " - shift - while test "$#" -ne 0; do - result+="${style_key_begin}$1${style_key_end}" - shift - if test "$#" -ne 0; then - result+=' ' - fi - done - __print_line "$result" - } - function indent_key { - __print_line "${style_key_indent}$(render_key "$@")" - } + + # select colors + if test "$use_colors" = 'yes'; then + # spacers + style__count_spacer="${style__color__count_spacer-}" + # lines + style__result_line="${style__color__result_line-}" + style__end__result_line="${style__color_end__result_line-}" + style__active_line="${style__color__active_line-}" + style__end__active_line="${style__color_end__active_line-}" + style__selected_line="${style__color__selected_line-}" + style__end__selected_line="${style__color_end__selected_line-}" + style__default_line="${style__color__default_line-}" + style__end__default_line="${style__color_end__default_line-}" + style__empty_line="${style__color__empty_line-}" + style__end__empty_line="${style__color_end__empty_line-}" + style__inactive_line="${style__color__inactive_line-}" + style__end__inactive_line="${style__color_end__inactive_line-}" + # legend + style__legend="${style__color__legend-}" + style__end__legend="${style__color_end__legend-}" + style__key="${style__color__key-}" + style__end__key="${style__color_end__key-}" + # paging counts + style__count_more="${style__color__count_more-}" + style__end__count_more="${style__color_end__count_more-}" + style__count_selected="${style__color__count_selected-}" + style__end__count_selected="${style__color_end__count_selected-}" + style__count_default="${style__color__count_default-}" + style__end__count_default="${style__color_end__count_default-}" + style__count_empty="${style__color__count_empty-}" + style__end__count_empty="${style__color_end__count_empty-}" + # paging headers + style__bar_top="${style__color__bar_top-}" + style__end__bar_top="${style__color_end__bar_top-}" + style__bar_middle="${style__color__bar_middle-}" + style__end__bar_middle="${style__color_end__bar_middle-}" + style__bar_bottom="${style__color__bar_bottom-}" + style__end__bar_bottom="${style__color_end__bar_bottom-}" + else + # spacers + style__count_spacer="${style__nocolor__count_spacer-}" + # lines + style__result_line="${style__nocolor__result_line-}" + style__end__result_line="${style__nocolor_end__result_line-}" + style__active_line="${style__nocolor__active_line-}" + style__end__active_line="${style__nocolor_end__active_line-}" + style__selected_line="${style__nocolor__selected_line-}" + style__end__selected_line="${style__nocolor_end__selected_line-}" + style__default_line="${style__nocolor__default_line-}" + style__end__default_line="${style__nocolor_end__default_line-}" + style__empty_line="${style__nocolor__empty_line-}" + style__end__empty_line="${style__nocolor_end__empty_line-}" + style__inactive_line="${style__nocolor__inactive_line-}" + style__end__inactive_line="${style__nocolor_end__inactive_line-}" + # legend + style__legend="${style__nocolor__legend-}" + style__end__legend="${style__nocolor_end__legend-}" + style__key="${style__nocolor__key-}" + style__end__key="${style__nocolor_end__key-}" + # paging counts + style__count_more="${style__nocolor__count_more-}" + style__end__count_more="${style__nocolor_end__count_more-}" + style__count_selected="${style__nocolor__count_selected-}" + style__end__count_selected="${style__nocolor_end__count_selected-}" + style__count_default="${style__nocolor__count_default-}" + style__end__count_default="${style__nocolor_end__count_default-}" + style__count_empty="${style__nocolor__count_empty-}" + style__end__count_empty="${style__nocolor_end__count_empty-}" + # paging headers + style__bar_top="${style__nocolor__bar_top-}" + style__end__bar_top="${style__nocolor_end__bar_top-}" + style__bar_middle="${style__nocolor__bar_middle-}" + style__end__bar_middle="${style__nocolor_end__bar_middle-}" + style__bar_bottom="${style__nocolor__bar_bottom-}" + style__end__bar_bottom="${style__nocolor_end__bar_bottom-}" + fi + + # ===================================== + # Menu # adjust question local question_title question_with_body if test "${#option_question[@]}" -ne 0; then # bash v3 compat if test -n "${option_question[0]}"; then - question_title="$color_underline$color_bold${option_question[0]}$color_reset" + question_title="$(echo-style --underline+bold="${option_question[0]}")" question_with_body="$(__print_lines "$question_title" "${option_question[@]:1}")" else question_title="$(__print_lines "${option_question[@]:1}")" @@ -476,6 +414,7 @@ function choose_() ( function __fuzzy_haystack_needle { local haystack="$1" needle="$2" [[ "$(__lowercase_string "$haystack")" == *"$(__lowercase_string "$needle")"* ]] + return } # prepare label handling @@ -589,52 +528,52 @@ function choose_() ( bin_gfold='' \ bin_gwc='' \ commentary='' \ - items_last_index \ + terminal_margin=0 \ + content_columns \ items_count="${#items[@]}" \ + items_last_index \ + items_renders=() \ + items_rows=() \ + legend_cancel_content legend_cancel_rendering legend_cancel_rows \ + legend_cancel_rows \ + legend_choose_content legend_choose_rendering legend_choose_rows \ + legend_choose_content='' \ + legend_choose_rows \ + legend_confirm_content legend_confirm_rendering legend_confirm_rows \ + legend_confirm_content='' \ + legend_confirm_rows \ menu_bottom_index_choose=0 \ menu_bottom_index_confirm=0 \ menu_cursor_choose=0 \ menu_cursor_confirm=0 \ menu_direction=1 \ menu_header_shrunk='' \ - menu_header_size \ + menu_header_rows \ menu_header='' \ - menu_skip_render='no' \ - menu_hint_extras_cancel='' \ - menu_hint_extras_choose='' \ - menu_hint_extras_confirm='' \ - menu_hint_main_choose='' \ - menu_hint_main_confirm='' \ - menu_hint_render_cancel='' \ - menu_hint_render_choose='' \ - menu_hint_render_confirm='' \ - menu_hint_size_cancel \ - menu_hint_size_choose \ - menu_hint_size_confirm \ menu_mode='choose' \ + menu_skip_render='no' \ menu_status=0 \ menu_top_index_choose=0 \ menu_top_index_confirm=0 \ paging_supported='yes' \ paging_used \ - renders=() \ - size_columns_prior=0 \ - size_columns=80 \ - size_content=75 \ - size_rows_prior=0 \ - size_rows=10 \ - sizes=() \ + terminal_columns_prior=0 \ + terminal_columns=80 \ + terminal_rows_prior=0 \ + terminal_rows=10 \ tty_target items_last_index="$((items_count - 1))" - mapfile -t renders < <(get-array "$items_count") - mapfile -t sizes < <(get-array "$items_count") + mapfile -t items_renders < <(get-array "$items_count") + mapfile -t items_rows < <(get-array "$items_count") # prepare paging tty_target="$(is-tty --fallback)" if test "$tty_target" = '/dev/stderr' || command-missing tput; then # fix [tput: No value for $TERM and no -T specified] errors when fetching columns and rows on CI paging_supported='no' - # @todo multi-line items won't + style__hide_cursor='' + style__show_cursor='' + # @todo multi-line items won't else if is-mac; then bin_gfold="$(type -P 'gfold' 2>/dev/null || :)" @@ -653,118 +592,122 @@ function choose_() ( fi # prepare hints - # prefer key names if possible, as people don't know the symbols - if test "$option_multi" = 'yes'; then - menu_hint_main_cancel+="$(render_key 'CONFIRM CANCELATION' 'ENTER' 'E')" - menu_hint_main_choose+="$(render_key 'SELECT' 'SPACE')" - menu_hint_main_choose+="$(indent_key 'CONFIRM' 'ENTER' 'E')" - menu_hint_main_confirm+="$(render_key 'CONFIRM SELECTION' 'ENTER' 'E')" - else - menu_hint_main_cancel+="$(render_key 'CONFIRM CANCELATION' 'SPACE' 'ENTER' 'E')" - menu_hint_main_choose+="$(render_key 'SELECT' 'SPACE' 'ENTER' 'E')" - menu_hint_main_confirm+="$(render_key 'CONFIRM SELECTION' 'SPACE' 'ENTER' 'E')" - fi - menu_hint_main_cancel+="$(indent_key 'ABORT CANCELATION' 'ESC' 'Q')" - menu_hint_main_confirm+="$(indent_key 'CHANGE SELECTION' 'ESC' 'Q')" - _temp="$(indent_key 'ABORT' 'CTRL C')" - menu_hint_extras_cancel+="$_temp" - menu_hint_extras_confirm+="$_temp" - if test "$can_cancel" = 'yes'; then - # cancel restores defaults (if multi) or selects none (if non-multi) and leaves - menu_hint_main_choose+="$(indent_key 'CANCEL' 'ESC' 'Q')" - fi - if test "$items_count" -ne 1; then - # [⬆⬇⇧] have alignment issues, use [↑↓] - _temp="$(indent_key 'UP' '↑' 'W' 'K')" - _temp+="$(indent_key 'DOWN' '↓' 'S' 'J')" - menu_hint_main_choose+="$_temp" - menu_hint_extras_cancel+="$_temp" - menu_hint_extras_confirm+="$_temp" - # comment out self-explanatory keys - # menu_hint_extras_choose+="$(indent_key 'FIRST' 'HOME', 'fn ⇧ ↑')" - # menu_hint_extras_choose+="$(indent_key 'LAST' 'END', 'fn ⇧ ↓')" - # menu_hint_extras_choose+="$(indent_key 'PAGE UP' '←' 'A' 'H')" - # menu_hint_extras_choose+="$(indent_key 'PAGE DOWN' '→' 'D' 'L')" - if test "$option_multi" = 'yes'; then - # comment out self-explanatory keys - # menu_hint_extras_choose+="$(indent_key 'SELECT & NEXT' '+' 'INSERT')" - # menu_hint_extras_choose+="$(indent_key 'SELECT & PREV' '-')" - # menu_hint_extras_choose+="$(indent_key 'UNSELECT & NEXT' 'DELETE')" - # menu_hint_extras_choose+="$(indent_key 'UNSELECT & PREV' 'BACKSPACE')" - menu_hint_extras_choose+="$(indent_key 'ALL/NONE' 'T')" - fi - fi - if test "$can_revert_to_defaults" = 'yes'; then - menu_hint_extras_choose+="$(indent_key 'NEXT PREF' 'TAB')" # next preference - menu_hint_extras_choose+="$(indent_key 'PREV PREF' '⇧ TAB')" # prior preference - menu_hint_extras_choose+="$(indent_key 'RESET' 'Z')" # reset preferences - fi if test -n "$question_with_body"; then # @todo only bold the first question line menu_header="$question_with_body"$'\n' fi - # @todo: FILTER [asd] SHOWING [2] HIDING [19] TOTAL [21] TOGGLE [F] - - # this is too slow to recalculate on each interaction - # @todo why isn't this called? - function refresh_menu_hint { - local which="$1" main extras render cleaned size - if test "$which" = 'choose'; then - main="$menu_hint_main_choose" - extras="$menu_hint_extras_choose" - elif test "$which" = 'cancel'; then - main="$menu_hint_main_cancel" - extras="$menu_hint_extras_cancel" - else - main="$menu_hint_main_confirm" - extras="$menu_hint_extras_confirm" + function add_legend_keys { + # extract the current state + local name="$1" legend="$2" keys=("${@:3}") var content rendering total last index key shrunk rows + var="${name}_rendering" + rendering="${!var}" + if test "$rendering" = 'no'; then + return 0 + fi + var="${name}_content" + content="${!var}" + total="${#keys[@]}" + last="$((total - 1))" + + # render the legend keys + # this could be cached, but no need, reitems_rows are rare enough it doesn't matter + if test -n "$content"; then + content+="$style__legend_legend_spacer" fi - # see if the hint supports exctras - render="$main$extras" - cleaned="$(echo-trim-colors -- "$render" | "$bin_gfold" -w "$size_columns")" - size="$("$bin_gwc" -l <<<"${cleaned}")" - if test "$size" -gt 1; then - # the menu hint does not have enough room for extras - render="$main" - cleaned="$(echo-trim-colors -- "$render" | "$bin_gfold" -w "$size_columns")" - size="$("$bin_gwc" -l <<<"${cleaned}")" + content+="${style__legend}${legend}${style__end__legend}${style__legend_key_spacer}" + for ((index = 0; index < total; index++)); do + key="${keys[index]}" + content+="${style__key}${key}${style__end__key}" + if test "$index" -ne "$last"; then + content+="${style__key_key_spacer}" + fi + done + shrunk="$(echo-trim-colors -- "$content" | "$bin_gfold" -w "$terminal_columns")" + rows="$("$bin_gwc" -l <<<"$shrunk")" + if test "$rows" -le 1; then + eval "${name}_content=\"\$content\"" + eval "${name}_rows=\"\$rows\"" + else + eval "${name}_rendering='no'" fi - # apply - if test "$which" = 'choose'; then - menu_hint_render_choose="$render" - menu_hint_size_choose="$size" - elif test "$which" = 'cancel'; then - menu_hint_render_cancel="$render" - menu_hint_size_cancel="$size" + } + function reset_legends { + legend_cancel_content='' + # trunk-ignore(shellcheck/SC2034) + legend_cancel_rendering='yes' + legend_cancel_rows=0 + legend_choose_content='' + # trunk-ignore(shellcheck/SC2034) + legend_choose_rendering='yes' + legend_choose_rows=0 + legend_confirm_content='' + # trunk-ignore(shellcheck/SC2034) + legend_confirm_rendering='yes' + legend_confirm_rows=0 + } + function render_lengends { + reset_legends + # prefer key names if possible, as people don't know the symbols + if test "$option_multi" = 'yes'; then + add_legend_keys 'legend_cancel' 'CONFIRM CANCELATION' 'ENTER' 'E' + add_legend_keys 'legend_choose' 'SELECT' 'SPACE' + add_legend_keys 'legend_choose' 'CONFIRM' 'ENTER' 'E' + add_legend_keys 'legend_confirm' 'CONFIRM SELECTION' 'ENTER' 'E' else - menu_hint_render_confirm="$render" - menu_hint_size_confirm="$size" + add_legend_keys 'legend_cancel' 'CONFIRM CANCELATION' 'SPACE' 'ENTER' 'E' + add_legend_keys 'legend_choose' 'SELECT' 'SPACE' 'ENTER' 'E' + add_legend_keys 'legend_confirm' 'CONFIRM SELECTION' 'SPACE' 'ENTER' 'E' + fi + add_legend_keys 'legend_cancel' 'ABORT CANCELATION' 'ESC' 'Q' + add_legend_keys 'legend_confirm' 'CHANGE SELECTION' 'ESC' 'Q' + add_legend_keys 'legend_cancel' 'ABORT' 'CTRL C' + add_legend_keys 'legend_confirm' 'ABORT' 'CTRL C' + if test "$can_cancel" = 'yes'; then + # cancel restores defaults (if multi) or selects none (if non-multi) and leaves + add_legend_keys 'legend_choose' 'CANCEL' 'ESC' 'Q' + fi + if test "$items_count" -ne 1; then + # [⬆⬇⇧] have alignment issues, use [↑↓] + add_legend_keys 'legend_choose' 'UP' '↑' 'W' 'K' + add_legend_keys 'legend_choose' 'DOWN' '↓' 'S' 'J' + if test "$can_revert_to_defaults" = 'yes'; then + add_legend_keys 'legend_choose' 'NEXT PREF' 'TAB' # next preference + add_legend_keys 'legend_choose' 'PREV PREF' '⇧ TAB' # prior preference + add_legend_keys 'legend_choose' 'RESET' 'Z' # reset preferences + if test "$option_multi" = 'yes'; then + add_legend_keys 'legend_choose' 'ALL/NONE' 'T' + fi + fi + add_legend_keys 'legend_choose' 'PAGE UP' '←' 'A' 'H' + add_legend_keys 'legend_choose' 'PAGE DOWN' '→' 'D' 'L' + add_legend_keys 'legend_choose' 'FIRST' 'HOME', 'fn ⇧ ↑' + add_legend_keys 'legend_choose' 'LAST' 'END', 'fn ⇧ ↓' + if test "$option_multi" = 'yes'; then + add_legend_keys 'legend_choose' 'SELECT & NEXT' '+' 'INSERT' + add_legend_keys 'legend_choose' 'SELECT & PREV' '-' + add_legend_keys 'legend_choose' 'UNSELECT & NEXT' 'DELETE' + add_legend_keys 'legend_choose' 'UNSELECT & PREV' 'BACKSPACE' + fi fi } function refresh_terminal_size { if test "$paging_supported" = 'no'; then paging_used='no' - menu_hint_render_cancel="$menu_hint_main_cancel" - menu_hint_render_choose="$menu_hint_main_confirm" - menu_hint_render_confirm="$menu_hint_main_confirm" - menu_hint_size_cancel=0 - menu_hint_size_choose=0 - menu_hint_size_confirm=0 + content_columns="$((terminal_columns - terminal_margin))" + reset_legends else - size_rows="$(tput lines)" - size_columns="$(tput cols)" + terminal_rows="$(tput lines)" + terminal_columns="$(tput cols)" # only recalculate everything if the size actually changed from last time - if test "$size_rows" -ne "$size_rows_prior" -o "$size_columns" -ne "$size_columns_prior"; then - size_content="$((size_columns - 5))" + if test "$terminal_rows" -ne "$terminal_rows_prior" -o "$terminal_columns" -ne "$terminal_columns_prior"; then + content_columns="$((terminal_columns - terminal_margin))" # calculate menu header size - menu_header_shrunk="$(echo-trim-colors -- "$menu_header" | "$bin_gfold" -w "$size_columns")" - menu_header_size="$("$bin_gwc" -l <<<"${menu_header_shrunk}")" - # see if the hint supports exctras - refresh_menu_hint 'cancel' - refresh_menu_hint 'choose' - refresh_menu_hint 'confirm' + menu_header_shrunk="$(echo-trim-colors -- "$menu_header" | "$bin_gfold" -w "$terminal_columns")" + menu_header_rows="$("$bin_gwc" -l <<<"${menu_header_shrunk}")" + # refresh the legends + render_lengends # move start index to current item, as otherwise it could be out of range - if test "$size_rows" -lt "$size_rows_prior" -o "$size_columns" -lt "$size_columns_prior"; then + if test "$terminal_rows" -lt "$terminal_rows_prior" -o "$terminal_columns" -lt "$terminal_columns_prior"; then # @todo we should detect if showing everything is possible before resorting to this menu_top_index_choose="$menu_cursor_choose" menu_bottom_index_choose="$menu_cursor_choose" @@ -773,11 +716,11 @@ function choose_() ( fi # reset paging for new size paging_used='maybe' - mapfile -t renders < <(get-array "$items_count") - mapfile -t sizes < <(get-array "$items_count") + mapfile -t items_renders < <(get-array "$items_count") + mapfile -t items_rows < <(get-array "$items_count") # update priors - size_rows_prior="$size_rows" - size_columns_prior="$size_columns" + terminal_rows_prior="$terminal_rows" + terminal_columns_prior="$terminal_columns" fi fi } @@ -1084,10 +1027,20 @@ function choose_() ( function set_menu_mode { local new="$1" # sanity check if confirm is appropriate - if test "$new" = 'confirm' -a "$option_required" = 'yes' -a "$selected_count" -eq 0; then - menu_skip_render='yes' - menu_mode='choose' - return 0 + if test "$option_required" = 'yes'; then + if test "$new" = 'confirm'; then + if test "$selected_count" -eq 0; then + menu_skip_render='yes' + menu_mode='choose' + return 0 + fi + elif test "$new" = 'cancel'; then + if test "$defaults_count" -eq 0; then + menu_skip_render='yes' + menu_mode='choose' + return 0 + fi + fi fi # check if we need to recalculate paging and update the mode if test "$new" != "$menu_mode"; then @@ -1104,25 +1057,40 @@ function choose_() ( local debug_counter=0 function render_menu { local \ + bar_bottom_content='' \ + bar_bottom_selected_count=0 \ + bar_bottom_suffix='' \ + bar_bottom_unselected_defaults_count=0 \ + bar_middle_content='' \ + bar_middle_selected_count=0 \ + bar_middle_suffix='' \ + bar_middle_unselected_defaults_count=0 \ + bar_top_content='' \ + bar_top_selected_count=0 \ + bar_top_suffix='' \ + bar_top_unselected_defaults_count=0 \ + index \ item_index=0 \ item_line \ item_original \ item_rendered \ - item_size \ - items_bundled_size=0 \ + item_rows \ + items_bundled_rows=0 \ items_bundled='' \ line_prefix \ - line_style \ + line_begin \ + line_end \ menu_bottom_index \ menu_cursor \ - menu_hint_render \ - menu_hint_size \ menu_index=0 \ - menu_total \ menu_last_index \ - menu_size=0 \ + menu_legend_content \ + menu_legend_rows \ + menu_rows=0 \ menu_title='' \ menu_top_index \ + menu_total \ + page_count \ verb # refresh the terminal size refresh_terminal_size @@ -1131,8 +1099,8 @@ function choose_() ( verb='Selected' menu_bottom_index="$menu_bottom_index_choose" menu_cursor="$menu_cursor_choose" - menu_hint_render="$menu_hint_render_choose" - menu_hint_size="$menu_hint_size_choose" + menu_legend_content="$legend_choose_content" + menu_legend_rows="$legend_choose_rows" menu_total="$items_count" menu_last_index="$items_last_index" menu_top_index="$menu_top_index_choose" @@ -1141,14 +1109,14 @@ function choose_() ( verb='Cancel to' menu_total="$defaults_count" menu_last_index="$defaults_last_index" - menu_hint_render="$menu_hint_render_cancel" - menu_hint_size="$menu_hint_size_cancel" + menu_legend_content="$legend_cancel_content" + menu_legend_rows="$legend_cancel_rows" else verb='Confirm' menu_total="$selected_count" menu_last_index="$selected_last_index" - menu_hint_render="$menu_hint_render_confirm" - menu_hint_size="$menu_hint_size_confirm" + menu_legend_content="$legend_confirm_content" + menu_legend_rows="$legend_confirm_rows" fi # @todo, consider having these and cursors for cancel as well, instead of sharing with confirm menu_bottom_index="$menu_bottom_index_confirm" @@ -1180,11 +1148,10 @@ function choose_() ( menu_bottom_index="$menu_index" # debug function debug { - printf '%s' $'\e]0;'"c=$menu_cursor,mi=$menu_index,ii=$item_index,d=$menu_direction,t=$menu_top_index,b=$menu_bottom_index,l=$menu_last_index,u=$paging_used,s=$menu_size,r=$size_rows,c=$debug_counter"$'\a' >"$tty_target" + printf '%s' $'\e]0;'"c=$menu_cursor,mi=$menu_index,ii=$item_index,d=$menu_direction,t=$menu_top_index,b=$menu_bottom_index,l=$menu_last_index,u=$paging_used,r=$menu_rows,c=$debug_counter"$'\a' >"$tty_target" debug_counter="$((debug_counter + 1))" } # e.g. go to second page, navigate half way, go page up - local page_visible_selected_count=0 page_visible_unselected_defaults_count=0 for (( ; menu_index >= 0 && menu_index <= menu_last_index; menu_index += menu_direction)); do if test "$menu_mode" = 'choose'; then item_index="$menu_index" @@ -1194,70 +1161,73 @@ function choose_() ( item_index="${selected_indexes[menu_index]}" fi # determine prefix - line_prefix='' - line_style='' if test "$menu_index" -eq "$menu_cursor"; then - line_style+="$style_active_line" - line_prefix+='⏵ ' + line_begin="$style__active_line" + line_prefix="$style__indent_active" + line_end="$style__end__active_line" else - line_prefix+=' ' + line_begin="$style__inactive_line" + line_prefix="$style__indent_inactive" + line_end="$style__end__inactive_line" fi if test "${selected[item_index]-}" = 'yes' -a "$menu_mode" != 'cancel'; then - line_style+="$style_selected_line" - line_prefix+="$icon_selected " - page_visible_selected_count="$((page_visible_selected_count + 1))" + line_begin+="$style__selected_line" + line_prefix+="${style__icon_selected}" + line_end+="$style__end__selected_line" + bar_middle_selected_count="$((bar_middle_selected_count + 1))" elif test "${defaults[item_index]-}" = 'yes'; then - line_style+="$style_default_line" - line_prefix+="$icon_default " - page_visible_unselected_defaults_count="$((page_visible_unselected_defaults_count + 1))" + line_begin+="$style__default_line" + line_prefix+="${style__icon_default}" + line_end+="$style__end__default_line" + bar_middle_unselected_defaults_count="$((bar_middle_unselected_defaults_count + 1))" elif test "$menu_index" -eq "$menu_cursor"; then - line_prefix+="$icon_active " + line_prefix+="${style__icon_active}" else - line_prefix+="$icon_standard " + line_prefix+="${style__icon_standard}" fi - line_prefix="${line_style}${line_prefix}" + line_prefix="${line_begin}${line_prefix}" # determine paging if test "$paging_used" = 'no'; then # paging is no longer needed, no recalculations needed - if test -n "${renders[item_index]}"; then + if test -n "${items_renders[item_index]}"; then # use rendered item (in case it needed to be formatted if it exists) - item_line="${line_prefix}${renders[item_index]}${color_reset}"$'\n' + item_line="${line_prefix}${items_renders[item_index]}${line_end}"$'\n' else # otherwise use original item - item_line="${line_prefix}${items[item_index]}${color_reset}"$'\n' + item_line="${line_prefix}${items[item_index]}${line_end}"$'\n' fi else # paging is needed, so we must recalculate bundled size - if test -n "${renders[item_index]}"; then - item_rendered="${renders[item_index]}" - item_size="${sizes[item_index]}" + if test -n "${items_renders[item_index]}"; then + item_rendered="${items_renders[item_index]}" + item_rows="${items_rows[item_index]}" else item_original="${items[item_index]}" - if test "${#item_original}" -lt "$size_content" && [[ $item_original != *$'\n'* && $item_original != *$'\t'* ]]; then + if test "${#item_original}" -lt "$content_columns" && [[ $item_original != *$'\n'* && $item_original != *$'\t'* ]]; then # no need to format item, as it is small enough item_rendered="$item_original" - item_size=1 - renders[item_index]="$item_rendered" - sizes[item_index]="$item_size" + item_rows=1 + items_renders[item_index]="$item_rendered" + items_rows[item_index]="$item_rows" else # need to format item, as it is too big - item_rendered="$("$bin_gfmt" -t -w "$size_content" <<<"$item_original")" + item_rendered="$("$bin_gfmt" -t -w "$content_columns" <<<"$item_original")" item_rendered="${item_rendered//$'\n'/$'\n '}" - item_size="$("$bin_gwc" -l <<<"${item_rendered}")" - renders[item_index]="$item_rendered" - sizes[item_index]="$item_size" + item_rows="$("$bin_gwc" -l <<<"${item_rendered}")" + items_renders[item_index]="$item_rendered" + items_rows[item_index]="$item_rows" fi fi # calculate total menu size - menu_size="$((menu_header_size + items_bundled_size + item_size + menu_hint_size + 2))" - if test "$menu_size" -gt "$size_rows"; then + menu_rows="$((menu_header_rows + items_bundled_rows + item_rows + menu_legend_rows + 3))" + if test "$menu_rows" -gt "$terminal_rows"; then # the menu would now be too large, so skip the rest item_line='' break else - item_line="${line_prefix}${item_rendered}${color_reset}"$'\n' - items_bundled_size="$((items_bundled_size + item_size))" + item_line="${line_prefix}${item_rendered}${line_end}"$'\n' + items_bundled_rows="$((items_bundled_rows + item_rows))" fi fi # append or prepend the line to the bundle @@ -1292,7 +1262,7 @@ function choose_() ( # if paging was used, and we could support more rows, then re-render in the other direction # @todo update menu_index instead of cursor, so that cursor remains sensible (optional, may not be a good idea) - if test "$paging_used" = 'yes' -a "$menu_size" -lt "$size_rows"; then + if test "$paging_used" = 'yes' -a "$menu_rows" -lt "$terminal_rows"; then if test "$menu_direction" -eq -1 -a "$menu_top_index" -eq 0; then # we can show more items, so re-render in the other direction if test "$menu_mode" = 'choose'; then @@ -1315,71 +1285,58 @@ function choose_() ( fi fi - # calculate headers and footers - local page_header='' page_visible='' page_footer='' page_count - if test "$paging_supported" = 'yes'; then - page_count="$((menu_bottom_index - menu_top_index + 1))" - # [ 5 above: 1 selected, 3 preferences] - # ... 5 above: 1 selected, 3 preferences ... - # └┘┌┐ 5 above: 1 selected, 3 preferences ... - # └ 5 above, 1 selected, 3 preferences ┘ - # ┌ 5 above | 1 selected | 3 preferences ┐ - # … - # [ no above ] - ### - # ┌ BELOW: 376 below ∙ 45 selected ∙ 8 unselected defaults ┐ - # .. - # ├ ABOVE: 5 items ∙ 22 selected ┤ - # ├ SHOWN: 30 items ∙ 24 selected ∙ 8 unselected defaults ┤ - # ... - # ├ BELOW: 283 items ┤ - # ... - # └ ABOVE: 376 below ∙ 45 selected ∙ 8 unselected defaults ┘ - local index \ - page_header_selected_count=0 \ - page_header_unselected_defaults_count=0 \ - page_footer_selected_count=0 \ - page_footer_unselected_defaults_count=0 \ - page_hint_indent=' ' \ - color_symbol_start="$color_foreground_intense_black" color_symbol_end="$color_disable_foreground" - local below_open_symbol="${color_symbol_start}┌${color_symbol_end}" below_close_symbol="${color_symbol_start}┐${color_symbol_end}" \ - continue_open_symbol="${color_symbol_start}├${color_symbol_end}" continue_close_symbol="${color_symbol_start}┤${color_symbol_end}" \ - above_open_symbol="${color_symbol_start}└${color_symbol_end}" above_close_symbol="${color_symbol_start}┘${color_symbol_end}" \ - sep_symbol="${color_symbol_start}∙${color_symbol_end}" - local header_close_symbol='' visibile_close_symbol="$continue_close_symbol" footer_close_symbol='' - # ⏺ = too big - # ∶ - # ⌜ ⌝ ⌞ ⌟ - # ⌌ ⌍ ⌎ ⌏ - # ╭ ╮ ╯ ╰ + # reset direction + if test "$menu_direction" -eq -1; then + menu_direction=1 + fi + # calculate page top, middle, bottom + if test -z "$items_bundled"; then + page_count=0 + if test "$menu_mode" = 'choose'; then + bar_top_content+="${style__indent_bar}${style__bar_top}${style__count_empty}choose from nothing below${style__end__count_empty}${style__end__bar_top}"$'\n' + items_bundled="${style__active_line}${style__empty_line}${style__indent_active}[ nothing provided ]${style__end__empty_line}${style__end__active_line}"$'\n' + bar_bottom_content+="${style__indent_bar}${style__bar_bottom}${style__count_empty}choose from nothing above${style__end__count_empty}${style__end__bar_bottom}"$'\n' + elif test "$menu_mode" = 'cancel'; then + bar_top_content+="${style__indent_bar}${style__bar_top}${style__count_default}cancel with nothing selected${style__end__count_empty}${style__end__bar_top}"$'\n' + items_bundled="${style__active_line}${style__empty_line}${style__indent_active}[ no selection ]${style__end__empty_line}${style__end__active_line}"$'\n' + bar_bottom_content+="${style__indent_bar}${style__bar_bottom}${style__count_default}cancel with nothing selected${style__end__count_empty}${style__end__bar_bottom}"$'\n' + else + bar_top_content+="${style__indent_bar}${style__bar_top}${style__count_selected}confirm with nothing selected${style__end__count_empty}${style__end__bar_top}"$'\n' + items_bundled="${style__active_line}${style__empty_line}${style__indent_active}[ no selection ]${style__end__empty_line}${style__end__active_line}"$'\n' + bar_bottom_content+="${style__indent_bar}${style__bar_bottom}${style__count_selected}confirm with nothing selected${style__end__count_empty}${style__end__bar_bottom}"$'\n' + fi + elif test "$paging_supported" = 'yes'; then + page_count="$((menu_bottom_index - menu_top_index + 1))" # calculate header counts if test "$menu_top_index" -eq 0; then if test "$menu_mode" = 'choose'; then # choose: fetch all below - page_header+="${page_hint_indent}${below_open_symbol} ${style_count_more_begin}choose any $menu_total below${style_count_more_end}" - page_header_selected_count="$selected_count" + bar_top_content+="${style__indent_bar}${style__bar_top}${style__count_more}choose any $menu_total below${style__end__count_more}" + bar_top_selected_count="$selected_count" for index in "${default_indexes[@]}"; do if test "${selected[index]-}" = 'yes'; then continue fi - page_header_unselected_defaults_count="$((page_header_unselected_defaults_count + 1))" + bar_top_unselected_defaults_count="$((bar_top_unselected_defaults_count + 1))" done elif test "$menu_mode" = 'cancel'; then - page_header+="${page_hint_indent}${below_open_symbol} ${style_count_default_begin}cancel to all $menu_total defaults below${style_count_default_end}" + # cancel: fetch all defaults below + bar_top_content+="${style__indent_bar}${style__bar_top}${style__count_default}cancel to all $menu_total defaults below${style__end__count_default}" else - page_header+="${page_hint_indent}${below_open_symbol} ${style_count_selected_begin}confirm all $menu_total selected below${style_count_selected_end}" + # confirm: confirm all selected below + bar_top_content+="${style__indent_bar}${style__bar_top}${style__count_selected}confirm all $menu_total selected below${style__end__count_selected}" fi - header_close_symbol="$below_close_symbol" + bar_top_suffix="$style__end__bar_top" else if test "$menu_mode" = 'choose'; then # choose: fetch more above - page_header+="${page_hint_indent}${continue_open_symbol} ${style_count_more_begin}$menu_top_index more above${style_count_more_end}" + bar_top_content+="${style__indent_bar}${style__bar_middle}${style__count_more}$menu_top_index more above${style__end__count_more}" for index in "${selected_indexes[@]}"; do if test "$index" -ge "$menu_top_index"; then break fi - page_header_selected_count="$((page_header_selected_count + 1))" + bar_top_selected_count="$((bar_top_selected_count + 1))" done for index in "${default_indexes[@]}"; do if test "$index" -ge "$menu_top_index"; then @@ -1388,110 +1345,115 @@ function choose_() ( if test "${selected[index]-}" = 'yes'; then continue fi - page_header_unselected_defaults_count="$((page_header_unselected_defaults_count + 1))" + bar_top_unselected_defaults_count="$((bar_top_unselected_defaults_count + 1))" done elif test "$menu_mode" = 'cancel'; then - page_header+="${page_hint_indent}${continue_open_symbol} ${style_count_default_begin}$menu_top_index more defaults above${style_count_default_end}" + bar_top_content+="${style__indent_bar}${style__bar_middle}${style__count_default}$menu_top_index more defaults above${style__end__count_default}" else - page_header+="${page_hint_indent}${continue_open_symbol} ${color_foreground_green}$menu_top_index more selected above${color_disable_foreground}" + bar_top_content+="${style__indent_bar}${style__bar_middle}${style__count_selected}$menu_top_index more selected above${style__end__count_selected}" fi - header_close_symbol="$continue_close_symbol" + bar_top_suffix="$style__end__bar_middle" fi # calculate bottom counts if test "$menu_bottom_index" -eq "$menu_last_index"; then if test "$menu_mode" = 'choose'; then # choose: fetch all above - page_footer+="${page_hint_indent}${above_open_symbol} ${style_count_more_begin}choose any $menu_total above${style_count_more_end}" - page_footer_selected_count="$selected_count" + bar_bottom_content+="${style__indent_bar}${style__bar_bottom}${style__count_more}choose any $menu_total above${style__end__count_more}" + bar_bottom_selected_count="$selected_count" for index in "${default_indexes[@]}"; do if test "${selected[index]-}" = 'yes'; then continue fi - page_footer_unselected_defaults_count="$((page_footer_unselected_defaults_count + 1))" + bar_bottom_unselected_defaults_count="$((bar_bottom_unselected_defaults_count + 1))" done elif test "$menu_mode" = 'cancel'; then - page_footer+="${page_hint_indent}${above_open_symbol} ${style_count_default_begin}cancel to all $menu_total defaults above${style_count_default_end}" + # cancel: fetch all defaults above + bar_bottom_content+="${style__indent_bar}${style__bar_bottom}${style__count_default}cancel to all $menu_total defaults above${style__end__count_default}" else - page_footer+="${page_hint_indent}${above_open_symbol} ${style_count_selected_begin}confirm all $menu_total selected above${style_count_selected_end}" + # confirm: confirm all selected above + bar_bottom_content+="${style__indent_bar}${style__bar_bottom}${style__count_selected}confirm all $menu_total selected above${style__end__count_selected}" fi - footer_close_symbol="$above_close_symbol" + bar_bottom_content+="$style__end__bar_bottom" else index="$((menu_last_index - menu_bottom_index))" if test "$menu_mode" = 'choose'; then # choose: fetch more below - page_footer+="${page_hint_indent}${continue_open_symbol} ${style_count_more_begin}$index more below${style_count_more_end}" + bar_bottom_content+="${style__indent_bar}${style__bar_middle}${style__count_more}$index more below${style__end__bar_top}" for index in "${selected_indexes[@]}"; do if test "$index" -le "$menu_bottom_index"; then continue fi - page_footer_selected_count="$((page_footer_selected_count + 1))" + bar_bottom_selected_count="$((bar_bottom_selected_count + 1))" done for index in "${default_indexes[@]}"; do if test "$index" -le "$menu_bottom_index" -o "${selected[index]-}" = 'yes'; then continue fi - page_footer_unselected_defaults_count="$((page_footer_unselected_defaults_count + 1))" + bar_bottom_unselected_defaults_count="$((bar_bottom_unselected_defaults_count + 1))" done elif test "$menu_mode" = 'cancel'; then - page_footer+="${page_hint_indent}${continue_open_symbol} ${style_count_default_begin}cancel to $index more defaults below${style_count_default_end}" + # cancel: fetch more defaults below + bar_bottom_content+="${style__indent_bar}${style__bar_middle}${style__count_default}cancel to $index more defaults below${style__end__count_default}" else - page_footer+="${page_hint_indent}${continue_open_symbol} ${style_count_selected_begin}confirm $index more selected below${style_count_selected_end}" + # confirm: confirm more selected below + bar_bottom_content+="${style__indent_bar}${style__bar_middle}${style__count_selected}confirm $index more selected below${style__end__count_selected}" fi - footer_close_symbol="$continue_close_symbol" + bar_bottom_content+="$style__end__bar_middle" fi # add selected and unslected defaults counts if test "$menu_mode" = 'choose'; then - if test "$page_header_selected_count" -ne 0; then - page_header+=" ${sep_symbol} ${style_count_selected_begin}${page_header_selected_count} selected${style_count_selected_end}" + # choose: add top counts + if test "$bar_top_selected_count" -ne 0; then + bar_top_content+="${style__count_spacer}${style__count_selected}${bar_top_selected_count} selected${style__end__count_selected}" fi - if test "$page_header_unselected_defaults_count" -ne 0; then - page_header+=" ${sep_symbol} ${style_count_default_begin}${page_header_unselected_defaults_count} unselected defaults${style_count_default_end}" + if test "$bar_top_unselected_defaults_count" -ne 0; then + bar_top_content+="${style__count_spacer}${style__count_default}${bar_top_unselected_defaults_count} unselected defaults${style__end__count_default}" fi - page_visible+="${page_hint_indent}${continue_open_symbol} ${style_count_more_begin}$page_count visible${style_count_more_end}" - if test -n "$page_visible"; then - if test "$page_visible_selected_count" -ne 0; then - page_visible+=" ${sep_symbol} ${style_count_selected_begin}${page_visible_selected_count} selected${style_count_selected_end}" + # choose: add middle counts + if test "$paging_used" = 'yes'; then + bar_middle_content+="${style__indent_bar}${style__bar_middle}${style__count_more}$page_count visible${style__end__bar_top}" + if test "$bar_middle_selected_count" -ne 0; then + bar_middle_content+="${style__count_spacer}${style__count_selected}${bar_middle_selected_count} selected${style__end__count_selected}" fi - if test "$page_visible_unselected_defaults_count" -ne 0; then - page_visible+=" ${sep_symbol} ${style_count_default_begin}${page_visible_unselected_defaults_count} unselected defaults${style_count_default_end}" + if test "$bar_middle_unselected_defaults_count" -ne 0; then + bar_middle_content+="${style__count_spacer}${style__count_default}${bar_middle_unselected_defaults_count} unselected defaults${style__end__count_default}" fi + bar_middle_suffix="$style__end__bar_middle" fi - if test "$page_footer_selected_count" -ne 0; then - page_footer+=" ${sep_symbol} ${style_count_selected_begin}${page_footer_selected_count} selected${style_count_selected_end}" + # choose: add bottom counts + if test "$bar_bottom_selected_count" -ne 0; then + bar_bottom+="${style__count_spacer}${style__count_selected}${bar_bottom_selected_count} selected${style__end__count_selected}" fi - if test "$page_footer_unselected_defaults_count" -ne 0; then - page_footer+=" ${sep_symbol} ${style_count_default_begin}${page_footer_unselected_defaults_count} unselected defaults${style_count_default_end}" + if test "$bar_bottom_unselected_defaults_count" -ne 0; then + bar_bottom+="${style__count_spacer}${style__count_default}${bar_bottom_unselected_defaults_count} unselected defaults${style__end__count_default}" fi elif test "$menu_mode" = 'cancel'; then - page_visible+="${page_hint_indent}${continue_open_symbol} ${style_count_default_begin}$page_count visible${style_count_default_end}" + # cancel: add middle counts + bar_middle_content+="${style__indent_bar}${style__bar_middle}${style__count_default}$page_count visible${style__end__count_default}" + bar_middle_suffix="$style__end__bar_middle" else - page_visible+="${page_hint_indent}${continue_open_symbol} ${style_count_selected_begin}$page_count visible${style_count_selected_end}" + # confirm: add middle counts + bar_middle_content+="${style__indent_bar}${style__bar_middle}${style__count_selected}$page_count visible${style__end__count_selected}" + bar_middle_suffix="$style__end__bar_middle" fi - page_header+=" ${header_close_symbol}"$'\n' - if test -n "$page_visible"; then - page_visible+=" ${visibile_close_symbol}"$'\n' + bar_top_content+="${bar_top_suffix}"$'\n' + if test -n "$bar_middle_content"; then + bar_middle_content+="${bar_middle_suffix}"$'\n' fi - page_footer+=" ${footer_close_symbol}"$'\n' - fi - - # reset direction - if test "$menu_direction" -eq -1; then - menu_direction=1 + bar_bottom_content+="${bar_bottom_suffix}"$'\n' fi # output menu - if test -z "$items_bundled"; then - items_bundled="${color_dim}[ nothing provided ]"$'\n' - fi if test "$paging_used" = 'yes'; then menu_title=$'\e]0;'"👉 $verb $menu_total of $items_count items 💁‍♀️ Viewing $page_count of $items_count items [$((menu_top_index + 1))…$((menu_cursor + 1))…$((menu_bottom_index + 1))] 👈"$'\a' else menu_title=$'\e]0;'"👉 $verb $menu_total of $items_count items 👈"$'\a' fi - printf '\e[H\e[2J%s' "${menu_title}${menu_header}${page_header}${page_visible}${items_bundled}${page_footer}${menu_hint_render}" >"$tty_target" + # \e[${terminal_columns}G -- movie cursor to end so it doesn't look like a key + printf '%s' "${style__erase_screen}${style__hide_cursor}${menu_title}${menu_header}${bar_top_content}${bar_middle_content}${items_bundled}${bar_bottom_content}${menu_legend_content}" >"$tty_target" } function render_result { local render="$question_title" index @@ -1511,11 +1473,11 @@ function choose_() ( # add results only if lingering, as there may be more than terminal height, so clearing wouldn't support such for index in "${selected_indexes[@]}"; do if test "${selected[index]}" = 'yes'; then - render+="$color_dim$icon_selected ${items[index]}${color_reset}"$'\n' + render+="${style__result_line}${style__icon_ident}${items[index]}${style__end__result_line}"$'\n' fi done if test "$selected_count" -eq 0; then - render+="${color_dim}[ nothing provided ]"$'\n' + render+="${style__result_line}[ nothing selected ]${style__end__result_line}"$'\n' fi # inform __print_string "$render" >"$tty_target" @@ -1546,6 +1508,11 @@ function choose_() ( function handle_menu { local input read_status # action + function show_cursor { + __print_string "$style__show_cursor" >"$tty_target" + trap - EXIT + } + trap show_cursor EXIT tty_start while true; do # (re-)render the menu? @@ -1664,6 +1631,7 @@ function choose_() ( menu_skip_render='no' fi done + show_cursor tty_finish } diff --git a/commands/config-helper b/commands/config-helper index c3526b96b..0285b251e 100755 --- a/commands/config-helper +++ b/commands/config-helper @@ -4,7 +4,7 @@ function config_helper_test() ( source "$DOROTHY/sources/bash.bash" # prepare - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" __print_line fs-rm --quiet --no-confirm -- "$(fs-temp --directory='config-helper')" local test_file missing_file expected_stderr @@ -116,7 +116,7 @@ function config_helper_test() ( -- cat "$test_file" # done - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" ) function config_helper() ( source "$DOROTHY/sources/bash.bash" diff --git a/commands/confirm b/commands/confirm index f5829c9dc..33c64e2be 100755 --- a/commands/confirm +++ b/commands/confirm @@ -7,7 +7,7 @@ function confirm_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # --ignore-stderr otherwise only \n^[[68;1R is output @@ -57,7 +57,7 @@ function confirm_test() ( } | eval-tester --name='cancel response was entered' --status=125 --ignore-stderr \ -- confirm --ppid=-1 --bool --timeout=5 -- 'What is your response?' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function confirm_() ( diff --git a/commands/dorothy b/commands/dorothy index e1f64198e..57f4b0ca4 100755 --- a/commands/dorothy +++ b/commands/dorothy @@ -498,7 +498,7 @@ function dorothy_() ( function ensure_minimal_dependencies { # dorothy has been installed - echo-segment --h2='Ensure required dependencies' + echo-style --h2='Ensure required dependencies' # macos tooling if __is_mac; then @@ -529,18 +529,18 @@ function dorothy_() ( fi # log - echo-segment --g2='Ensure required dependencies' + echo-style --g2='Ensure required dependencies' } function ensure_development_dependencies { - echo-segment --h2='Ensure development dependencies' + echo-style --h2='Ensure development dependencies' setup-util-bash --quiet "$@" setup-util-ripgrep --quiet "$@" setup-util-prettier --quiet "$@" setup-util-shellcheck --quiet "$@" setup-util-shfmt --quiet "$@" setup-util-trunk --quiet "$@" - echo-segment --g2='Ensure development dependencies' + echo-style --g2='Ensure development dependencies' } function assert_dorothy_configured { @@ -855,13 +855,13 @@ function dorothy_() ( fi } function __update_modern_dorothy { - if __command_exists echo-segment git-helper; then - echo-segment --h2="Updating the Dorothy installation at $DOROTHY" || return + if __command_exists echo-style git-helper; then + echo-style --h2="Updating the Dorothy installation at $DOROTHY" || return # update origin first git-helper update --path="$DOROTHY" || return # update upstream second git-helper update --path="$DOROTHY" -- --remote-name="$dorothy_upstream_remote_name" --remote-url="$dorothy_upstream_git_https" || return - echo-segment --g2="Updating the Dorothy installation at $DOROTHY" || return + echo-style --g2="Updating the Dorothy installation at $DOROTHY" || return else return 1 fi @@ -1122,11 +1122,11 @@ function dorothy_() ( fi } function update_user { - echo-segment --h2="Updating the Dorothy user configuration at $DOROTHY/user" + echo-style --h2="Updating the Dorothy user configuration at $DOROTHY/user" if ! git-helper update --path="$DOROTHY/user"; then __print_line '...Dorothy user configuration was unable to be updated, you will have to figure this out later...' fi - echo-segment --g2="Updating the Dorothy user configuration at $DOROTHY/user" + echo-style --g2="Updating the Dorothy user configuration at $DOROTHY/user" } # update or install the user configuration based on its presence @@ -1224,7 +1224,7 @@ function dorothy_() ( esac done - echo-segment --h2='Dorothy Shell Configuration' + echo-style --h2='Dorothy Shell Configuration' # if not uninstalling if test "$option_uninstall" = 'no'; then @@ -1254,7 +1254,7 @@ function dorothy_() ( # bash if is-needle --needle=bash -- "${use_shells[@]}"; then - echo-segment --h3='Configuring Bash' + echo-style --h3='Configuring Bash' setup-util-bash # mac and raspi ubuntu @@ -1265,7 +1265,7 @@ function dorothy_() ( config-helper --file="$HOME/.bashrc" -- \ --find='.+? # Dorothy' --replace="source \"$DOROTHY/init.sh\" # Dorothy" - echo-segment --g3='Configuring Bash' + echo-style --g3='Configuring Bash' else config-helper --file="$HOME/.bash_profile" -- \ --find='.+? # Dorothy' --replace='' @@ -1275,14 +1275,14 @@ function dorothy_() ( # dash if is-needle --needle=dash -- "${use_shells[@]}"; then - echo-segment --h3='Configuring Dash' + echo-style --h3='Configuring Dash' setup-util-dash # configure config-helper --file="$HOME/.profile" -- \ --find='.+? # Dorothy' --replace=". \"$DOROTHY/init.sh\" # Dorothy" - echo-segment --g3='Configuring Dash' + echo-style --g3='Configuring Dash' elif ! is-needle --needle=bash -- "${use_shells[@]}" && ! is-needle --needle=ksh -- "${use_shells[@]}"; then config-helper --file="$HOME/.profile" -- \ --find='.+? # Dorothy' --replace='' @@ -1293,7 +1293,7 @@ function dorothy_() ( # https://elv.sh/ref/command.html#rc-file # https://elv.sh/ref/runtime.html # https://github.com/elves/elvish/issues/1726 - echo-segment --h3='Configuring Elvish' + echo-style --h3='Configuring Elvish' setup-util-elvish mkdir -p "$XDG_CONFIG_HOME/elvish" @@ -1301,7 +1301,7 @@ function dorothy_() ( config-helper --file="$XDG_CONFIG_HOME/elvish/rc.elv" -- \ --find='.+? # Dorothy' --replace="eval (cat '$DOROTHY/init.elv' | slurp) # Dorothy" - echo-segment --h3='Configuring Elvish' + echo-style --h3='Configuring Elvish' else mkdir -p "$XDG_CONFIG_HOME/elvish" config-helper --file="$XDG_CONFIG_HOME/elvish/rc.elv" -- \ @@ -1310,7 +1310,7 @@ function dorothy_() ( # fish if is-needle --needle=fish -- "${use_shells[@]}"; then - echo-segment --h3='Configuring Fish' + echo-style --h3='Configuring Fish' setup-util-fish mkdir -p "$XDG_CONFIG_HOME/fish" @@ -1318,7 +1318,7 @@ function dorothy_() ( config-helper --file="$XDG_CONFIG_HOME/fish/config.fish" -- \ --find='.+? # Dorothy' --replace="source '$DOROTHY/init.fish' # Dorothy" - echo-segment --g3='Configuring Zsh' + echo-style --g3='Configuring Zsh' else mkdir -p "$XDG_CONFIG_HOME/fish" config-helper --file="$XDG_CONFIG_HOME/fish/config.fish" -- \ @@ -1327,14 +1327,14 @@ function dorothy_() ( # ksh if is-needle --needle=ksh -- "${use_shells[@]}"; then - echo-segment --h3='Configuring KSH' + echo-style --h3='Configuring KSH' setup-util-ksh # configure config-helper --file="$HOME/.profile" -- \ --find='.+? # Dorothy' --replace=". '$DOROTHY/init.sh' # Dorothy" - echo-segment --g3='Configuring KSH' + echo-style --g3='Configuring KSH' elif ! is-needle --needle=bash -- "${use_shells[@]}" && ! is-needle --needle=dash -- "${use_shells[@]}"; then config-helper --file="$HOME/.profile" -- \ --find='.+? # Dorothy' --replace='' @@ -1342,14 +1342,14 @@ function dorothy_() ( # nu if is-needle --needle=nu -- "${use_shells[@]}"; then - echo-segment --h3='Configuring Nu' + echo-style --h3='Configuring Nu' setup-util-nu # trunk-ignore(shellcheck/SC2016) config-helper --file="$(nu -c 'echo $nu.loginshell-path')" -- \ --find='.+? # Dorothy' --replace="source '$DOROTHY/init.nu' # Dorothy" - echo-segment --g3='Configuring Nu' + echo-style --g3='Configuring Nu' elif __command_exists nu; then # trunk-ignore(shellcheck/SC2016) config-helper --file="$(nu -c 'echo $nu.loginshell-path')" -- \ @@ -1359,7 +1359,7 @@ function dorothy_() ( # xonsh if is-needle --needle=xonsh -- "${use_shells[@]}"; then # https://xon.sh/xonshrc.html - echo-segment --h3='Configuring Xonsh' + echo-style --h3='Configuring Xonsh' setup-util-xonsh mkdir -p "$XDG_CONFIG_HOME/xonsh/rc.d" @@ -1367,7 +1367,7 @@ function dorothy_() ( config-helper --file="$XDG_CONFIG_HOME/xonsh/rc.xsh" -- \ --find='.+? # Dorothy' --replace="execx(compilex(open('$DOROTHY/init.xsh').read())) # Dorothy" - echo-segment --g3='Configuring Xonsh' + echo-style --g3='Configuring Xonsh' else mkdir -p "$XDG_CONFIG_HOME/xonsh/rc.d" config-helper --file="$XDG_CONFIG_HOME/xonsh/rc.xsh" -- \ @@ -1377,7 +1377,7 @@ function dorothy_() ( # zsh # https://zsh.sourceforge.io/Intro/intro_3.html if is-needle --needle=zsh -- "${use_shells[@]}"; then - echo-segment --h3='Configuring Zsh' + echo-style --h3='Configuring Zsh' setup-util-zsh mkdir -p "$ZDOTDIR" @@ -1391,7 +1391,7 @@ function dorothy_() ( config-helper --file="$HOME/.zshenv" -- \ --find='ZDOTDIR=.+' --replace="ZDOTDIR='$ZDOTDIR'" - echo-segment --g3='Configuring Zsh' + echo-style --g3='Configuring Zsh' else mkdir -p "$ZDOTDIR" config-helper --file="$ZDOTDIR/.zshrc" -- \ @@ -1402,7 +1402,7 @@ function dorothy_() ( --find='ZDOTDIR=.+' --replace="ZDOTDIR='$ZDOTDIR'" fi - echo-segment --g2='Dorothy Shell Configuration' + echo-style --g2='Dorothy Shell Configuration' } # ===================================== @@ -1431,7 +1431,7 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Install Dorothy' + echo-style --h1='Install Dorothy' if test "$option_skip_install" = 'no'; then ensure_minimal_dependencies ensure_machine_configured @@ -1440,7 +1440,7 @@ function dorothy_() ( ensure_shell_configured --clean="$option_clean" # log success - echo-segment --g1='Install Dorothy' + echo-style --g1='Install Dorothy' echo-style --success='Dorothy is now setup.' ' ' --notice='Restart your terminal.' } @@ -1450,12 +1450,12 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Uninstall Dorothy' + echo-style --h1='Uninstall Dorothy' ensure_minimal_dependencies ensure_shell_configured --uninstall # log success and instructions for removal - echo-segment --g1='Uninstall Dorothy' + echo-style --g1='Uninstall Dorothy' echo-style --success='Dorothy is now uninstalled.' ' ' --notice='Restart your terminal.' local paths=() if test -d "$DOROTHY"; then @@ -1475,14 +1475,14 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Update Dorothy' + echo-style --h1='Update Dorothy' ensure_minimal_dependencies ensure_dorothy_configured ensure_user_configured - echo-segment --h2='Correct Dorothy Permissions' + echo-style --h2='Correct Dorothy Permissions' ensure_permissions_configured # needed as new commands wouldn't be executable otherwise - echo-segment --g2='Correct Dorothy Permissions' - echo-segment --g1='Update Dorothy' + echo-style --g2='Correct Dorothy Permissions' + echo-style --g1='Update Dorothy' } # don't use [sh], as [sh] is [dash] on ubuntu, and [dash] doesn't support the [--...] args @@ -1598,10 +1598,10 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Correct Dorothy Permissions' + echo-style --h1='Correct Dorothy Permissions' ensure_minimal_dependencies ensure_permissions_configured - echo-segment --g1='Correct Dorothy Permissions' + echo-style --g1='Correct Dorothy Permissions' } function act_edit { @@ -1609,7 +1609,7 @@ function dorothy_() ( assert_dorothy_and_user_cloned # action - echo-segment --h1='Edit Dorothy' + echo-style --h1='Edit Dorothy' # ensure_minimal_dependencies <-- if they are editing, then we assume they are already setup ensure_permissions_configured if test "$(edit --dry --only-editor)" == 'code'; then @@ -1617,7 +1617,7 @@ function dorothy_() ( else edit -- "$DOROTHY" fi - echo-segment --g1='Edit Dorothy' + echo-style --g1='Edit Dorothy' } function act_review { @@ -1625,12 +1625,12 @@ function dorothy_() ( assert_dorothy_and_user_cloned # action - echo-segment --h1='Review Dorothy' + echo-style --h1='Review Dorothy' ensure_minimal_dependencies ensure_permissions_configured git-helper review "$DOROTHY/user" || : git-helper review "$DOROTHY" || : - echo-segment --g1='Review Dorothy' + echo-style --g1='Review Dorothy' } function act_theme { @@ -1638,7 +1638,7 @@ function dorothy_() ( assert_dorothy_and_user_cloned # action - echo-segment --h1='Select Dorothy Theme' + echo-style --h1='Select Dorothy Theme' ensure_minimal_dependencies # features @@ -1679,7 +1679,7 @@ function dorothy_() ( # log echo-style --success='Configuration change applied, ' --notice='restart your terminal for the change to take effect.' - echo-segment --g1='Select Dorothy Theme' + echo-style --g1='Select Dorothy Theme' } function act_dev { @@ -1687,7 +1687,7 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Dorothy Development' + echo-style --h1='Dorothy Development' if is-ci; then ensure_development_dependencies --no-quiet else @@ -1705,7 +1705,7 @@ function dorothy_() ( eval-helper --no-quiet -- trunk --version || : # log - echo-segment --g1='Dorothy Development' + echo-style --g1='Dorothy Development' } function act_format { @@ -1713,7 +1713,7 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Dorothy Format' + echo-style --h1='Dorothy Format' ensure_development_dependencies # adjust for ci @@ -1723,26 +1723,26 @@ function dorothy_() ( fi # on dorothy - echo-segment --h3="$DOROTHY" + echo-style --h3="$DOROTHY" ( cd "$DOROTHY" # format trunk fmt --all "${args[@]}" ) - echo-segment --g3="$DOROTHY" + echo-style --g3="$DOROTHY" # on user configuration if test -d "$DOROTHY/user/.trunk"; then - echo-segment --h3="$DOROTHY/user" + echo-style --h3="$DOROTHY/user" ( cd "$DOROTHY/user" # format trunk fmt --all "${args[@]}" ) - echo-segment --g3="$DOROTHY/user" + echo-style --g3="$DOROTHY/user" fi - echo-segment --g1='Dorothy Format' + echo-style --g1='Dorothy Format' } function act_check { @@ -1750,7 +1750,7 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Dorothy Checks' + echo-style --h1='Dorothy Checks' ensure_development_dependencies # adjust for ci @@ -1760,26 +1760,26 @@ function dorothy_() ( fi # on dorothy - echo-segment --h3="$DOROTHY" + echo-style --h3="$DOROTHY" ( cd "$DOROTHY" # check trunk check --all "${args[@]}" ) - echo-segment --g3="$DOROTHY" + echo-style --g3="$DOROTHY" # on user configuration if test -d "$DOROTHY/user/.trunk"; then - echo-segment --h3="$DOROTHY/user" + echo-style --h3="$DOROTHY/user" ( cd "$DOROTHY/user" # check trunk check --all "${args[@]}" ) - echo-segment --g3="$DOROTHY/user" + echo-style --g3="$DOROTHY/user" fi - echo-segment --g1='Dorothy Checks' + echo-style --g1='Dorothy Checks' } function act_lint { @@ -1787,7 +1787,7 @@ function dorothy_() ( assert_dorothy_configured # action - echo-segment --h1='Dorothy Lint' + echo-style --h1='Dorothy Lint' ensure_development_dependencies # adjust for ci @@ -1803,7 +1803,7 @@ function dorothy_() ( fi # on dorothy - echo-segment --h3="$DOROTHY" + echo-style --h3="$DOROTHY" ( cd "$DOROTHY" # upgrade @@ -1826,11 +1826,11 @@ function dorothy_() ( npx prettier --write README.md fi ) - echo-segment --g3="$DOROTHY" + echo-style --g3="$DOROTHY" # on user configuration if test -d "$DOROTHY/user/.trunk"; then - echo-segment --h3="$DOROTHY/user" + echo-style --h3="$DOROTHY/user" ( cd "$DOROTHY/user" # upgrade @@ -1845,10 +1845,10 @@ function dorothy_() ( trunk fmt --all "${args[@]}" trunk check --all "${args[@]}" ) - echo-segment --g3="$DOROTHY/user" + echo-style --g3="$DOROTHY/user" fi - echo-segment --g1='Dorothy Lint' + echo-style --g1='Dorothy Lint' } function act_test { @@ -1857,7 +1857,7 @@ function dorothy_() ( # ^ no need for user config for tests # action - echo-segment --h1='Dorothy Tests' + echo-style --h1='Dorothy Tests' source "$DOROTHY/sources/ripgrep.bash" # able to test on bash v3? @@ -1892,11 +1892,11 @@ function dorothy_() ( if test "${#commands[@]}" -ne 0; then echo-style --error='The following commands have unsafe function calls:' for filepath in "${commands[@]}"; do - echo-element --open="$filepath" + echo-style --element="$filepath" rg --regexp="$unsafe_regexp" "$filepath" - echo-element --close="$filepath" + echo-style --/element="$filepath" done - echo-segment --e1='Dorothy Tests' + echo-style --e1='Dorothy Tests' return 1 fi @@ -1939,12 +1939,12 @@ function dorothy_() ( if test "${#failures[@]}" -ne 0; then echo-style --error='The following tests were failures:' __print_lines "${failures[@]}" - echo-segment --e1='Dorothy Tests' + echo-style --e1='Dorothy Tests' return 1 fi # log - echo-segment --g1='Dorothy Tests' + echo-style --g1='Dorothy Tests' } function act_todos { @@ -1953,7 +1953,7 @@ function dorothy_() ( # ^ no need for user config for todos # action - echo-segment --h1='Dorothy Todos' + echo-style --h1='Dorothy Todos' source "$DOROTHY/sources/ripgrep.bash" # verbose about command conventions and support @@ -2015,11 +2015,11 @@ function dorothy_() ( if test "${#file_bad[@]}" -ne 0; then file_status=1 fi - echo-element --openclose="$filename" --status="$file_status" "${file_good[@]}" "${file_bad[@]}" + echo-style --element/="$filename" --status="$file_status" "${file_good[@]}" "${file_bad[@]}" done # log - echo-segment --g1='Dorothy Todos' + echo-style --g1='Dorothy Todos' } # ===================================== diff --git a/commands/dorothy-config b/commands/dorothy-config index 6a02c120e..01a963688 100755 --- a/commands/dorothy-config +++ b/commands/dorothy-config @@ -4,7 +4,7 @@ function dorothy_config_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # remove fs-rm --quiet --no-confirm -- "$DOROTHY/user/config/dorothy-config-testing.bash" @@ -39,7 +39,7 @@ function dorothy_config_test() ( eval-tester --name='custom config was removed' --stdout="$expected_stdout" --stderr="$expected_stderr" \ -- eval-no-color -- dorothy-config 'setup.bash' --prefer=public -- --field='DOROTHY_CONFIG_TESTING' --replace= - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function dorothy_config() ( diff --git a/commands/echo-count-lines b/commands/echo-count-lines index 54dbf3702..a7e37b0ac 100755 --- a/commands/echo-count-lines +++ b/commands/echo-count-lines @@ -2,7 +2,7 @@ function echo_count_lines_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='args, one blank line' --stdout='0' \ -- echo-count-lines -- '' @@ -91,7 +91,7 @@ function echo_count_lines_test() ( } | eval-tester --name='stdin, one complete line, one incomplete line' --stdout='1' \ -- echo-count-lines --stdin --no-inline - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_count_lines() ( diff --git a/commands/echo-element b/commands/echo-element index 734193cf0..15184b2b3 100755 --- a/commands/echo-element +++ b/commands/echo-element @@ -9,7 +9,7 @@ function echo_element() ( function help { cat <<-EOF >/dev/stderr ABOUT: - Forward to [echo-style], with expansions for --open, --close, --openclose, and --status. + [echo-style] now natively supports elements, change [--open=] to [--element=], [--close=] to [--/element=], and [--openclose=] to [--element/=], and [--status=] remains the same. USAGE: echo-element [--] ... @@ -25,23 +25,20 @@ function echo_element() ( case "$item" in '--help' | '-h') help ;; '--open='*) - option_args+=('--element_open' "--bold=${item#*=}" '--element_close') + item="${item#*=}" + option_args+=("--element=$item") ;; '--close='*) - option_args+=('--element_slash_open' "--bold=${item#*=}" '--element_close') + item="${item#*=}" + option_args+=("--/element=$item") ;; '--openclose='*) - option_args+=('--element_open' "--bold=${item#*=}" '--element_slash_close') + item="${item#*=}" + option_args+=("--element/=$item") ;; '--status='*) item="${item#*=}" - if test "$item" -eq 0; then - # success - option_args+=("--g3=[$item]") - else - # failure - option_args+=("--e3=[$item]") - fi + option_args+=("--status=$item") ;; *) option_args+=("$item") ;; esac diff --git a/commands/echo-escape-newlines b/commands/echo-escape-newlines index 2320c2c0e..d3e638d45 100755 --- a/commands/echo-escape-newlines +++ b/commands/echo-escape-newlines @@ -2,7 +2,7 @@ function echo_escape_newlines_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='using arguments' --stdout='a\nb' \ -- echo-escape-newlines -- $'a\nb' @@ -12,7 +12,7 @@ function echo_escape_newlines_test() ( } | eval-tester --name='using stdin' --stdout='a\nb' \ -- echo-escape-newlines --stdin - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_escape_newlines() ( diff --git a/commands/echo-file b/commands/echo-file index c3f8c90a4..52407cd39 100755 --- a/commands/echo-file +++ b/commands/echo-file @@ -122,10 +122,10 @@ function echo_file() ( function echo_file_bat { local file="$1" if test "$option_plain" = 'yes'; then - echo-element --open="$file" + echo-style --element="$file" "${bat_cmd[@]}" "$file" echo - echo-element --close="$file" + echo-style --/element="$file" else "${bat_cmd[@]}" "$file" fi @@ -140,14 +140,14 @@ function echo_file() ( eval_capture --statusvar=bat_status -- echo_file_bat "$file" fi if test "$bat_status" -ne 0; then - echo-element --open="$file" + echo-style --element="$file" echo-style --code="$(echo-trim-padding --stdin <"$file")" - echo-element --close="$file" + echo-style --/element="$file" fi else - echo-element --open="$file" >/dev/stderr + echo-style --element="$file" >/dev/stderr echo-style --error="The file does not exist." >/dev/stderr - echo-element --close="$file" --status=2 >/dev/stderr + echo-style --/element="$file" --status=2 >/dev/stderr result=2 # ENOENT No such file or directory # ^ dont like this, so that all files are noted before crash fi diff --git a/commands/echo-join b/commands/echo-join index 3f05cf211..e4999e63a 100755 --- a/commands/echo-join +++ b/commands/echo-join @@ -2,7 +2,7 @@ function echo_join_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --stdout='a b' -- echo-join -- a b @@ -16,7 +16,7 @@ function echo_join_test() ( __print_lines a b | eval-tester --stdout=$'a\n\tb' -- echo-join --join=$'\n\t' --stdin - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_join() ( diff --git a/commands/echo-lines b/commands/echo-lines index e2ad8bc17..1e8400a3d 100755 --- a/commands/echo-lines +++ b/commands/echo-lines @@ -2,7 +2,7 @@ function echo_lines_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='args' --stdout=$'a\nb' \ -- echo-lines -- a b @@ -152,7 +152,7 @@ function echo_lines_test() ( eval-tester --name='double tab indent' --stdout=$'\t\t\'double "quote" inside\' "single \'quote\' inside" \'3\'\n\t\t\'4\' \'5\' \'6\'' \ -- echo-lines --columns=3 --filler=space --width=inputs --quoted --indent=$'\t\t' -- 'double "quote" inside' "single 'quote' inside" 3 4 5 6 - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_lines() ( diff --git a/commands/echo-lines-after b/commands/echo-lines-after index 177f102d5..92afac405 100755 --- a/commands/echo-lines-after +++ b/commands/echo-lines-after @@ -2,7 +2,7 @@ function echo_lines_after_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='using arguments' --stdout=$'c\n\nb' \ -- echo-lines-after '' --needle='b' -- $'a\nb\n\nb\n\nc\n\nb' @@ -25,7 +25,7 @@ function echo_lines_after_test() ( eval-tester --name='using <<<' --stdout=$'c\n\nb' \ -- echo-lines-after '' --needle='b' - <<<"$(__print_lines a b '' b '' c '' b)" - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_lines_after() ( diff --git a/commands/echo-lines-before b/commands/echo-lines-before index 77da8faa4..d32c65636 100755 --- a/commands/echo-lines-before +++ b/commands/echo-lines-before @@ -5,7 +5,7 @@ function echo_lines_before_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='using arguments' --stdout=$'a\nb' \ -- echo-lines-before --needle='' -- $'a\nb\n\nc\nd' @@ -28,7 +28,7 @@ function echo_lines_before_test() ( eval-tester --name='using <<<' --stdout=$'a\nb' \ -- echo-lines-before --needle='' - <<<"$(__print_lines a b '' c d)" - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_lines_before() ( diff --git a/commands/echo-math b/commands/echo-math index a64654ad7..8f4595190 100755 --- a/commands/echo-math +++ b/commands/echo-math @@ -2,7 +2,7 @@ function echo_math_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" local inputs=('1 - 1/2' '1 - 1/3' '1 - 1/4') local expected=$'0.50\n0.67\n0.75' @@ -27,7 +27,7 @@ function echo_math_test() ( -- echo-math --precision=2 --tool=awk --stdin fi - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_math() ( diff --git a/commands/echo-segment b/commands/echo-segment index f4db75a5d..6d38294e4 100755 --- a/commands/echo-segment +++ b/commands/echo-segment @@ -9,7 +9,7 @@ function echo_segment() ( function help { cat <<-EOF >/dev/stderr ABOUT: - Forward to [echo-style], adding open and close segments. + [echo-style] now supports _open and _close segments natively, as such there is no need for [echo-segment] anymore USAGE: echo-segment [--] ... @@ -17,38 +17,10 @@ function echo_segment() ( return 22 # EINVAL 22 Invalid argument } - # process - local item option_args=() field name value - while test "$#" -ne 0; do - item="$1" - shift - case "$item" in - '--help' | '-h') help ;; - *) - field="${item:2}" - name="${field%%=*}" - if test "$name" = "$field"; then - option_args+=("$item") - continue - fi - value="${field#*=}" - if test "$name" = 'h1'; then - # add a preceeding newline - option_args+=($'\n') - fi - option_args+=( - "--${name}_open" - "--${name}=${value}" - "--${name}_close" - ) - ;; - esac - done - # ===================================== # Action - echo-style "${option_args[@]}" + echo-style "$@" ) # fire if invoked standalone diff --git a/commands/echo-style b/commands/echo-style index 9af81a0d0..72622aabc 100755 --- a/commands/echo-style +++ b/commands/echo-style @@ -79,32 +79,38 @@ function echo_style() ( } # process - local item trail='yes' items=() use_colors - use_colors="$(echo-color-enabled --fallback=yes --)" # parse env only, as [--color=] and [--nocolor=] are used by us + local item items=() option_trail='yes' option_debug='no' option_color + option_color="$(echo-color-enabled --fallback=yes --)" # parse env only, as [--color=] and [--nocolor=] are used by us while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; + '--no-debug'* | '--debug'*) + option_debug="$(get-flag-value --affirmative --fallback="$option_debug" -- "$item")" + ;; '--no-trail'* | '--trail'*) - trail="$(get-flag-value --affirmative --fallback="$trail" -- "$item")" + option_trail="$(get-flag-value --affirmative --fallback="$option_trail" -- "$item")" ;; '--color' | '--colors' | '--colors=yes') - use_colors='yes' + option_color='yes' ;; '--no-color' | '--no-colors' | '--colors=no') - use_colors='no' + option_color='no' + ;; + --) + items+=("$@") + shift $# + ;; + *) + items+=("$item" "$@") + shift $# ;; - *) items+=("$item") ;; esac done - # check if no color - local color_target tty_target - color_target='/dev/stdout' - if test "$use_colors" = 'no'; then - color_target='/dev/null' - fi + # prepare + local tty_target tty_target="$(is-tty --fallback)" # ===================================== @@ -119,140 +125,216 @@ function echo_style() ( # ===================================== # Action - # shared vars - local DISABLE='' - - # helper - function colorize { - local style="$1" disable_style - - # convert hyphens to underscores - style="${style//-/_}" - - # expand shortcuts - case "$style" in - 'bg_hi_'*) style="background_intense_${style:6}" ;; - *'_hi_bg') style=style="background_intense_${style:0:-6}" ;; - - 'fg_hi_'*) style="foreground_intense_${style:6}" ;; - *'_hi_fg') style=style="foreground_intense_${style:0:-6}" ;; - - 'fg_'*) style="foreground_${style:3}" ;; - *'_fg') style="foreground_${style:0:-3}" ;; - - 'bg_'*) style="background_${style:3}" ;; - *'_bg') style="background_${style:0:-3}" ;; - - 'hi_'*) style="intense_${style:3}" ;; - *'_hi') style="intense_${style:0:-3}" ;; - esac + # act + local item flag style generic \ + i current_char_index last_char_index \ + item_target buffer_target='/dev/stdout' \ + MISSING_STYLES=() \ + ITEM_COLOR buffer_color="$option_color" \ + ITEM_BEGIN \ + item_content \ + ITEM_END \ + buffer_left='' buffer_disable='' buffer_right='' + function get_style { + local style="$1" var='' found='no' + if test "$ITEM_COLOR" = 'yes'; then + # begin + var="style__color__${style}" + if __is_var_set "$var"; then + ITEM_BEGIN+="${!var}" + found='yes' + else + var="style__${style}" + if __is_var_set "$var"; then + ITEM_BEGIN+="${!var}" + found='yes' + else + var="style__nocolor__${style}" + if __is_var_set "$var"; then + found='yes' + fi + fi + fi - # if it don't exist, it may be a foreground shorthand - if ! __is_var_set "$style" && __is_var_set "foreground_$style"; then - style="foreground_$style" - fi + # end + var="style__color_end__${style}" + if __is_var_set "$var"; then + ITEM_END="${!var}${ITEM_END}" + found='yes' + else + var="style__end__${style}" + if __is_var_set "$var"; then + ITEM_END="${!var}${ITEM_END}" + found='yes' + else + var="style__nocolor_end__${style}" + if __is_var_set "$var"; then + found='yes' + fi + fi + fi + else + # begin + var="style__nocolor__${style}" + if __is_var_set "$var"; then + ITEM_BEGIN+="${!var}" + found='yes' + else + var="style__${style}" + if __is_var_set "$var"; then + ITEM_BEGIN+="${!var}" + found='yes' + else + var="style__color__${style}" + if __is_var_set "$var"; then + found='yes' + fi + fi + fi - # return the color value - if __is_var_set "$style"; then - __print_string "${!style}" - - # determine the disable style - # don't convert to case/esac, too complicated - # check earlier echo did not already output the disable - if [[ $style != 'disable_'* ]]; then - if [[ $style == 'foreground_'* ]]; then - DISABLE+="$disable_foreground" - elif [[ $style == 'background_'* ]]; then - DISABLE+="$disable_background" + # end + var="style__nocolor_end__${style}" + if __is_var_set "$var"; then + ITEM_END="${!var}${ITEM_END}" + found='yes' + else + var="style__${style}" + if __is_var_set "$var"; then + ITEM_END="${!var}${ITEM_END}" + found='yes' else - # custom disable, check if it exits - disable_style="disable_$style" - if __is_var_set "$disable_style"; then - # if it does, use it - DISABLE+="${!disable_style}" - else - # otherwise use a generic reset - DISABLE+="$reset" + var="style__color_end__${style}" + if __is_var_set "$var"; then + found='yes' fi fi fi + fi - elif [[ $style != *'_open' ]] && [[ $style != *'_close' ]]; then - # ^ ignore errors on *_open and *_close, as they are optional - __print_line "Style [$style] is missing." >/dev/stderr - return 22 # EINVAL 22 Invalid argument + if test "$found" = 'no'; then + MISSING_STYLES+=("${style}") fi } - - # act - local item flag value value_target='' last_i colorize_status for item in "${items[@]}"; do - flag='' - value='' - # check flag status if test "${item:0:2}" != '--'; then - # not a flag - __print_string "$item" + # not a flag, just item content + buffer_left+="$item" continue fi flag="${item:2}" + item_content='' + generic='yes' # get the flag and value combo for ((i = 0; i < ${#flag}; i++)); do if test "${flag:i:1}" = '='; then - value="${flag:i+1}" + generic='no' + item_content="${flag:i+1}" flag="${flag:0:i}" break fi done # handle style+style combinations - value_target='/dev/stdout' - last_i=0 - DISABLE='' - for ((i = 0; i <= ${#flag}; i++)); do - if test "${flag:i:1}" = '+' -o "$i" -eq "${#flag}"; then - style="${flag:last_i:i-last_i}" - last_i="$((i + 1))" - if test "$style" = 'stdout'; then - value_target='/dev/stdout' - color_target='/dev/stdout' - elif test "$style" = 'stderr'; then - value_target='/dev/stderr' - color_target='/dev/stderr' - elif test "$style" = 'tty'; then - value_target="$tty_target" - color_target="$tty_target" - elif test "$style" = 'color'; then - value_target="$color_target" - elif test "$style" = 'nocolor'; then - if test "$color_target" != '/dev/null'; then - value_target='/dev/null' - fi - else - styles+=("$style") - eval_capture --statusvar=colorize_status -- \ - colorize "$style" >"$color_target" - if test "$colorize_status" -ne 0; then - __print_line "[$0 $*] FAILED" >/dev/stderr - return "$colorize_status" + last_char_index=0 + item_target="$buffer_target" + ITEM_COLOR="$buffer_color" + ITEM_STYLE='' + ITEM_BEGIN='' + ITEM_END='' + for ((current_char_index = 0; current_char_index <= ${#flag}; current_char_index++)); do + if test "${flag:current_char_index:1}" = '+' -o "$current_char_index" -eq "${#flag}"; then + style="${flag:last_char_index:current_char_index-last_char_index}" + last_char_index="$((current_char_index + 1))" + style="${style//-/_}" # convert hyphens to underscores + + # handle special cases + case "$style" in + black | red | green | yellow | blue | magenta | cyan | white | purple | gray | grey) style="foreground_$style" ;; + 'intense_'*) style="foreground_intense_${style:8}" ;; + /*) style="slash_${style:1}" ;; + */) style="${style:0:-1}_slash" ;; + status) + if test "$item_content" -eq 0; then + style='good3' + else + style='error3' fi - fi + item_content="[${item_content}]" + ;; + color) + ITEM_COLOR='yes' + continue + ;; + nocolor) + ITEM_COLOR='no' + continue + ;; + stdout) + item_target='/dev/stdout' + continue + ;; + stderr) + item_target='/dev/stderr' + continue + ;; + tty) + item_target="$tty_target" + continue + ;; + null) + item_target='/dev/null' + continue + ;; + esac + + # get the style + get_style "$style" fi done - # value - if test -n "$value"; then - __print_string "$value" >"$value_target" - __print_string "$DISABLE" >"$color_target" + # handle nocolor and color correctly, as in conditional output based on NO_COLOR=true + # e.g. env COLOR=false echo-style --color=yes --nocolor=no # outputs no + # e.g. env COLOR=true echo-style --color=yes --nocolor=no # outputs yes + if test "$option_color" != "$ITEM_COLOR"; then + continue + fi + + # if it is generic, add the styles (except disable) to the buffer instead + if test "$generic" = 'yes'; then + # flush buffer if necessary + if test "$item_target" != "$buffer_target"; then + __print_string "${buffer_left}" >"$buffer_target" + buffer_left='' + buffer_target="$item_target" + fi + # update buffer + buffer_left+="${ITEM_BEGIN}${ITEM_STYLE}" + # if [[ $buffer_disable != *"$ITEM_DISABLE"* ]]; then + # buffer_disable="${ITEM_DISABLE}${buffer_disable}" + # fi + buffer_right="${ITEM_END}${buffer_right}" + else + # flush buffer if necessary + if test "$item_target" != "$buffer_target"; then + __print_string "${buffer_left}" >"$buffer_target" + buffer_left='' + __print_string "${ITEM_BEGIN}${item_content}${ITEM_END}" >"$item_target" + else + buffer_left+="${ITEM_BEGIN}${item_content}${ITEM_END}" + fi fi done - # finish up - # __print_string "$reset" >"$color_target" - if test "$trail" = 'yes' -a -n "$value_target"; then # -n check for zero arguments - echo >"$value_target" # trailing newline, should of course go to the trailing target + # close the buffer + if test "$option_trail" = 'yes'; then + buffer_right+=$'\n' + fi + __print_string "${buffer_left}${buffer_disable}${buffer_right}" >"$buffer_target" + if test "$option_debug" = 'yes' -a "${#MISSING_STYLES[@]}" -ne 0; then + __print_lines 'ERROR: MISSING STYLES:' "${MISSING_STYLES[@]}" >/dev/stderr + return 22 # EINVAL 22 Invalid argument fi ) diff --git a/commands/echo-trim-colors b/commands/echo-trim-colors index ea0d0e05b..76801cc31 100755 --- a/commands/echo-trim-colors +++ b/commands/echo-trim-colors @@ -3,7 +3,7 @@ function echo_trim_colors_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" { echo-style --green='i am green' | echo-trim-colors --stdin | echo-escape-newlines --stdin @@ -15,7 +15,7 @@ function echo_trim_colors_test() ( } | eval-tester --name='stdin' --stdout='i am green' \ -- cat - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_trim_colors() ( diff --git a/commands/echo-trim-each-line b/commands/echo-trim-each-line index f4ddb21d2..cd6a828c6 100755 --- a/commands/echo-trim-each-line +++ b/commands/echo-trim-each-line @@ -2,7 +2,7 @@ function echo_trim_each_line_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" local inputs=(' a ' $'\t a \t\n b ' $'\t a \t' ' b ') local expected=$'a\na\nb\na\nb' @@ -15,7 +15,7 @@ function echo_trim_each_line_test() ( } | eval-tester --name='trimming arguments' --stdout="$expected" \ -- echo-trim-each-line --stdin - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_trim_each_line() ( diff --git a/commands/echo-trim-zero-length b/commands/echo-trim-zero-length index 02b7277fb..537eeec1d 100755 --- a/commands/echo-trim-zero-length +++ b/commands/echo-trim-zero-length @@ -2,7 +2,7 @@ function echo_trim_zero_length_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" local inputs=('a' '' 'b' ' ' 'c' 'null' 'd' 'false') local expected=$'a\nb\n \nc\nnull\nd\nfalse' @@ -15,7 +15,7 @@ function echo_trim_zero_length_test() ( } | eval-tester --name='trimming arguments' --stdout="$expected" \ -- echo-trim-zero-length --stdin - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_trim_zero_length() ( diff --git a/commands/echo-wait b/commands/echo-wait index 13f3d80b8..58712f0bc 100755 --- a/commands/echo-wait +++ b/commands/echo-wait @@ -3,7 +3,7 @@ function echo_wait_test() ( source "$DOROTHY/sources/bash.bash" source "$(type -P eval-tester)" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # optional dependencies setup-util-moreutils --quiet --optional --no-fallback # sponge @@ -82,7 +82,7 @@ function echo_wait_test() ( -- sudo-helper -- cat "$file" fi - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function echo_wait() ( diff --git a/commands/eval-helper b/commands/eval-helper index 288d5de3c..19e761f69 100755 --- a/commands/eval-helper +++ b/commands/eval-helper @@ -102,7 +102,7 @@ function eval_helper() ( option_title="$(echo-escape-command -- "${option_cmd[@]}")" fi if test "$option_wrap" = 'yes'; then - element_open="$(echo-element --open="$option_title")" + element_open="$(echo-style --element="$option_title")" else element_open="$(echo-style --code="$option_title")" fi @@ -130,7 +130,7 @@ function eval_helper() ( # footers if test "$option_wrap" = 'yes'; then - echo-element --close="$option_title" --status="$cmd_status" >"$tty_target" + echo-style --/element="$option_title" --status="$cmd_status" >"$tty_target" fi if test "$cmd_status" -eq 0; then if test -n "$option_success"; then @@ -199,7 +199,7 @@ function eval_helper() ( # if it didn't output anything, output self closing wrap, then footer, then exit if test -z "$(cat "$body")"; then - echo-element --openclose="$option_title" --status="$cmd_status" >"$tty_target" + echo-style --element/="$option_title" --status="$cmd_status" >"$tty_target" if test -n "$footer"; then __print_string "$footer" >"$tty_target" fi @@ -217,7 +217,7 @@ function eval_helper() ( fi # outpout wrap footer if test "$option_wrap" = 'yes'; then - echo-element --close="$option_title" --status="$cmd_status" >"$tty_target" + echo-style --/element="$option_title" --status="$cmd_status" >"$tty_target" fi # output footer if test -n "$footer"; then diff --git a/commands/eval-tester b/commands/eval-tester index 83dc21553..f6e672ddf 100755 --- a/commands/eval-tester +++ b/commands/eval-tester @@ -109,7 +109,7 @@ function eval_tester() ( else args+=('--no-stderr') fi - echo-segment --h3="$title" + echo-style --h3="$title" eval_capture "${args[@]}" -- "${option_cmd[@]}" # test exit code @@ -127,12 +127,12 @@ function eval_tester() ( if test "$option_stdout" != "$stdout"; then fail='yes' echo-style --red="Actual Stdout != Expected Stdout" $'\n' \ - --h3='' $'\n' \ + --header3='' $'\n' \ "$stdout" $'\n' \ - --h3='' $'\n' \ - --h3='' $'\n' \ + --header3='' $'\n' \ + --header3='' $'\n' \ "$option_stdout" $'\n' \ - --h3='' + --header3='' else echo-style --green="Actual Stdout == Expected Stdout" fi @@ -147,12 +147,12 @@ function eval_tester() ( elif test "$option_stderr" != "$stderr"; then fail='yes' echo-style --red="Actual Stderr != Expected Stderr" $'\n' \ - --h3='' $'\n' \ + --header3='' $'\n' \ "$stderr" $'\n' \ - --h3='' $'\n' \ - --h3='' $'\n' \ + --header3='' $'\n' \ + --header3='' $'\n' \ "$option_stderr" $'\n' \ - --h3='' + --header3='' else echo-style --green="Actual Stderr == Expected Stderr" fi @@ -160,10 +160,10 @@ function eval_tester() ( # pass or fail if test "$fail" = 'yes'; then - echo-segment --e3="$title" $'\n' + echo-style --e3="$title" $'\n' return 1 else - echo-segment --g3="$title" $'\n' + echo-style --g3="$title" $'\n' fi ) diff --git a/commands/expand-path b/commands/expand-path index c2197d32e..2d26f3744 100755 --- a/commands/expand-path +++ b/commands/expand-path @@ -8,7 +8,7 @@ function expand_path_test() ( source "$DOROTHY/sources/bash.bash" source "$(type -P eval-tester)" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval_tester --name='test non-existent path' --stdout='' \ -- expand-path -- '/i/do/not exist*' @@ -16,7 +16,7 @@ function expand_path_test() ( eval_tester --name='test existent path' --stdout="$DOROTHY/commands/expand-path" \ -- expand-path -- "$DOROTHY/*/expand-path" - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function expand_path() ( diff --git a/commands/flush-dns b/commands/flush-dns index 0a4ec106e..38c53d0f9 100755 --- a/commands/flush-dns +++ b/commands/flush-dns @@ -35,7 +35,7 @@ function flush_dns() ( # ===================================== # Acction - echo-segment --h1="Flush DNS" + echo-style --h1="Flush DNS" # https://support.apple.com/en-us/HT202516 if is-mac; then @@ -75,7 +75,7 @@ function flush_dns() ( return 19 # ENODEV 19 Operation not supported by device fi - echo-segment --g1="Flush DNS" + echo-style --g1="Flush DNS" ) # fire if invoked standalone diff --git a/commands/fs-own b/commands/fs-own index 93a0c1a5b..2f43efb31 100755 --- a/commands/fs-own +++ b/commands/fs-own @@ -2,7 +2,7 @@ function fs_own_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" local dir file dir="$(fs-temp --directory)" @@ -32,7 +32,7 @@ function fs_own_test() ( eval-tester --name='can own a durectory -quiet +admin' --ignore-stdout --ignore-stderr \ -- fs-own --no-quiet --admin -- "$dir" - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function fs_own() ( diff --git a/commands/fs-rm b/commands/fs-rm index 9a6a618f8..81a6a0285 100755 --- a/commands/fs-rm +++ b/commands/fs-rm @@ -235,12 +235,12 @@ function fs_rm() ( title+=" --group=$option_group" fi title+=" $path" - echo-segment --h2="$title" + echo-style --h2="$title" eval_capture --statusvar=rm_status -- do_rm "$path" if test "$rm_status" -eq 0; then - echo-segment --g2="$title" " $CONCLUSION" + echo-style --g2="$title" " $CONCLUSION" else - echo-segment --e2="$title" " $CONCLUSION" + echo-style --e2="$title" " $CONCLUSION" return "$rm_status" fi fi diff --git a/commands/fs-size b/commands/fs-size index db81b72bc..5a1efe7fd 100755 --- a/commands/fs-size +++ b/commands/fs-size @@ -96,12 +96,12 @@ function fs_size() ( return else title="fs-size $(echo-quote -- "$path")" - echo-segment --h2="$title" + echo-style --h2="$title" eval_capture --statusvar=size_status -- do_size "$path" if test "$size_status" -eq 0; then - echo-segment --g2="$title" " $CONCLUSION" + echo-style --g2="$title" " $CONCLUSION" else - echo-segment --e2="$title" " $CONCLUSION" + echo-style --e2="$title" " $CONCLUSION" return "$size_status" fi fi diff --git a/commands/fs-speed b/commands/fs-speed index 5ed708211..061b0156b 100755 --- a/commands/fs-speed +++ b/commands/fs-speed @@ -74,7 +74,7 @@ function fs_speed() ( local path for path in "${option_paths[@]}"; do # start - echo-segment --h1="Speed Test: $path" + echo-style --h1="Speed Test: $path" # https://raw.githubusercontent.com/axboe/fio/master/examples/fio-seq-RW.fio cd "$path" @@ -83,7 +83,7 @@ function fs_speed() ( fs-rm --quiet --no-confirm --user="$option_user" --group="$option_group" -- ./fio-seq-RW # done - echo-segment --g1="Speed Test: $path" + echo-style --g1="Speed Test: $path" done ) @@ -107,7 +107,7 @@ fi # local scratchpad log bytes megabytes speed path # for path in "${option_paths[@]}"; do # # start -# echo-segment --h1="Speed Test: $path" +# echo-style --h1="Speed Test: $path" # # is broken: https://github.com/axboe/fio/blob/master/examples/fio-seq-read.fio # # is broken: https://github.com/axboe/fio/blob/master/examples/fio-seq-write.fio @@ -164,5 +164,5 @@ fi # fs-rm --quiet --no-confirm -- "$scratchpad" "$log" # # done -# echo-segment --g1="Speed Test: $path" +# echo-style --g1="Speed Test: $path" # done diff --git a/commands/get-flag-value b/commands/get-flag-value index fefb17893..61fce3f33 100755 --- a/commands/get-flag-value +++ b/commands/get-flag-value @@ -2,7 +2,7 @@ function get_flag_value_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # named, not found @@ -162,7 +162,7 @@ function get_flag_value_test() ( # done - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function get_flag_value() ( diff --git a/commands/get-github-release b/commands/get-github-release index fd8e9c777..6c0c8c75a 100755 --- a/commands/get-github-release +++ b/commands/get-github-release @@ -2,7 +2,7 @@ function get_github_release_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # prepare local expected diff --git a/commands/get-installer b/commands/get-installer index 4c469d151..270f5ffd2 100755 --- a/commands/get-installer +++ b/commands/get-installer @@ -286,7 +286,7 @@ function get_installer() ( # testing if test "$*" = '--test'; then - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # test that the installers for the aliases actually exist local key value='' result=0 @@ -305,9 +305,9 @@ function get_installer() ( # return result if test "$result" -eq 0; then - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" else - echo-segment --e1="TEST: $0" + echo-style --e1="TEST: $0" fi return "$result" fi diff --git a/commands/get-profile b/commands/get-profile index 97b35d234..43563540e 100755 --- a/commands/get-profile +++ b/commands/get-profile @@ -23,7 +23,7 @@ function get_profile() ( function help { cat <<-EOF >/dev/stderr - $(echo-style --h1='SYNOPSIS') + $(echo-style --header1='SYNOPSIS') $( echo-style \ --bold='get-profile' ' ' \ @@ -49,13 +49,13 @@ function get_profile() ( --disable-bold+italic=']]' ) - $(echo-style --h1='DESCRIPTION') + $(echo-style --header1='DESCRIPTION') Attempts to retrieve a profile property from one or more sources. - $(echo-style --h1='CONFIGURATION') + $(echo-style --header1='CONFIGURATION') The $(echo-style --bold='config') source uses the $(echo-style --bold='profile.bash') configuration file. - $(echo-style --h1='OPTIONS') + $(echo-style --header1='OPTIONS') $( echo-style \ --bold='get-profile' ' ' \ @@ -87,7 +87,7 @@ function get_profile() ( if omitted, all sources will be used. if $(echo-style --bold='...') is used, it will be expanded to all sources. - $(echo-style --h1='EXIT STATUS') + $(echo-style --header1='EXIT STATUS') $(echo-style --green='[0] if a value was found.') stdout will output the fetched value. stderr will be empty. @@ -96,7 +96,7 @@ function get_profile() ( stdout will be empty. stderr will output that the result is undefined. - $(echo-style --h1='EXAMPLES') + $(echo-style --header1='EXAMPLES') Attempt to retrieve the name from the first available source, these are equivalent: $(echo-style --bold='get-profile name') diff --git a/commands/gocryptfs-helper b/commands/gocryptfs-helper index 382cbb5e8..8a4118398 100755 --- a/commands/gocryptfs-helper +++ b/commands/gocryptfs-helper @@ -184,12 +184,12 @@ function gocryptfs_helper() ( echo-style --warning="Vaults have different features." result=1 fi - echo-element --open="$old_vault" + echo-style --element="$old_vault" __print_line "$old_vault_features" - echo-element --close="$old_vault" - echo-element --open="$new_vault" + echo-style --/element="$old_vault" + echo-style --element="$new_vault" __print_line "$new_vault_features" - echo-element --close="$new_vault" + echo-style --/element="$new_vault" return "$result" } function act_upgrade { diff --git a/commands/is-bash-version-outdated b/commands/is-bash-version-outdated index b68b8acc0..bd96f4144 100755 --- a/commands/is-bash-version-outdated +++ b/commands/is-bash-version-outdated @@ -8,7 +8,7 @@ function is_bash_version_outdated_test() ( # BASH_VERSION_LATEST # test if the known version is still the latest available version - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # dependencies source "$DOROTHY/sources/ripgrep.bash" @@ -17,16 +17,16 @@ function is_bash_version_outdated_test() ( bash_version_latest_available="$( fetch 'https://ftp.gnu.org/gnu/bash/?C=M;O=D' | rg --max-count=1 --only-matching --regexp='href="bash-([0-9.]+?)[.]tar[.]gz"' --replace='$1' )" - echo-segment --h2='latest known bash version is the latest available bash version' + echo-style --h2='latest known bash version is the latest available bash version' echo-style --bold='current bash version' ' = ' --invert="$BASH_VERSION_CURRENT" echo-style --bold='latest known bash version' ' = ' --invert="$BASH_VERSION_LATEST" echo-style --bold='latest available bash version' ' = ' --invert="$bash_version_latest_available" if test "$BASH_VERSION_LATEST" != "$bash_version_latest_available"; then - echo-segment --e2='latest known bash version is the latest available bash version' + echo-style --e2='latest known bash version is the latest available bash version' return 1 fi - echo-segment --g2='latest known bash version is the latest available bash version' - echo-segment --g1="TEST: $0" + echo-style --g2='latest known bash version is the latest available bash version' + echo-style --g1="TEST: $0" return 0 ) diff --git a/commands/is-digit b/commands/is-digit index f92b129f9..e36ce3fa4 100755 --- a/commands/is-digit +++ b/commands/is-digit @@ -2,7 +2,7 @@ function is_digit_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='0-9 ARE a digits' --status=0 \ -- is-digit -- 0 1 2 3 4 5 6 7 8 9 @@ -28,7 +28,7 @@ function is_digit_test() ( eval-tester --name='1a IS NOT a digit' --status=1 \ -- is-digit -- '1a' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_digit() ( diff --git a/commands/is-empty-string b/commands/is-empty-string index e9816447e..abc283c29 100755 --- a/commands/is-empty-string +++ b/commands/is-empty-string @@ -2,7 +2,7 @@ function is_empty_string_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='zero-length is empty' \ -- is-empty-string -- '' @@ -22,7 +22,7 @@ function is_empty_string_test() ( eval-tester --name='letters not empty' --status=1 \ -- is-empty-string -- 'a' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_empty_string() ( diff --git a/commands/is-generic b/commands/is-generic index c61a3f3ec..8d92fc3c2 100755 --- a/commands/is-generic +++ b/commands/is-generic @@ -2,7 +2,7 @@ function is_generic_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='user.local is generic' --status=0 \ -- is-generic -- 'user.local' @@ -10,7 +10,7 @@ function is_generic_test() ( eval-tester --name='custom.local is not generic' --status=1 \ -- is-generic -- 'custom.local' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_generic() ( diff --git a/commands/is-globstar b/commands/is-globstar index 35c3bf646..00387853b 100755 --- a/commands/is-globstar +++ b/commands/is-globstar @@ -2,7 +2,7 @@ function is_globstar_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='empty' --status=22 --ignore-stderr \ -- is-globstar @@ -19,7 +19,7 @@ function is_globstar_test() ( eval-tester --name='globstar string' --status=0 \ -- is-globstar -- ' /Users/runner/.cache/dorothy/**/unziptar/5241/rg' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_globstar() ( diff --git a/commands/is-integer b/commands/is-integer index 87629a15f..b702b5191 100755 --- a/commands/is-integer +++ b/commands/is-integer @@ -15,7 +15,7 @@ function is_integer_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='zero' --status=0 \ -- is-integer -- 0 @@ -53,7 +53,7 @@ function is_integer_test() ( eval-tester --name='combo' --status=1 \ -- is-integer -- '-0a' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_integer() ( diff --git a/commands/is-internet-working b/commands/is-internet-working index b948b54f1..f55af26d6 100755 --- a/commands/is-internet-working +++ b/commands/is-internet-working @@ -67,7 +67,7 @@ function is_internet_working() ( # header if test "$option_quiet" != 'yes'; then - echo-segment --h1='Verify Internet Connection' + echo-style --h1='Verify Internet Connection' fi # check @@ -96,7 +96,7 @@ function is_internet_working() ( echo-style --green="It appears you are connected to the internet." fi if test "$option_quiet" != 'yes'; then - echo-segment --g1='Verify Internet Connection' + echo-style --g1='Verify Internet Connection' fi return 0 else @@ -107,7 +107,7 @@ function is_internet_working() ( It could be a DNS issue in which [setup-dns] may work. EOF )" - echo-segment --e1='Verify Internet Connection' + echo-style --e1='Verify Internet Connection' fi return 1 fi diff --git a/commands/is-linux b/commands/is-linux index 6b42cba72..a16ed791b 100755 --- a/commands/is-linux +++ b/commands/is-linux @@ -2,7 +2,7 @@ function is_linux_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" local os os="$(uname -s)" @@ -14,7 +14,7 @@ function is_linux_test() ( -- is-linux fi - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_linux() ( diff --git a/commands/is-mac b/commands/is-mac index bb18927fe..60b3d6d00 100755 --- a/commands/is-mac +++ b/commands/is-mac @@ -2,7 +2,7 @@ function is_mac_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" local os os="$(uname -s)" @@ -14,7 +14,7 @@ function is_mac_test() ( -- is-mac fi - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_mac() ( diff --git a/commands/is-match b/commands/is-match index 4837ca4bf..5ac21a5b2 100755 --- a/commands/is-match +++ b/commands/is-match @@ -2,7 +2,7 @@ function is_match_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='match works' --status=0 \ -- is-match 'a +haystack ?' 'a haystack' @@ -13,7 +13,7 @@ function is_match_test() ( eval-tester --name='no match works' --status=1 \ -- is-match -i 'Z|Y' 'abc' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_match() ( diff --git a/commands/is-number b/commands/is-number index 0c954a77c..4ed9d61ba 100755 --- a/commands/is-number +++ b/commands/is-number @@ -2,7 +2,7 @@ function is_number_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" eval-tester --name='zero IS a number' --status=0 \ -- is-number -- 0 @@ -43,7 +43,7 @@ function is_number_test() ( eval-tester --name='combo IS NOT a number' --status=1 \ -- is-number -- '-0a' - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_number() ( diff --git a/commands/is-same b/commands/is-same index af758bf70..d36ad086c 100755 --- a/commands/is-same +++ b/commands/is-same @@ -68,22 +68,22 @@ function is_same() ( # same path if test "$first_path" = "$second_path"; then echo-style \ - --h1="$first_path" $'\n' \ + --header1="$first_path" $'\n' \ $'\n' \ - --h1="$second_path" $'\n' \ + --header1="$second_path" $'\n' \ $'\n' \ - --g1="^ same because they are the same path" + --good1="^ same because they are the same path" return 0 fi # same target if test "$(fs-realpath -- "$first_path")" = "$(fs-realpath -- "$second_path")"; then echo-style \ - --h1="$first_path" $'\n' \ + --header1="$first_path" $'\n' \ $'\n' \ - --h1="$second_path" $'\n' \ + --header1="$second_path" $'\n' \ $'\n' \ - --g1="^ same because they are are symlinked" + --good1="^ same because they are are symlinked" return 0 fi @@ -93,13 +93,13 @@ function is_same() ( second_structure="$(fs-structure -- "$second_path")" if test "$first_structure" != "$second_structure"; then echo-style \ - --h1="$first_path" $'\n' \ + --header1="$first_path" $'\n' \ --dim="$first_structure" $'\n' \ $'\n' \ - --h1="$second_path" $'\n' \ + --header1="$second_path" $'\n' \ --dim="$second_structure" $'\n' \ $'\n' \ - --e1='^ different because their structures differ' + --error1='^ different because their structures differ' return 1 fi @@ -118,12 +118,12 @@ function is_same() ( # same checksum if test "${checksums[0]}" = "${checksums[1]}"; then - echo-style --g1="^ same because their checksums match" + echo-style --good1="^ same because their checksums match" return 0 fi # otherwise - echo-style --e1="^ different" + echo-style --error1="^ different" return 1 ) diff --git a/commands/is-tty b/commands/is-tty index d63366c97..aa19f05ba 100755 --- a/commands/is-tty +++ b/commands/is-tty @@ -3,7 +3,7 @@ function is_tty_test() ( source "$DOROTHY/sources/bash.bash" source "$(type -P eval-tester)" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" function __do_test { __print_line "\$- = $-" @@ -104,7 +104,7 @@ function is_tty_test() ( __print_line 'stderr =' echo-lines --indent=' ' --stdin <<<"$stderr" - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function is_tty() ( diff --git a/commands/mount-helper b/commands/mount-helper index e760fa7d3..505fb037e 100755 --- a/commands/mount-helper +++ b/commands/mount-helper @@ -1293,7 +1293,7 @@ function mount_helper() ( rm_cmd "${rm_cmd[*]}" } function do_configure { - echo-segment --h2='configure' + echo-style --h2='configure' # add fuse config # https://github.com/rfjakob/gocryptfs/blob/master/Documentation/MANPAGE.md#-allow_other @@ -1303,11 +1303,11 @@ function mount_helper() ( # ensure sudo and cron are configured correctly for automounting sudo-helper --local - echo-segment --g2='configure' + echo-style --g2='configure' } function do_automount { # prepare - echo-segment --h2='automount' + echo-style --h2='automount' local add_fstab_line add_cron_line # determine @@ -1324,7 +1324,7 @@ function mount_helper() ( # fstab if test -n "$fstab_needle"; then - echo-segment --h3='fstab' + echo-style --h3='fstab' if test -n "$fstab_source"; then echo-style --invert='fstab' ' is ' --positive='supported' ' for ' --code="$log_source" else @@ -1337,12 +1337,12 @@ function mount_helper() ( fi # apply config-edit --fstab --line="$fstab_line" --needle="$fstab_needle" --add="$add_fstab_line" - echo-segment --g3='fstab' + echo-style --g3='fstab' fi # cron if test -n "$cron_needle"; then - echo-segment --h3='cron' + echo-style --h3='cron' if test -n "$cron_line"; then echo-style --invert='cron' ' is ' --positive='supported' ' for ' --code="$log_source" else @@ -1361,10 +1361,10 @@ function mount_helper() ( config-edit --cron-system --needle="${option_target@Q}" --remove config-edit --cron-user --line="$cron_line" --needle="${option_target@Q}" --add="$add_cron_line" fi - echo-segment --g3='cron' + echo-style --g3='cron' fi - echo-segment --g2='automount' + echo-style --g2='automount' } function scan_haystack_for_string_needle { local filter="$1" @@ -1419,7 +1419,7 @@ function mount_helper() ( fi # check - echo-segment --h2='check mount entries' + echo-style --h2='check mount entries' local haystack found haystack="$(mount)" if test -n "$check_type"; then @@ -1465,11 +1465,11 @@ function mount_helper() ( if test -n "$found"; then SHARED_CHECK_STATUS+='[valid]' echo-style --positive='matching expectation:' $'\n' --code="$found" - echo-segment --g2='check mount entries' + echo-style --g2='check mount entries' return 0 else echo-style --warning='matching expectation:' ' ' --invert="$check_target" $'\n' --code='[[ expectation not mounted ]]' - echo-segment --e2='check mount entries' + echo-style --e2='check mount entries' return 1 fi } @@ -1491,7 +1491,7 @@ function mount_helper() ( # update check eval_capture -- do_check local_check_status="$SHARED_CHECK_STATUS" - echo-segment --h2='unmount' + echo-style --h2='unmount' # reminder to the user what they are working with log_source_target @@ -1707,7 +1707,7 @@ function mount_helper() ( fi # success - echo-segment --g2='unmount' + echo-style --g2='unmount' return 0 } function do_mount { @@ -1735,7 +1735,7 @@ function mount_helper() ( fi # segment - echo-segment --h2='mount' + echo-style --h2='mount' # validate gocryptfs here instead of during parsing, as if it is during parsing, it will crash if checking if an unmounted gocryptfs source is unmounted (e.g. /mnt/an-unmounted-hard-drive/a-gocryptfs-source) if test -n "$gocryptfs_source"; then @@ -1838,7 +1838,7 @@ function mount_helper() ( # log echo-style --success='Successfully mounted' ' ' --invert="$log_source" ' ' --success='to' ' ' --invert="$option_target" - echo-segment --g2='mount' + echo-style --g2='mount' } # ===================================== @@ -1880,14 +1880,14 @@ function mount_helper() ( # do the action with correct logging local action_status - echo-segment --h2="$title" + echo-style --h2="$title" log_source_target eval_capture --statusvar=action_status -- do_action log_source_target if test "$action_status" -eq 0; then - echo-segment --g2="$title" + echo-style --g2="$title" else - echo-segment --e2="$title" + echo-style --e2="$title" return "$action_status" fi } diff --git a/commands/read-key b/commands/read-key index 631036298..5c4d13814 100755 --- a/commands/read-key +++ b/commands/read-key @@ -3,7 +3,7 @@ function read_key_test() ( source "$DOROTHY/sources/bash.bash" - echo-segment --h1="TEST: $0" + echo-style --h1="TEST: $0" # refer to [is-tty --test] for more comprehensive testing @@ -94,7 +94,7 @@ function read_key_test() ( } | eval-tester --name='down was detected' --stdout='down' \ -- read-key --timeout=10 - echo-segment --g1="TEST: $0" + echo-style --g1="TEST: $0" return 0 ) function read_key() ( diff --git a/commands/setup-bin b/commands/setup-bin index 4ad934960..1132a9e4f 100755 --- a/commands/setup-bin +++ b/commands/setup-bin @@ -36,7 +36,7 @@ function setup_bin() ( # Helpers # prepare - echo-segment --h1='Setup Binaries' + echo-style --h1='Setup Binaries' # symlink_app ...[ ] function symlink_app { @@ -112,7 +112,7 @@ function setup_bin() ( # ===================================== # Done - echo-segment --g1='Setup Binaries' + echo-style --g1='Setup Binaries' ) # fire if invoked standalone diff --git a/commands/setup-dns b/commands/setup-dns index 622489589..c70c240b8 100755 --- a/commands/setup-dns +++ b/commands/setup-dns @@ -757,7 +757,7 @@ function setup_dns() ( # https://support.apple.com/en-us/HT202516 # log - echo-segment --h1="Configure and $action_title macOS" + echo-style --h1="Configure and $action_title macOS" # apply local interface @@ -766,7 +766,7 @@ function setup_dns() ( done # log - echo-segment --g1="Configure and $action_title macOS" + echo-style --g1="Configure and $action_title macOS" else # ------------------------------------- # DNS Service: Systemd (aka systemd-resolved, systemd-resolve, resolvectl, resolv) @@ -800,7 +800,7 @@ function setup_dns() ( # log local systemd_title='Systemd-resolved' - echo-segment --h1="Configure and $action_title $systemd_title" + echo-style --h1="Configure and $action_title $systemd_title" # dump the data for where we are sudo-helper -- resolvectl status --no-pager || : @@ -939,7 +939,7 @@ function setup_dns() ( # sudo-helper -- systemctl reset-failed # log - echo-segment --g1="Configure and $action_title $systemd_title" + echo-style --g1="Configure and $action_title $systemd_title" fi } function __is_vpn_interface { @@ -993,7 +993,7 @@ function setup_dns() ( fi # log - echo-segment --h1="$action_title $aghome_title" + echo-style --h1="$action_title $aghome_title" # check we are the right one check_installation "$aghome_id" "$aghome_bin_file" @@ -1025,10 +1025,10 @@ function setup_dns() ( # confirm success if test -x "$aghome_bin_file"; then - echo-segment --g1="$action_title $aghome_title" + echo-style --g1="$action_title $aghome_title" else echo-style --error="Unable to make executable: $aghome_bin_file" >/dev/stderr - echo-segment --e1="$action_title $aghome_title" + echo-style --e1="$action_title $aghome_title" return 1 fi } @@ -1039,7 +1039,7 @@ function setup_dns() ( fi # log - echo-segment --h1="Uninstall $aghome_title" + echo-style --h1="Uninstall $aghome_title" # stop and uninstall the service sudo-helper -- "${aghome_bin_cmd[@]}" --service stop || : @@ -1052,7 +1052,7 @@ function setup_dns() ( do_remove --reload --service="$aghome_id" -- "$aghome_bin_file" "$aghome_conf_dir" "$aghome_data_dir" "$aghome_state_dir" "$aghome_service_file" # log - echo-segment --g1="Uninstall $aghome_title" + echo-style --g1="Uninstall $aghome_title" } function aghome_configure { local action action_title upstream_servers server pattern replace @@ -1065,7 +1065,7 @@ function setup_dns() ( fi # log - echo-segment --h1="Configure and $action_title $aghome_title" + echo-style --h1="Configure and $action_title $aghome_title" # this is here, because we need to seed the configuration file before we can do changes to it if test ! -f "$aghome_conf_file" -a "$action" = 'enable'; then @@ -1113,7 +1113,7 @@ function setup_dns() ( fi # log - echo-segment --g1="Configure and $action_title $aghome_title" + echo-style --g1="Configure and $action_title $aghome_title" } # ===================================== @@ -1157,7 +1157,7 @@ function setup_dns() ( fi # prepare and log - echo-segment --h1="$action_title $dnscrypt_title" + echo-style --h1="$action_title $dnscrypt_title" # download the upgrade, prior to disabling temp_bin_file="$( @@ -1208,10 +1208,10 @@ function setup_dns() ( # confirm success if test -x "$dnscrypt_bin_file"; then - echo-segment --g1="$action_title $dnscrypt_title" + echo-style --g1="$action_title $dnscrypt_title" else echo-style --error="Unable to make executable: $dnscrypt_bin_file" >/dev/stderr - echo-segment --e1="$action_title $dnscrypt_title" + echo-style --e1="$action_title $dnscrypt_title" return 1 fi } @@ -1222,7 +1222,7 @@ function setup_dns() ( fi # log - echo-segment --h1="Uninstall $dnscrypt_title" + echo-style --h1="Uninstall $dnscrypt_title" # stop and uninstall the service sudo-helper -- "${dnscrypt_bin_cmd[@]}" --service stop || : @@ -1235,7 +1235,7 @@ function setup_dns() ( do_remove --reload --service="$dnscrypt_id" -- "$dnscrypt_bin_file" "$dnscrypt_conf_dir" "$dnscrypt_service_file" # log - echo-segment --g1="Uninstall $dnscrypt_title" + echo-style --g1="Uninstall $dnscrypt_title" } function dnscrypt_configure { local action action_title temp_conf_file dnscrypt_options @@ -1248,7 +1248,7 @@ function setup_dns() ( fi # log - echo-segment --h1="Configure and $action_title $dnscrypt_title" + echo-style --h1="Configure and $action_title $dnscrypt_title" # if the configuration doesn't exist if test ! -f "$dnscrypt_conf_file"; then @@ -1256,7 +1256,7 @@ function setup_dns() ( # as we deactivated the prior service echo-style --error="Missing configuration file: $dnscrypt_conf_file" >/dev/stderr echo-style --warning='You should attempt reinstallation then try again.' >/dev/stderr - echo-segment --e1="Configure and $action_title $dnscrypt_title" + echo-style --e1="Configure and $action_title $dnscrypt_title" fi # if [dnscrypt_names] is empty, get the user to decide @@ -1302,7 +1302,7 @@ function setup_dns() ( fi # log - echo-segment --g1="Configure and $action_title $dnscrypt_title" + echo-style --g1="Configure and $action_title $dnscrypt_title" } # ===================================== @@ -1346,7 +1346,7 @@ function setup_dns() ( fi # log - echo-segment --h1="$action_title $cloudflared_title" + echo-style --h1="$action_title $cloudflared_title" # download the upgrade, prior to disabling # setup-util --cli=cloudflared APT_KEY='https://pkg.cloudflare.com/cloudflare-main.gpg' APT_REPO='deb [arch={ARCH} signed-by={KEY}] https://pkg.cloudflare.com/cloudflared jammy main' APT='cloudflared' @@ -1379,10 +1379,10 @@ function setup_dns() ( # confirm success if test -x "$cloudflared_bin_file"; then - echo-segment --g1="$action_title $cloudflared_title" + echo-style --g1="$action_title $cloudflared_title" else echo-style --error="Unable to make executable: $cloudflared_bin_file" >/dev/stderr - echo-segment --e1="$action_title $cloudflared_title" + echo-style --e1="$action_title $cloudflared_title" return 1 fi } @@ -1393,7 +1393,7 @@ function setup_dns() ( fi # log - echo-segment --h1="Uninstall $cloudflared_title" + echo-style --h1="Uninstall $cloudflared_title" # stop, disable, uninstall the service if it exists service_disable "$cloudflared_proxy_service_file" @@ -1409,7 +1409,7 @@ function setup_dns() ( fi # log - echo-segment --g1="Uninstall $cloudflared_title" + echo-style --g1="Uninstall $cloudflared_title" } function cloudflared_configure { local action action_title upstream_servers upstream_section upstream_args server @@ -1424,7 +1424,7 @@ function setup_dns() ( fi # log - echo-segment --h1="Configure and $action_title $cloudflared_title" + echo-style --h1="Configure and $action_title $cloudflared_title" # check check_installation "$cloudflared_id" "$cloudflared_bin_file" @@ -1518,7 +1518,7 @@ EOF fi # log - echo-segment --g1="Configure and $action_title $cloudflared_title" + echo-style --g1="Configure and $action_title $cloudflared_title" } # ===================================== @@ -1569,7 +1569,7 @@ EOF fi # log, tunnels are always enable - echo-segment --h1="Configure and Enable Cloudflared Tunnel" + echo-style --h1="Configure and Enable Cloudflared Tunnel" # process args while test "$#" -ne 0; do @@ -1732,7 +1732,7 @@ EOF service_enable "$tunnel_service_file" # log - echo-segment --g1="Configure and Enable Cloudflared Tunnel" + echo-style --g1="Configure and Enable Cloudflared Tunnel" } function tunnel_configure { local args arg @@ -1788,7 +1788,7 @@ EOF # ===================================== # Action - echo-segment --h1='Setup DNS' + echo-style --h1='Setup DNS' # ------------------------------------- # Prompts @@ -1855,9 +1855,9 @@ EOF # Verification # Verify DNS - echo-segment --h1='Verify DNS' + echo-style --h1='Verify DNS' verify_dns_generic - echo-segment --g1='Verify DNS' + echo-style --g1='Verify DNS' # Prompt the user which hosts they want to use # This is here, as we need internet to be working. @@ -1919,7 +1919,7 @@ EOF # --field='DNS_PROVIDER' --value="$DNS_PROVIDER" # done - echo-segment --g1='Setup DNS' + echo-style --g1='Setup DNS' ) # fire if invoked standalone diff --git a/commands/setup-git b/commands/setup-git index 56ddc9247..f52bbb712 100755 --- a/commands/setup-git +++ b/commands/setup-git @@ -63,12 +63,12 @@ function setup_git() ( # ===================================== # Prepare - echo-segment --h1='Setup Git' + echo-style --h1='Setup Git' # dependencies - echo-segment --h2='Install Git' + echo-style --h2='Install Git' setup-util-git - echo-segment --g2='Install Git' + echo-style --g2='Install Git' # vars local protocol_options=( @@ -230,7 +230,7 @@ function setup_git() ( # Apply Configuration # General - echo-style --h2='Git Configuration: General' + echo-style --header2='Git Configuration: General' git config --global core.excludesfile "$HOME/.gitignore_global" git config --global push.default simple git config --global mergetool.keepBackup false @@ -240,13 +240,13 @@ function setup_git() ( fi # Profile - echo-style --h2='Git Configuration: Profile' + echo-style --header2='Git Configuration: Profile' git config --global user.name "$GIT_NAME" git config --global user.email "$GIT_EMAIL" git config --global git.protocol "$GIT_PROTOCOL" # Authorizations - echo-style --h2='Git Configuration: Auth' + echo-style --header2='Git Configuration: Auth' if test -n "$GITHUB_USERNAME"; then git config --global github.user "$GITHUB_USERNAME" else @@ -259,7 +259,7 @@ function setup_git() ( fi # Merge Tool - echo-style --h2="Git Configuration: Merge/Diff Tool: $MERGE_TOOL" + echo-style --header2="Git Configuration: Merge/Diff Tool: $MERGE_TOOL" git config --global diff.tool "$MERGE_TOOL" git config --global merge.tool "$MERGE_TOOL" @@ -267,18 +267,18 @@ function setup_git() ( local editor editor="$(edit --dry --wait || :)" if test -n "$editor"; then - echo-style --h2="Git Configuration: Editor: $editor" + echo-style --header2="Git Configuration: Editor: $editor" git config --global core.editor "$editor" fi # Authentication # Use MacOS Credential Helper if available, otherwise default to time cache if is-mac; then - echo-style --h2="Git Configuration: MacOS Credentials" + echo-style --header2="Git Configuration: MacOS Credentials" git config --global credential.helper osxkeychain git config --global difftool.prompt false else - echo-style --h2="Git Configuration: Linux Credentials" + echo-style --header2="Git Configuration: Linux Credentials" git config --global credential.helper 'cache --timeout=86400' fi @@ -298,13 +298,13 @@ function setup_git() ( # fatal: the receiving end does not support --signed push # done - echo-style --h2="Git Configuration: Signing: Enabled" + echo-style --header2="Git Configuration: Signing: Enabled" } function sign_check_key { # Check we have a key if test -z "$key"; then cat <<-EOF >/dev/stderr - $(echo-style --e2="Git Configuration: Signing:") + $(echo-style --error2="Git Configuration: Signing:") Signing was desired, however there was no key specified. $(echo-style --notice='Run the' ' ' --code_notice='setup-git --configure' ' ' --notice='to configure.') EOF @@ -314,7 +314,7 @@ function setup_git() ( # Check the key exists if test ! -f "$key"; then cat <<-EOF >/dev/stderr - $(echo-style --e2="Git Configuration: Signing:") + $(echo-style --error2="Git Configuration: Signing:") Signing was desired, however the key does not exist: $key $(echo-style --notice='Run the' ' ' --code_notice='setup-git --configure' ' ' --notice='to configure.') EOF @@ -329,7 +329,7 @@ function setup_git() ( git config --global --unset tag.gpgsign || : git config --global --unset commit.gpgsign || : git config --global --unset user.signingkey || : - echo-style --h2="Git Configuration: Signing: Disabled" + echo-style --header2="Git Configuration: Signing: Disabled" } function sign_krypton { # Use Krypton for Signing @@ -338,7 +338,7 @@ function setup_git() ( # configure git for krypton git config --global gpg.program "$(type -P krgpg)" git config --global --unset user.signingkey || : - echo-style --h2="Git Configuration: Kypton: Enabled" + echo-style --header2="Git Configuration: Kypton: Enabled" } function sign_gnu { # Use GnuPG (GPG) Key for Signing @@ -346,7 +346,7 @@ function setup_git() ( sign_check_key "$key" # key - echo-style --h2="Git Configuration: Signing: GPG Key: $key" + echo-style --header2="Git Configuration: Signing: GPG Key: $key" git config --using GnuPGlobal gpg.program "$(type -P gpg)" git config --global user.signingkey "$key" @@ -359,7 +359,7 @@ function setup_git() ( sign_check_key "$key" # key - echo-style --h2="Git Configuration: Signing: SSH Key: $key" + echo-style --header2="Git Configuration: Signing: SSH Key: $key" git config --global gpg.format ssh git config --global user.signingkey "$key" } @@ -385,7 +385,7 @@ function setup_git() ( git config --global user.signingkey "$op_pub" git config --global gpg.ssh.program "$(type -P op-ssh-sign)" cat <<-EOF - $(echo-style --h2="Git Configuration: Signing: 1Password") + $(echo-style --header2="Git Configuration: Signing: 1Password") Make sure you add the following public key as your SSH signing key on: https://github.com/settings/ssh/new @@ -393,14 +393,14 @@ function setup_git() ( EOF else cat <<-EOF >/dev/stderr - $(echo-style --e2="Git Configuration: Signing: 1Password") + $(echo-style --error2="Git Configuration: Signing: 1Password") GPG using 1Password was desired, however was unable to find a public key. EOF return 1 fi else cat <<-EOF >/dev/stderr - $(echo-style --e2="Git Configuration: Signing: 1Password") + $(echo-style --error2="Git Configuration: Signing: 1Password") GPG using 1Password was desired, however 1Password does not appear to be installed on this system. Install it first via: $(echo-style --code="setup-util-1password") @@ -411,7 +411,7 @@ function setup_git() ( fi } function sign_setup { - echo-style --h2="Git Configuration: Signing" + echo-style --header2="Git Configuration: Signing" # adjust if test "$GPG_SIGNING_AGENT" = 'op'; then @@ -447,7 +447,7 @@ function setup_git() ( # ===================================== # Security - echo-style --h2="Git Configuration: Permissions" + echo-style --header2="Git Configuration: Permissions" ssh-helper permissions gpg-helper permissions @@ -467,7 +467,7 @@ function setup_git() ( # ===================================== # Configure protocols now that ssh is setup - echo-style --h2="Git Configuration: Protocol: $GIT_PROTOCOL" + echo-style --header2="Git Configuration: Protocol: $GIT_PROTOCOL" if test "$GIT_PROTOCOL" = 'ssh' && ! ssh-helper test; then echo-style --notice="SSH failed, temporarily configuring for HTTPS" GIT_PROTOCOL='https' @@ -497,7 +497,7 @@ function setup_git() ( # ===================================== # Done - echo-segment --g1='Setup Git' + echo-style --g1='Setup Git' ) # fire if invoked standalone diff --git a/commands/setup-go b/commands/setup-go index df9fa82f1..8c02a915c 100755 --- a/commands/setup-go +++ b/commands/setup-go @@ -79,7 +79,7 @@ function setup_go() ( # ===================================== # Start - echo-segment --h1='Setup Go' + echo-style --h1='Setup Go' # ===================================== # Install @@ -121,7 +121,7 @@ function setup_go() ( # ===================================== # Finish - echo-segment --g1='Setup Go' + echo-style --g1='Setup Go' ) # fire if invoked standalone diff --git a/commands/setup-hosts b/commands/setup-hosts index 3b113b9ec..a89cace6b 100755 --- a/commands/setup-hosts +++ b/commands/setup-hosts @@ -48,7 +48,7 @@ function setup_hosts() ( # ===================================== # Start - echo-segment --h1="Setup Hosts file" + echo-style --h1="Setup Hosts file" # ===================================== # Configuration @@ -178,7 +178,7 @@ function setup_hosts() ( # ===================================== # Finish - echo-segment --g1="Setup Hosts file" + echo-style --g1="Setup Hosts file" # finally, flush dns flush-dns diff --git a/commands/setup-linux b/commands/setup-linux index ab1d4e4ae..930fef9be 100755 --- a/commands/setup-linux +++ b/commands/setup-linux @@ -360,7 +360,7 @@ function setup_linux() ( done elif test "$action" = 'install' -o "$action" = 'update'; then # log - echo-segment --h1="$title" + echo-style --h1="$title" # update references for item in "${updates[@]}"; do @@ -416,7 +416,7 @@ function setup_linux() ( done # log - echo-segment --g1="$title" + echo-style --g1="$title" else # unknown action help "An unrecognised action was provided: $action" diff --git a/commands/setup-linux-raspi b/commands/setup-linux-raspi index 78a4f89d3..5b7752cf6 100755 --- a/commands/setup-linux-raspi +++ b/commands/setup-linux-raspi @@ -51,7 +51,7 @@ function setup_linux_raspi() ( # Action # log - echo-segment --h1='Raspberry Pi Essentials' + echo-style --h1='Raspberry Pi Essentials' # ensure raspi firmware is up to date # otherwise newer operating system releases can cause issues @@ -91,7 +91,7 @@ function setup_linux_raspi() ( return 1 fi - echo-segment --g1='Raspberry Pi Essentials' + echo-style --g1='Raspberry Pi Essentials' ) # fire if invoked standalone diff --git a/commands/setup-linux-recovery b/commands/setup-linux-recovery index 3724c97e4..ee2e2ca45 100755 --- a/commands/setup-linux-recovery +++ b/commands/setup-linux-recovery @@ -52,7 +52,7 @@ function setup_linux_recovery() ( # ===================================== # Action - echo-segment --h1='Update GRUB with Recovery Hotkeys' + echo-style --h1='Update GRUB with Recovery Hotkeys' sudo-helper --inherit \ -- config-helper --file='/etc/sysctl.d/99-sysctl.conf' -- \ @@ -65,7 +65,7 @@ function setup_linux_recovery() ( echo-style --error='Failed to upgrade grub with the recovery options. Please send a PR to Dorothy to add support. Continuing...' >/dev/stderr fi - echo-segment --g1='Update GRUB with Recovery Hotkeys' + echo-style --g1='Update GRUB with Recovery Hotkeys' ) # fire if invoked standalone diff --git a/commands/setup-linux-safegraphics b/commands/setup-linux-safegraphics index 829e70558..d7a75e82a 100755 --- a/commands/setup-linux-safegraphics +++ b/commands/setup-linux-safegraphics @@ -44,7 +44,7 @@ function setup_linux_safegraphics() ( # ===================================== # Action - echo-segment --h1='Update GRUB with Safe Graphics' + echo-style --h1='Update GRUB with Safe Graphics' sudo-helper --inherit \ -- config-helper --file='/etc/default/grub' -- \ @@ -52,7 +52,7 @@ function setup_linux_safegraphics() ( grub-helper - echo-segment --g1='Update GRUB with Safe Graphics' + echo-style --g1='Update GRUB with Safe Graphics' ) # fire if invoked standalone diff --git a/commands/setup-mac b/commands/setup-mac index 5d8f389b8..162e68651 100755 --- a/commands/setup-mac +++ b/commands/setup-mac @@ -60,7 +60,7 @@ function setup_mac() ( setup-mac-brew clean elif test "$action" = 'install' -o "$action" = 'update'; then # log - echo-segment --h1="$title" + echo-style --h1="$title" # reassert minimal apple dependencies setup-util-apple-rosetta @@ -81,7 +81,7 @@ function setup_mac() ( fi # log - echo-segment --g1="$title" + echo-style --g1="$title" else # unknown action help "An unrecognised action was provided: $action" diff --git a/commands/setup-mac-appstore b/commands/setup-mac-appstore index cf1a565a7..1013ad443 100755 --- a/commands/setup-mac-appstore +++ b/commands/setup-mac-appstore @@ -74,7 +74,7 @@ function setup_mac_appstore() ( # Action # log - echo-segment --h1="Mac App Store" + echo-style --h1="Mac App Store" # dependencies setup-util-mas --quiet @@ -117,7 +117,7 @@ function setup_mac_appstore() ( fi # log - echo-segment --g1="Mac App Store" + echo-style --g1="Mac App Store" ) # fire if invoked standalone diff --git a/commands/setup-mac-brew b/commands/setup-mac-brew index 6d6324586..4f91d6da2 100755 --- a/commands/setup-mac-brew +++ b/commands/setup-mac-brew @@ -206,7 +206,7 @@ function setup_mac_brew() ( function clean_brew { # environment provides: # HOMEBREW_ARCH, HOMEBREW_PREFIX - echo-segment --h2='Cleanup homebrew' + echo-style --h2='Cleanup homebrew' if is-brew; then # fix common permission errors # Error: Could not cleanup old kegs! Fix your permissions on: @@ -229,7 +229,7 @@ function setup_mac_brew() ( # cleanup further fs-rm --quiet --no-confirm --sudo -- "$(brew --cache)" fi - echo-segment --g2='Cleanup homebrew' + echo-style --g2='Cleanup homebrew' } # update brew @@ -261,7 +261,7 @@ function setup_mac_brew() ( # if yes, then install the linting tools if test "$HOMEBREW_ENCODING_INSTALL" = 'yes'; then - echo-segment --h1="Homebrew encoding tools" + echo-style --h1="Homebrew encoding tools" echo-style --notice="This can take a while... ⏲" # install dependencies: @@ -282,7 +282,7 @@ function setup_mac_brew() ( uninstall_encoding # log - echo-segment --h2="Install ffmpeg with options" + echo-style --h2="Install ffmpeg with options" # fetch all the build options for ffmpeg local ffmpeg_opts bad_option @@ -299,8 +299,8 @@ function setup_mac_brew() ( -- brew install homebrew-ffmpeg/ffmpeg/ffmpeg "${ffmpeg_opts[@]}" # log - echo-segment --g2='Install ffmpeg with options' - echo-segment --g1='Homebrew encoding tools' + echo-style --g2='Install ffmpeg with options' + echo-style --g1='Homebrew encoding tools' else echo-style --notice='Skipped encoding tools installation, due to preference.' fi @@ -346,36 +346,36 @@ function setup_mac_brew() ( # install packages with brew, that are fast to install function brew_install_fast { - echo-segment --h2="Install $# formulas" + echo-style --h2="Install $# formulas" brew_install --formula -- "$@" - echo-segment --g2="Install $# formulas" + echo-style --g2="Install $# formulas" } # install packages with brew, that are slow to install function brew_install_slow { # if we are on an official directory, then we are using bottles which are pre-compiled and fast if test "$HOMEBREW_PREFIX" = '/usr/local' -o "$HOMEBREW_PREFIX" = '/opt/homebrew'; then - echo-segment --h2="Install $# extra formulas" + echo-style --h2="Install $# extra formulas" brew_install --formula -- "$@" - echo-segment --g2="Install $# extra formulas" + echo-style --g2="Install $# extra formulas" else # otherwise we are on a custom directory, can't use bottles, so have to compile ourselves, which takes forever if confirm --linger --bool --ppid=$$ -- "Do you want to install [$*]?" 'These can take hours, so best left overnight...'; then - echo-segment --h2="Install $# slow formulas" + echo-style --h2="Install $# slow formulas" echo-style --notice="This can take a while... ⏲" brew_install --formula -- "$@" - echo-segment --g2="Install $# slow formulas" + echo-style --g2="Install $# slow formulas" fi fi } # install fonts with brew function brew_install_fonts { - echo-segment --h2="Install $# fonts" + echo-style --h2="Install $# fonts" if test "$#" -ne 0; then eval_capture brew_install --cask -- "$@" fi - echo-segment --g2="Install $# fonts" + echo-style --g2="Install $# fonts" } # install casks with brew @@ -391,17 +391,17 @@ function setup_mac_brew() ( )" mapfile -t cask_selection <<<"$fodder" # <( destroys stdin fi - echo-segment --h2="Install $# casks" + echo-style --h2="Install $# casks" if test "${#cask_selection[@]}" -ne 0; then brew_install --cask -- "${cask_selection[@]}" fi - echo-segment --g2="Install $# casks" + echo-style --g2="Install $# casks" } # uninstall packages with brew function brew_uninstall { local pkg - echo-segment --h2="Uninstall $# formulas" + echo-style --h2="Uninstall $# formulas" if test "$#" -ne 0; then echo-style --dim='You can ignore "No available ..." errors.' echo-style --dim='You can ignore "No such keg: ..." errors.' @@ -409,33 +409,33 @@ function setup_mac_brew() ( brew uninstall --quiet --ignore-dependencies "$pkg" || : done fi - echo-segment --g2="Uninstall $# formulas" + echo-style --g2="Uninstall $# formulas" } # untap repositories with brew function brew_untap { local tap - echo-segment --h2="Untap $# repositories" + echo-style --h2="Untap $# repositories" if test "$#" -ne 0; then echo-style --dim='You can ignore "Error: No available tap ..." errors.' for tap in "$@"; do brew untap --quiet "$tap" || : done fi - echo-segment --g2="Untap $# repositories" + echo-style --g2="Untap $# repositories" } # tap repositories with brew function brew_tap { local tap - echo-segment --h2="Tap $# repositories" + echo-style --h2="Tap $# repositories" for tap in "$@"; do eval_helper --quiet --no-wrap \ --pending="Tap: $tap" \ --success="Tapped: $tap" \ -- brew tap --quiet "$tap" done - echo-segment --g2="Tap $# repositories" + echo-style --g2="Tap $# repositories" } # update A repository with brew @@ -458,14 +458,14 @@ function setup_mac_brew() ( # update repositories with brew function brew_repo { local repo - echo-segment --h2="Update $# repositories" + echo-style --h2="Update $# repositories" for repo in "$@"; do eval_helper --quiet --no-wrap \ --pending="Updating: $repo" \ --success="Updated: $repo" \ -- brew_update_repo "$repo" done - echo-segment --g2="Update $# repositories" + echo-style --g2="Update $# repositories" } # ===================================== @@ -479,9 +479,9 @@ function setup_mac_brew() ( # action: uninstall then exit if test "$action" = 'uninstall'; then - echo-segment --h1='Uninstall Homebrew' + echo-style --h1='Uninstall Homebrew' setup-util-brew --uninstall --no-quiet - echo-segment --g1='Uninstall Homebrew' + echo-style --g1='Uninstall Homebrew' echo-style --green+bold='Homebrew uninstalled, ' --red+bold+underline='restart your terminal to avoid errors.' return fi @@ -489,11 +489,11 @@ function setup_mac_brew() ( # log local title title="Setup/$(__uppercase_first_letter "$action") Homebrew" - echo-segment --h1="$title" + echo-style --h1="$title" # ensure brew is installed if ! is-brew; then - echo-segment --h2='Install Homebrew' + echo-style --h2='Install Homebrew' setup-util-brew --upgrade --no-quiet source "$DOROTHY/sources/environment.sh" # child processes will also inherit these changes echo-style --g2='Install Homebrew' @@ -509,9 +509,9 @@ function setup_mac_brew() ( brew_repo "${repos[@]}" # update - echo-segment --h2="Update Homebrew" + echo-style --h2="Update Homebrew" brew update --quiet - echo-segment --g2="Update Homebrew" + echo-style --g2="Update Homebrew" # uninstall packages brew_uninstall "${HOMEBREW_UNINSTALL[@]}" @@ -527,15 +527,15 @@ function setup_mac_brew() ( uninstall_encoding # update packages - echo-segment --h2="Upgrade Homebrew" + echo-style --h2="Upgrade Homebrew" update_brew - echo-segment --g2="Upgrade Homebrew" + echo-style --g2="Upgrade Homebrew" # depedencies - echo-segment --h2="Install build dependencies" + echo-style --h2="Install build dependencies" eval_helper --quiet \ -- setup-util-devel - echo-segment --g2="Install build dependencies" + echo-style --g2="Install build dependencies" # install encoding tools install_encoding @@ -629,7 +629,7 @@ function setup_mac_brew() ( # Finish # log - echo-segment --g1="$title" + echo-style --g1="$title" ) # fire if invoked standalone diff --git a/commands/setup-node b/commands/setup-node index 59e4c411e..86428b09e 100755 --- a/commands/setup-node +++ b/commands/setup-node @@ -92,7 +92,7 @@ function setup_node() ( # ===================================== # Start - echo-segment --h1='Setup Node.js' + echo-style --h1='Setup Node.js' # ===================================== # Install/Upgrade Node.js and npm @@ -104,7 +104,7 @@ function setup_node() ( # helper function configure_system_npm { - echo-segment --h2='Configure npm' + echo-style --h2='Configure npm' nvm-env -- npm config set init-author-name "$( ask --required --linger \ --question='What is the profile name that you want to configure npm with?' \ @@ -125,7 +125,7 @@ function setup_node() ( --question='What license do you want to configure npm to default to?' \ --default="$(npm config get init-license)" )" - echo-segment --g2='Configure npm' + echo-style --g2='Configure npm' } # check @@ -147,9 +147,9 @@ function setup_node() ( # Packages via npm if test "${#NPM_INSTALL[@]}" -ne 0; then - echo-segment --h2='Node.js Packages' + echo-style --h2='Node.js Packages' setup-util --installer=NODE -- "${NPM_INSTALL[@]}" - echo-segment --g2='Node.js Packages' + echo-style --g2='Node.js Packages' fi # ===================================== @@ -157,17 +157,17 @@ function setup_node() ( local version if test "${#NODE_VERSIONS[@]}" -ne 0; then - echo-segment --h2='Additional Node.js Versions' + echo-style --h2='Additional Node.js Versions' for version in "${NODE_VERSIONS[@]}"; do eval-helper --wrap --quiet --success="Installed: v$version" -- nvm-env -- nvm install "$version" done - echo-segment --g2='Additional Node.js Versions' + echo-style --g2='Additional Node.js Versions' fi # ===================================== # Finish - echo-segment --g1='Setup Node.js' + echo-style --g1='Setup Node.js' ) # fire if invoked standalone diff --git a/commands/setup-python b/commands/setup-python index 4ffa37278..546aa34ab 100755 --- a/commands/setup-python +++ b/commands/setup-python @@ -83,16 +83,16 @@ function setup_python() ( # ===================================== # Start - echo-segment --h1='Setup Python' + echo-style --h1='Setup Python' # ===================================== # Install # log - echo-segment --h2="Install Python" + echo-style --h2="Install Python" setup-util-python source "$DOROTHY/sources/environment.sh" - echo-segment --g2="Install Python" + echo-style --g2="Install Python" # ===================================== # PyEnv @@ -126,7 +126,7 @@ function setup_python() ( fi # log - echo-segment --h2="packages for $bin" + echo-style --h2="packages for $bin" echo-style --dim="$bin: $(type -P "$bin")" # generic prepare @@ -148,7 +148,7 @@ function setup_python() ( fi # download pip - echo-segment --h3='download pip' + echo-style --h3='download pip' pip_installer="$( fs-temp \ --directory='setup-python' \ @@ -162,14 +162,14 @@ function setup_python() ( -- down "$pip_installer_url" --filepath="$pip_installer" chmod +x "$pip_installer" echo-style --dim="installer: $pip_installer" - echo-segment --g3='download pip' + echo-style --g3='download pip' # install pip, depending on the situation, it may or may not have --break-system-packages - echo-segment --h3='install pip' + echo-style --h3='install pip' eval-helper --quiet \ -- "$bin" "$pip_installer" --user --break-system-packages || eval-helper --quiet \ -- "$bin" "$pip_installer" --user - echo-segment --g3='install pip' + echo-style --g3='install pip' source "$DOROTHY/sources/environment.sh" # echo @@ -180,40 +180,40 @@ function setup_python() ( # source "$DOROTHY/sources/environment.sh" # install pip packages - echo-segment --h3="install ${#pip_install[@]} pip packages" + echo-style --h3="install ${#pip_install[@]} pip packages" for item in "${pip_install[@]}"; do eval-helper --quiet --success="$(echo-style --success="pip installed: $item")" \ -- "$bin" -m \ pip install --user --break-system-packages --upgrade --force-reinstall --no-warn-script-location \ "$item" || : done - echo-segment --g3="install ${#pip_install[@]} pip packages" + echo-style --g3="install ${#pip_install[@]} pip packages" # pipx if test "$python_version" -eq 3; then # install pipx - echo-segment --h3='install pipx' + echo-style --h3='install pipx' fs-rm --quiet --no-confirm -- "$HOME/.local/pipx" # fix: Not removing existing venv /Users/balupton/.local/pipx/venvs/youtube-dl because it was not created in this session eval-helper --quiet \ -- "$bin" -m \ pip install --user --break-system-packages --upgrade --force-reinstall --no-warn-script-location \ pipx || : source "$DOROTHY/sources/environment.sh" - echo-segment --g3='install pipx' + echo-style --g3='install pipx' # install pipx packages - echo-segment --h3="install ${#pipx_install[@]} pipx packages" + echo-style --h3="install ${#pipx_install[@]} pipx packages" for item in "${pipx_install[@]}"; do eval-helper --quiet --success="$(echo-style --success="pipx installed: $item")" \ -- "$bin" -m \ pipx install --include-deps --force \ "$item" || : done - echo-segment --g3="install ${#pipx_install[@]} pipx packages" + echo-style --g3="install ${#pipx_install[@]} pipx packages" fi # done - echo-segment --g2="packages for $bin" + echo-style --g2="packages for $bin" } # install @@ -224,7 +224,7 @@ function setup_python() ( # ===================================== # Finish - echo-segment --g1='Setup Python' + echo-style --g1='Setup Python' ) # fire if invoked standalone diff --git a/commands/setup-ruby b/commands/setup-ruby index e1d5d1567..e2141b4ee 100755 --- a/commands/setup-ruby +++ b/commands/setup-ruby @@ -87,19 +87,19 @@ function setup_ruby() ( # ===================================== # Start - echo-segment --h1='Setup Ruby' + echo-style --h1='Setup Ruby' # ===================================== # Install - echo-segment --h2='Install ruby' + echo-style --h2='Install ruby' setup-util-ruby --upgrade --no-quiet - echo-segment --h2='Install ruby' + echo-style --h2='Install ruby' # ===================================== # Caches - echo-segment --h2='Pruning cache' + echo-style --h2='Pruning cache' # .ruby is an deprecated cache location, clear it if test -d "$HOME/.ruby"; then @@ -122,17 +122,17 @@ function setup_ruby() ( mkdir -p "$GEM_HOME" fi - echo-segment --g2='Pruning cache' + echo-style --g2='Pruning cache' # ===================================== # Reload # reload paths for changes to be detected and confirm installation - echo-segment --h2='Reload paths' + echo-style --h2='Reload paths' source "$DOROTHY/sources/environment.sh" if ! command-exists gem; then - echo-style --e2='Unable to find [gem] executable, so cannot proceed... ❌' >/dev/stderr + echo-style --error2='Unable to find [gem] executable, so cannot proceed... ❌' >/dev/stderr return 1 fi echo-style \ @@ -140,7 +140,7 @@ function setup_ruby() ( --dim="Ruby Version: $(ruby --version)" $'\n' \ --dim="Gem Path: $(type -P gem)" $'\n' \ --dim="Gem Version: $(gem --version)" - echo-segment --g2='Reload paths' + echo-style --g2='Reload paths' # ===================================== # Update @@ -163,7 +163,7 @@ function setup_ruby() ( # ===================================== # Finish - echo-segment --g1='Setup Ruby' + echo-style --g1='Setup Ruby' ) # fire if invoked standalone diff --git a/commands/setup-rust b/commands/setup-rust index 01e7c00ee..ebb924554 100755 --- a/commands/setup-rust +++ b/commands/setup-rust @@ -82,7 +82,7 @@ function setup_rust() ( # ===================================== # Start - echo-segment --h1='Setup Rust' + echo-style --h1='Setup Rust' # ===================================== # Install @@ -97,7 +97,7 @@ function setup_rust() ( # ===================================== # Finish - echo-segment --g1='Setup Rust' + echo-style --g1='Setup Rust' ) # fire if invoked standalone diff --git a/commands/setup-shell b/commands/setup-shell index dc4520423..7a7e588f2 100755 --- a/commands/setup-shell +++ b/commands/setup-shell @@ -66,26 +66,26 @@ function setup_shell() ( shell="$(basename "$1")" path="$(type -P "$1" || :)" if test -z "$path"; then - echo-segment --error="Failed to verify that shell [$shell] exists and is executable." >/dev/stderr + echo-style --error="Failed to verify that shell [$shell] exists and is executable." >/dev/stderr return 8 # ENOEXEC 8 Exec format error fi # log - echo-segment --h1="Selected [$shell] at [$path]" + echo-style --h1="Selected [$shell] at [$path]" # update system whitelist - echo-segment --h2='Update system whitelist' + echo-style --h2='Update system whitelist' if contains-line --stdin --needle="$path" /dev/stderr - echo-segment --e2="Update login shell for [$USER]" + echo-style --e2="Update login shell for [$USER]" return 19 # ENODEV 19 Operation not supported by device fi - echo-segment --g2="Update login shell for [$USER]" + echo-style --g2="Update login shell for [$USER]" # success case - echo-segment --g1="Selected [$shell] at [$path]" + echo-style --g1="Selected [$shell] at [$path]" echo-style --notice="Restart your terminal, or open a new one, for the change to take effect." } function use_first_available { diff --git a/commands/setup-system b/commands/setup-system index be346560c..f513fdebd 100755 --- a/commands/setup-system +++ b/commands/setup-system @@ -55,7 +55,7 @@ function setup_system() ( # Action # log - echo-segment --h1="$title" + echo-style --h1="$title" # action if test "$action" = 'install' -o "$action" = 'update'; then @@ -147,7 +147,7 @@ function setup_system() ( fi # log - echo-segment --g1="$title" + echo-style --g1="$title" ) # fire if invoked standalone diff --git a/commands/setup-util b/commands/setup-util index 4db563a77..246e49b09 100755 --- a/commands/setup-util +++ b/commands/setup-util @@ -497,26 +497,26 @@ function setup_util() ( # nothing installed if test "$option_action" = 'uninstall'; then # already uninstalled, so no need to uninstall - maybe_echo_style --g3="The [$option_name] utility was not found. Already uninstalled. ✅" >/dev/stderr + maybe_echo_style --good3="The [$option_name] utility was not found. Already uninstalled. ✅" >/dev/stderr # exit return 0 fi option_upgrade='no' # note that we aren't upgrading, which is used for logging # perform install - maybe_echo_style --h3="The [$option_name] utility was not found. Installing automatically... ⏲" >/dev/stderr + maybe_echo_style --header3="The [$option_name] utility was not found. Installing automatically... ⏲" >/dev/stderr elif test "$option_action" = 'uninstall'; then # exists, uninstall enabled option_upgrade='no' # note that we aren't upgrading, which is used for logging # perform uninstall - maybe_echo_style --h3="The [$option_name] utility is marked for uninstall. Uninstalling... ⏲" >/dev/stderr + maybe_echo_style --header3="The [$option_name] utility is marked for uninstall. Uninstalling... ⏲" >/dev/stderr elif test "$option_upgrade" = 'yes'; then # exists, upgrade enabled # perform upgrade - maybe_echo_style --h3="The [$option_name] utility is marked for upgrade. Upgrading... ⏲" >/dev/stderr + maybe_echo_style --header3="The [$option_name] utility is marked for upgrade. Upgrading... ⏲" >/dev/stderr elif test "$cli_working" = 'fail'; then # exists, not working # perform reinstall - maybe_echo_style --h3="The [$option_name] utility via [$option_cli] is misbehaving. Reinstalling automatically... ⏲" >/dev/stderr + maybe_echo_style --header3="The [$option_name] utility via [$option_cli] is misbehaving. Reinstalling automatically... ⏲" >/dev/stderr elif test "$option_check" = 'no'; then # exists, don't care, proceed anyway # used by setup-util-nerd-fonts to ensure we check for the correct font @@ -524,7 +524,7 @@ function setup_util() ( else # exists, no upgrade, is working # already installed, so no need to install again - maybe_echo_style --g3="The [$option_name] utility is already installed. ✅" >/dev/stderr + maybe_echo_style --good3="The [$option_name] utility is already installed. ✅" >/dev/stderr return 0 fi fi @@ -3605,7 +3605,7 @@ function setup_util() ( else suffix+='. ✅' fi - maybe_echo_style --g3="The [$option_name] utility was ${action_log}${suffix}" >/dev/stderr + maybe_echo_style --good3="The [$option_name] utility was ${action_log}${suffix}" >/dev/stderr } function log_failure { local suffix='' method="${1-}" @@ -3617,9 +3617,9 @@ function setup_util() ( suffix='. ❌' fi if test "$option_optional" = 'yes'; then - maybe_echo_style --n3="The [$option_name] optional utility was not ${action_log}${suffix}" >/dev/stderr + maybe_echo_style --notice3="The [$option_name] optional utility was not ${action_log}${suffix}" >/dev/stderr else - echo-style --e3="The [$option_name] required utility was not ${action_log}${suffix}" >/dev/stderr + echo-style --error3="The [$option_name] required utility was not ${action_log}${suffix}" >/dev/stderr fi return 0 } diff --git a/commands/setup-util-bash b/commands/setup-util-bash index c67994e62..d52e35a2d 100755 --- a/commands/setup-util-bash +++ b/commands/setup-util-bash @@ -128,10 +128,10 @@ function setup_util_bash() ( login_shell_version="$("$login_shell" -c -- 'echo $BASH_VERSION')" bash_shell_version="$("$bash_shell" -c -- 'echo $BASH_VERSION')" if test "$login_shell_version" != "$bash_shell_version"; then - echo-style --h2="Your login shell is an outdated version of bash." - echo-style --h2="You will now be prompted now to change it to a more modern shell." + echo-style --header2="Your login shell is an outdated version of bash." + echo-style --header2="You will now be prompted now to change it to a more modern shell." setup-shell - echo-style --h2="Close this terminal, open a new one, then run the command you ran again." + echo-style --header2="Close this terminal, open a new one, then run the command you ran again." return 0 fi fi diff --git a/commands/setup-util-flatpak b/commands/setup-util-flatpak index a9e1227a1..90945bf0d 100755 --- a/commands/setup-util-flatpak +++ b/commands/setup-util-flatpak @@ -46,7 +46,7 @@ function setup_util_flatpak() ( # if installed, then configure if command-exists flatpak; then # log start - echo-segment --h2='Configure flatpak' + echo-style --h2='Configure flatpak' # install sources sudo-helper -- flatpak remote-add --if-not-exists flathub \ @@ -54,7 +54,7 @@ function setup_util_flatpak() ( # ^ sudo with flatpak avoids gui sudo prompt # log success - echo-segment --g2='Configure flatpak' + echo-style --g2='Configure flatpak' fi ) diff --git a/commands/setup-util-node b/commands/setup-util-node index 61a4e1243..3f401d1b5 100755 --- a/commands/setup-util-node +++ b/commands/setup-util-node @@ -47,15 +47,15 @@ function setup_util_node() ( function clean_otherwise_wipe_nvm { # clean only what is necessary - echo-segment --h3='Clean Node.js versions and packages' + echo-style --h3='Clean Node.js versions and packages' if __clean_nvm; then - echo-segment --g3='Clean Node.js versions and packages' + echo-style --g3='Clean Node.js versions and packages' else # nvm buggered, clean it all - echo-segment --e3='Clean Node.js versions and packages' - echo-segment --h3='Clean Node.js Version Manager (NVM) instead' + echo-style --e3='Clean Node.js versions and packages' + echo-style --h3='Clean Node.js Version Manager (NVM) instead' wipe_nvm - echo-segment --g3='Clean Node.js Version Manager (NVM) instead' + echo-style --g3='Clean Node.js Version Manager (NVM) instead' fi } @@ -141,10 +141,10 @@ function setup_util_node() ( # https://nodejs.org/en/download/package-manager/ # @todo https://github.com/nodejs/unofficial-builds for riscv, but provides tars that include multiple directories - echo-segment --h2='Install Node.js via System' + echo-style --h2='Install Node.js via System' setup_system_node --install --force --quiet __print_line "Installed: $(node --version)" - echo-segment --g2='Install Node.js via System' + echo-style --g2='Install Node.js via System' # ===================================== # Clean NVM @@ -164,14 +164,14 @@ function setup_util_node() ( # > mode no such file or directory if ! is-alpine; then # install nvm - echo-segment --h2='Install Node.js Version Manager (NVM)' + echo-style --h2='Install Node.js Version Manager (NVM)' echo-style --dim "NVM_DIR=$NVM_DIR" eval_helper --quiet --no-wrap \ -- install_nvm - echo-segment --g2='Install Node.js Version Manager (NVM)' + echo-style --g2='Install Node.js Version Manager (NVM)' # nvm node - echo-segment --h2='Install Node.js via NVM' + echo-style --h2='Install Node.js via NVM' echo-style --dim='Installs active and LTS versions.' eval_helper --quiet --no-wrap \ -- install_nvm_node @@ -179,15 +179,15 @@ function setup_util_node() ( for version in "${versions[@]}"; do __print_line "Installed: v$version" done - echo-segment --g2='Install Node.js via NVM' + echo-style --g2='Install Node.js via NVM' fi # ===================================== # Upgrade npm - echo-segment --h3='Upgrade npm' + echo-style --h3='Upgrade npm' upgrade_system_or_nvm_npm - echo-segment --g3='Upgrade npm' + echo-style --g3='Upgrade npm' } function node_upgrade { install_node diff --git a/commands/setup-util-snap b/commands/setup-util-snap index c44760f42..dc7b471a4 100755 --- a/commands/setup-util-snap +++ b/commands/setup-util-snap @@ -38,7 +38,7 @@ function setup_util_snap() ( # if installed, configure if is-snap; then # log start - echo-segment --h2='Configure snap' + echo-style --h2='Configure snap' # ensure snap is discoverable to the system if test ! -d /snap; then @@ -59,7 +59,7 @@ function setup_util_snap() ( fi # log success - echo-segment --g2='Configure snap' + echo-style --g2='Configure snap' fi ) diff --git a/commands/setup-util-xcode b/commands/setup-util-xcode index 6a1fb019a..7630376f8 100755 --- a/commands/setup-util-xcode +++ b/commands/setup-util-xcode @@ -19,7 +19,7 @@ function setup_util_xcode() ( # log if test "$option_quiet" = 'no'; then - echo-segment --h1="Install Xcode" + echo-style --h1="Install Xcode" fi # check if xcode exists @@ -76,7 +76,7 @@ function setup_util_xcode() ( # log if test "$option_quiet" = 'no'; then - echo-segment --g1="Install Xcode" + echo-style --g1="Install Xcode" fi ) diff --git a/commands/setup-utils b/commands/setup-utils index bab4e238f..91dae45db 100755 --- a/commands/setup-utils +++ b/commands/setup-utils @@ -91,7 +91,7 @@ function setup_utils() ( # Action local item cmd - echo-segment --h1="Setup ${#option_utils[@]} utilities" + echo-style --h1="Setup ${#option_utils[@]} utilities" for item in "${option_utils[@]}"; do if test -n "$item"; then cmd="setup-util-${item}" @@ -99,7 +99,7 @@ function setup_utils() ( "$cmd" "${option_args[@]}" || : # don't fail everything if one fails else # can't use -EOF, as we want to print spacing - echo-style --e1="Unable to install [$item], as [$cmd] doesn't exist." $'\n' \ + echo-style --error1="Unable to install [$item], as [$cmd] doesn't exist." $'\n' \ $'\n' \ --red="You can create the missing command by running:" $'\n' \ $'\n' \ @@ -112,7 +112,7 @@ function setup_utils() ( fi fi done - echo-segment --g1="Setup ${#option_utils[@]} utilities" + echo-style --g1="Setup ${#option_utils[@]} utilities" ) # fire if invoked standalone diff --git a/commands/ssh-helper b/commands/ssh-helper index dd4af2ea0..b6593ef09 100755 --- a/commands/ssh-helper +++ b/commands/ssh-helper @@ -210,7 +210,7 @@ function ssh_helper() ( # http://apple.stackexchange.com/a/254619/15131 # https://stackoverflow.com/a/15578473/130638 # don't use $HOME as that isn't portable - echo-style --h2='SSH Configuration: .ssh/config' + echo-style --header2='SSH Configuration: .ssh/config' config-helper --file="$HOME/.ssh/config" -- \ --find='UserKnownHostsFile .+' --replace='UserKnownHostsFile ~/.ssh/known_hosts' \ --find='IgnoreUnknown .+' --replace='IgnoreUnknown UseKeychain,AddKeysToAgent,IdentitiesOnly' \ @@ -237,7 +237,7 @@ function ssh_helper() ( # SSH Keys if test "$option_configure" != 'no'; then - echo-style --h3='Add SSH Keys to SSH Agent' + echo-style --header3='Add SSH Keys to SSH Agent' if confirm --linger --negative --ppid=$$ -- 'Do you want to (re-)add your SSH keys to the SSH agent?'; then ssh_add fi @@ -254,7 +254,7 @@ function ssh_helper() ( # https://github.blog/2023-03-23-we-updated-our-rsa-ssh-host-key/ # log - echo-style --h3='Add GitHub Keys to Known Hosts' + echo-style --header3='Add GitHub Keys to Known Hosts' # ensure it exists, which it may not on new systems touch "$HOME/.ssh/known_hosts" diff --git a/commands/sudo-helper b/commands/sudo-helper index c7db19cc0..45e0eec2c 100755 --- a/commands/sudo-helper +++ b/commands/sudo-helper @@ -181,7 +181,7 @@ function sudo_helper() ( # [sudo --validate] doesn't work on multipass, so just use [true] as a no-op if ! sudo --non-interactive true &>/dev/null; then # password is required, let the user know what they are being prompted for - # [--code=*] better than [echo-element --openclose="$(echo-quote -- "${run[@]}" | echo-join ' ' --stdin)"] as that is too verbose + # [--code=*] better than [echo-style --element/="$(echo-quote -- "${run[@]}" | echo-join ' ' --stdin)"] as that is too verbose # use [--tty] to ensure the prompt is not hidden when otherwise hiding sudo output, such as in [command-working] # while it would be nice to clear lines, we cannot know how many lines to clear as they could require multiple attempts to enter the password # there would be a way of doing this with [tty.bash] however that is too complicated for this diff --git a/commands/until-success b/commands/until-success index cf04bca2f..fd5165a4e 100755 --- a/commands/until-success +++ b/commands/until-success @@ -68,14 +68,14 @@ function until_success() ( function attempt { local attempt_status attempt_output='' - echo-element --open="$title" + echo-style --element="$title" if test "$option_clear" = 'yes'; then eval_capture --statusvar=attempt_status --outputvar=attempt_output -- "$@" __print_line "$attempt_output" else eval_capture --statusvar=attempt_status -- "$@" fi - echo-element --close="$title" --status="$attempt_status" + echo-style --/element="$title" --status="$attempt_status" 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 diff --git a/config/styles.bash b/config/styles.bash index 08ddd3bac..42419ab22 100644 --- a/config/styles.bash +++ b/config/styles.bash @@ -4,94 +4,146 @@ # Used by `echo-style` -# colors which will be sought later # https://en.wikipedia.org/wiki/ANSI_escape_code#Colors # https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009 # https://mywiki.wooledge.org/BashFAQ/037 +####################################### +# ANSI STYLES ######################### + +# erasure +style__delete_line=$'\e[F\e[J' +style__erase_screen=$'\e[H\e[2J' +style__hide_cursor=$'\e[?25l' +style__show_cursor=$'\e[?25h' + +# modes +style__color_end__intensity=$'\e[22m' # +style__color_end__foreground=$'\e[39m' # +style__color_end__background=$'\e[49m' # +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters +# echo-style --bold=bold --dim=dim --italic=italic 'standard' --underline=underline --blink=blink --invert=invert --conceal=conceal --strike=strike --framed=framed --circled=circled --overlined=overlined standard +style__color__reset=$'\e[0m' # tput sgr0 +style__color__bold=$'\e[1m' # tput bold [supported: Terminal, VSCode, Alacritty, Hyper, Wave, Warp, iTerm2, Tabby, Kitty] [buggy support: Rio] [unsupported: cool-retro-term, Wez, Extratern, Contour] +style__color_end__bold="$style__color_end__intensity" +style__color__dim=$'\e[2m' # tput dim [supported: Terminal, VSCode, Alacritty, Hyper, Wave, Warp, iTerm2, Tabby, Wez, Contour, Kitty] [unsupported: cool-retro-term, Extraterm, Rio] +style__color_end__dim="$style__color_end__intensity" +style__color__italic=$'\e[3m' # [supported: VScode, Hyper] [colored support: Alacritty, Wave, iTerm2, Tabby, Wez, Extraterm, Contour, Kitty] [unsupported: Terminal, Warp, cool-retro-term, Rio] +style__color_end__italic=$'\e[23m' +style__color__underline=$'\e[4m' # tput sgr 0 1 [supported: Terminal, VSCode, Alacritty, Hyper, cool-retro-term, Wave, Warp, iTerm2, Tabby, Wez, Extraterm, Rio, Contour, Kitty] [unsupported: -] +style__color_end__underline=$'\e[24m' +style__color__double_underline=$'\e[21m' # [supported: Tabby] +style__color_end__double_underline=$'\e[24m' +style__color__blink=$'\e[5m' # tput blink [supported: Terminal, VSCode, Alacritty, Hyper, Contour] [fade-in-out support: Wez, cool-retro-term] [unsupported: Wave, Warp, iTerm2, Tabby, Extraterm, Rio, Kitty] +style__color_end__blink=$'\e[25m' +style__color__invert=$'\e[7m' # tput rev [supported: Terminal, VSCode, Alacritty, Hyper, cool-retro-arm, Wave, Warp, iTerm2, Tabby, Wez, Extraterm, Rio, Contour, Kitty] [unsupported: -] +style__color_end__invert=$'\e[27m' +style__color__conceal=$'\e[8m' # [supported: Terminal, VSCode, Alacritty, Hyper, iTerm2, Tabby, Wez, Rio, Contour] [unsupported: cool-retro-term, Wave, Warp, Extraterm, Kitty] +style__color_end__conceal=$'\e[28m' +style__color__strike=$'\e[9m' # [supported: VSCode, Alacritty, Hyper, Wave, Warp, iTerm2, Tabby, Wez, Extraterm, Rio, Contour, Kitty] [unsupported: cool-retro-term] +style__color_end__strike=$'\e[29m' +style__color__framed=$'\e[51m' # [frames each character: Contour] [unsupported: everything else] +style__color_end__framed=$'\e[54m' +style__color__circled=$'\e[52m' # [supported: none known] +style__color_end__circled="$style__color_end__framed" +style__color__overlined=$'\e[53m' # [supported: Tabby, Wez, Extratern, Contour] [unsupported: everything else] +style__color_end__overlined=$'\e[55m' + # foreground -foreground_black=$'\e[30m' # tput setaf 0 -foreground_red=$'\e[31m' # tput setaf 1 -foreground_green=$'\e[32m' # tput setaf 2 -foreground_yellow=$'\e[33m' # tput setaf 3 -foreground_blue=$'\e[34m' # tput setaf 4 -foreground_magenta=$'\e[35m' # tput setaf 5 -foreground_cyan=$'\e[36m' # tput setaf 6 -foreground_white=$'\e[37m' # tput setaf 7 -foreground_purple="$foreground_magenta" -foreground_gray="$foreground_white" -foreground_grey="$foreground_white" +style__color__foreground_black=$'\e[30m' # tput setaf 0 +style__color_end__foreground_black="$style__color_end__foreground" +style__color__foreground_red=$'\e[31m' # tput setaf 1 +style__color_end__foreground_red="$style__color_end__foreground" +style__color__foreground_green=$'\e[32m' # tput setaf 2 +style__color_end__foreground_green="$style__color_end__foreground" +style__color__foreground_yellow=$'\e[33m' # tput setaf 3 +style__color_end__foreground_yellow="$style__color_end__foreground" +style__color__foreground_blue=$'\e[34m' # tput setaf 4 +style__color_end__foreground_blue="$style__color_end__foreground" +style__color__foreground_magenta=$'\e[35m' # tput setaf 5 +style__color_end__foreground_magenta="$style__color_end__foreground" +style__color__foreground_cyan=$'\e[36m' # tput setaf 6 +style__color_end__foreground_cyan="$style__color_end__foreground" +style__color__foreground_white=$'\e[37m' # tput setaf 7 +style__color_end__foreground_white="$style__color_end__foreground" +style__color__foreground_purple="$style__color__foreground_magenta" +style__color_end__foreground_purple="$style__color_end__foreground" +style__color__foreground_gray="$style__color__foreground_white" +style__color_end__foreground_gray="$style__color_end__foreground" +style__color__foreground_grey="$style__color__foreground_white" +style__color_end__foreground_grey="$style__color_end__foreground" # foreground_intense -foreground_intense_black=$'\e[90m' # tput setaf 8 -foreground_intense_red=$'\e[91m' # tput setaf 9 -foreground_intense_green=$'\e[92m' # tput setaf 10 -foreground_intense_yellow=$'\e[93m' # tput setaf 11 -foreground_intense_blue=$'\e[94m' # tput setaf 12 -foreground_intense_magenta=$'\e[95m' # tput setaf 13 -foreground_intense_cyan=$'\e[96m' # tput setaf 14 -foreground_intense_white=$'\e[97m' # tput setaf 15 -foreground_intense_purple="$foreground_intense_magenta" -foreground_intense_gray="$foreground_intense_white" -foreground_intense_grey="$foreground_intense_white" +style__color__foreground_intense_black=$'\e[90m' # tput setaf 8 +style__color_end__foreground_intense_black="$style__color_end__foreground" +style__color__foreground_intense_red=$'\e[91m' # tput setaf 9 +style__color_end__foreground_intense_red="$style__color_end__foreground" +style__color__foreground_intense_green=$'\e[92m' # tput setaf 10 +style__color_end__foreground_intense_green="$style__color_end__foreground" +style__color__foreground_intense_yellow=$'\e[93m' # tput setaf 11 +style__color_end__foreground_intense_yellow="$style__color_end__foreground" +style__color__foreground_intense_blue=$'\e[94m' # tput setaf 12 +style__color_end__foreground_intense_blue="$style__color_end__foreground" +style__color__foreground_intense_magenta=$'\e[95m' # tput setaf 13 +style__color_end__foreground_intense_magenta="$style__color_end__foreground" +style__color__foreground_intense_cyan=$'\e[96m' # tput setaf 14 +style__color_end__foreground_intense_cyan="$style__color_end__foreground" +style__color__foreground_intense_white=$'\e[97m' # tput setaf 15 +style__color_end__foreground_intense_white="$style__color_end__foreground" +style__color__foreground_intense_purple="$style__color__foreground_intense_magenta" +style__color_end__foreground_intense_purple="$style__color_end__foreground" +style__color__foreground_intense_gray="$style__color__foreground_intense_white" +style__color_end__foreground_intense_gray="$style__color_end__foreground" +style__color__foreground_intense_grey="$style__color__foreground_intense_white" +style__color_end__foreground_intense_grey="$style__color_end__foreground" # background -background_black=$'\e[40m' # tput setab 0 -background_red=$'\e[41m' # tput setab 1 -background_green=$'\e[42m' # tput setab 2 -background_yellow=$'\e[43m' # tput setab 3 -background_blue=$'\e[44m' # tput setab 4 -background_magenta=$'\e[45m' # tput setab 5 -background_cyan=$'\e[46m' # tput setab 6 -background_white=$'\e[47m' # tput setab 7 -background_purple="$background_magenta" -background_gray="$background_white" -background_grey="$background_white" +style__color__background_black=$'\e[40m' # tput setab 0 +style__color_end__background_black="$style__color_end__background" +style__color__background_red=$'\e[41m' # tput setab 1 +style__color_end__background_red="$style__color_end__background" +style__color__background_green=$'\e[42m' # tput setab 2 +style__color_end__background_green="$style__color_end__background" +style__color__background_yellow=$'\e[43m' # tput setab 3 +style__color_end__background_yellow="$style__color_end__background" +style__color__background_blue=$'\e[44m' # tput setab 4 +style__color_end__background_blue="$style__color_end__background" +style__color__background_magenta=$'\e[45m' # tput setab 5 +style__color_end__background_magenta="$style__color_end__background" +style__color__background_cyan=$'\e[46m' # tput setab 6 +style__color_end__background_cyan="$style__color_end__background" +style__color__background_white=$'\e[47m' # tput setab 7 +style__color_end__background_white="$style__color_end__background" +style__color__background_purple="$style__color__background_magenta" +style__color_end__background_purple="$style__color_end__background" +style__color__background_gray="$style__color__background_white" +style__color_end__background_gray="$style__color_end__background" +style__color__background_grey="$style__color__background_white" +style__color_end__background_grey="$style__color_end__background" # background_intense -background_intense_black=$'\e[100m' # tput setab 8 -background_intense_red=$'\e[101m' # tput setab 9 -background_intense_green=$'\e[102m' # tput setab 10 -background_intense_yellow=$'\e[103m' # tput setab 11 -background_intense_blue=$'\e[104m' # tput setab 12 -background_intense_magenta=$'\e[105m' # tput setab 13 -background_intense_cyan=$'\e[106m' # tput setab 14 -background_intense_white=$'\e[107m' # tput setab 15 -background_intense_purple="$background_intense_magenta" -background_intense_gray="$background_intense_white" -background_intense_grey="$background_intense_white" - -# modes -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters -# echo-style --bold=bold --dim=dim --italic=italic 'standard' --underline=underline --blink=blink --invert=invert --conceal=conceal --strike=strike --framed=framed --circled=circled --overlined=overlined standard -reset=$'\e[0m' # tput sgr0 -bold=$'\e[1m' # tput bold [supported: Terminal, VSCode, Alacritty, Hyper, Wave, Warp, iTerm2, Tabby, Kitty] [buggy support: Rio] [unsupported: cool-retro-term, Wez, Extratern, Contour] -dim=$'\e[2m' # tput dim [supported: Terminal, VSCode, Alacritty, Hyper, Wave, Warp, iTerm2, Tabby, Wez, Contour, Kitty] [unsupported: cool-retro-term, Extraterm, Rio] -italic=$'\e[3m' # [supported: VScode, Hyper] [colored support: Alacritty, Wave, iTerm2, Tabby, Wez, Extraterm, Contour, Kitty] [unsupported: Terminal, Warp, cool-retro-term, Rio] -underline=$'\e[4m' # tput sgr 0 1 [supported: Terminal, VSCode, Alacritty, Hyper, cool-retro-term, Wave, Warp, iTerm2, Tabby, Wez, Extraterm, Rio, Contour, Kitty] [unsupported: -] -blink=$'\e[5m' # tput blink [supported: Terminal, VSCode, Alacritty, Hyper, Contour] [fade-in-out support: Wez, cool-retro-term] [unsupported: Wave, Warp, iTerm2, Tabby, Extraterm, Rio, Kitty] -invert=$'\e[7m' # tput rev [supported: Terminal, VSCode, Alacritty, Hyper, cool-retro-arm, Wave, Warp, iTerm2, Tabby, Wez, Extraterm, Rio, Contour, Kitty] [unsupported: -] -conceal=$'\e[8m' # [supported: Terminal, VSCode, Alacritty, Hyper, iTerm2, Tabby, Wez, Rio, Contour] [unsupported: cool-retro-term, Wave, Warp, Extraterm, Kitty] -strike=$'\e[9m' # [supported: VSCode, Alacritty, Hyper, Wave, Warp, iTerm2, Tabby, Wez, Extraterm, Rio, Contour, Kitty] [unsupported: cool-retro-term] -double_underline=$'\e[21m' # -disable_intensity=$'\e[22m' # -disable_bold="$disable_intensity" # -disable_dim="$disable_intensity" # -disable_italic=$'\e[23m' # -disable_underline=$'\e[24m' # -disable_blink=$'\e[25m' # -disable_invert=$'\e[27m' # -disable_conceal=$'\e[28m' # -reveal="$disable_conceal" # -disable_strike=$'\e[29m' # -disable_foreground=$'\e[39m' # -disable_background=$'\e[49m' # -framed=$'\e[51m' # [frames each character: Contour] [unsupported: everything else] -circled=$'\e[52m' # [supported: none known] -overlined=$'\e[53m' # [supported: Tabby, Wez, Extratern, Contour] [unsupported: everything else] -disable_framed=$'\e[54m' # -disable_circled="$disable_framed" # -disable_overlined=$'\e[55m' # +style__color__background_intense_black=$'\e[100m' # tput setab 8 +style__color_end__background_intense_black="$style__color_end__background" +style__color__background_intense_red=$'\e[101m' # tput setab 9 +style__color_end__background_intense_red="$style__color_end__background" +style__color__background_intense_green=$'\e[102m' # tput setab 10 +style__color_end__background_intense_green="$style__color_end__background" +style__color__background_intense_yellow=$'\e[103m' # tput setab 11 +style__color_end__background_intense_yellow="$style__color_end__background" +style__color__background_intense_blue=$'\e[104m' # tput setab 12 +style__color_end__background_intense_blue="$style__color_end__background" +style__color__background_intense_magenta=$'\e[105m' # tput setab 13 +style__color_end__background_intense_magenta="$style__color_end__background" +style__color__background_intense_cyan=$'\e[106m' # tput setab 14 +style__color_end__background_intense_cyan="$style__color_end__background" +style__color__background_intense_white=$'\e[107m' # tput setab 15 +style__color_end__background_intense_white="$style__color_end__background" +style__color__background_intense_purple="$style__color__background_intense_magenta" +style__color_end__background_intense_purple="$style__color_end__background" +style__color__background_intense_gray="$style__color__background_intense_white" +style__color_end__background_intense_gray="$style__color_end__background" +style__color__background_intense_grey="$style__color__background_intense_white" +style__color_end__background_intense_grey="$style__color_end__background" # If italics is not supported, swap it with something else... # Values of TERM_PROGRAM that are known to not support italics: @@ -99,59 +151,94 @@ disable_overlined=$'\e[55m' # # As italics support is rare, do the swap if not in a known terminal that supports italics.... if ! [[ ${TERM_PROGRAM-} =~ ^(Hyper|tmux|vscode)$ ]]; then # do not use underline, as it makes a mess, an underlined | or , or space is not pretty - # italic="$dim" - # disable_italic="$disable_dim" - italic="$foreground_intense_white" - disable_italic="$disable_foreground" + # style__color__italic="$style__color__dim" + # style__color_end__italic="$style__color_end__dim" + style__color__italic="$style__color__foreground_intense_white" + style__color_end__italic="$style__color_end__foreground" fi # modes that aren't implemented by operating systems # blink_fast=$'\e[6m' +####################################### +# CUSTOM STYLES ####################### + # styles -h1="${invert}" -e1="${background_red}${foreground_intense_white}" -g1="${background_intense_green}${foreground_black}" -n1="${background_intense_yellow}${foreground_black}" -h2="${bold}${underline}" -g2="${h2}${foreground_green}" -e2="${h2}${foreground_red}" -n2="${h2}${foreground_yellow}" -h3="${bold}" -g3="${h3}${foreground_green}" -e3="${h3}${foreground_red}" -n3="${h3}${foreground_yellow}" -header="${bold}${underline}" -error="${background_intense_red}${foreground_intense_white}" -success="${foreground_green}${bold}" -positive="${foreground_green}${bold}" -negative="${foreground_red}${bold}" -notice="${h2}${foreground_intense_yellow}" # on dark theme, this is your eyes that need help -warning="${e2}" -sudo="${foreground_intense_yellow}" -code="${dim}" -code_dim="${dim}${foreground_gray}" -code_notice="${dim}${foreground_intense_yellow}" # on dark theme, this is your eyes that need help +style__color__header="${style__color__bold}${style__color__underline}" +style__color_end__header="${style__color_end__intensity}${style__color_end__underline}" +style__color__header1="${style__color__invert}" +style__color_end__header1="${style__color_end__invert}" +style__color__header2="${style__color__bold}${style__color__underline}" +style__color_end__header2="${style__color_end__intensity}${style__color_end__underline}" +style__color__header3="${style__color__bold}" +style__color_end__header3="${style__color_end__intensity}" + +style__color__success="${style__color__foreground_green}${style__color__bold}" +style__color_end__success="${style__color_end__foreground}${style__color_end__intensity}" +style__color__positive="${style__color__foreground_green}${style__color__bold}" +style__color_end__positive="${style__color_end__foreground}${style__color_end__intensity}" +style__color__good1="${style__color__background_intense_green}${style__color__foreground_black}" +style__color_end__good1="${style__color_end__background}${style__color_end__foreground}" +style__color__good2="${style__color__bold}${style__color__underline}${style__color__foreground_green}" +style__color_end__good2="${style__color_end__intensity}${style__color_end__underline}${style__color_end__foreground}" +style__color__good3="${style__color__bold}${style__color__foreground_green}" +style__color_end__good3="${style__color_end__intensity}${style__color_end__foreground}" + +style__color__negative="${style__color__foreground_red}${style__color__bold}" +style__color_end__negative="${style__color_end__foreground}${style__color_end__intensity}" +style__color__error="${style__color__background_intense_red}${style__color__foreground_intense_white}" +style__color_end__error="${style__color_end__background}${style__color_end__foreground}" +style__color__error1="${style__color__background_red}${style__color__foreground_intense_white}" +style__color_end__error1="${style__color_end__background}${style__color_end__foreground}" +style__color__error2="${style__color__bold}${style__color__underline}${style__color__foreground_red}" +style__color_end__error2="${style__color_end__intensity}${style__color_end__underline}${style__color_end__foreground}" +style__color__error3="${style__color__bold}${style__color__foreground_red}" +style__color_end__error3="${style__color_end__intensity}${style__color_end__foreground}" + +style__color__notice="${style__color__bold}${style__color__underline}${style__color__foreground_intense_yellow}" # on dark theme, this is your eyes that need help +style__color_end__notice="${style__color_end__intensity}${style__color_end__underline}${style__color_end__foreground}" +style__color__warning="${style__color__bold}${style__color__underline}${style__color__foreground_yellow}" +style__color_end__warning="${style__color_end__intensity}${style__color_end__underline}${style__color_end__foreground}" +style__color__notice1="${style__color__background_intense_yellow}${style__color__foreground_black}" +style__color_end__notice1="${style__color_end__background}${style__color_end__foreground}" +style__color__notice2="${style__color__bold}${style__color__underline}${style__color__foreground_yellow}" +style__color_end__notice2="${style__color_end__intensity}${style__color_end__underline}${style__color_end__foreground}" +style__color__notice3="${style__color__bold}${style__color__foreground_yellow}" +style__color_end__notice3="${style__color_end__intensity}${style__color_end__foreground}" + +style__color__redacted="${style__color__background_black}${style__color__foreground_black}" # alternative to conceal, which respects color themes +style__color_end__redacted="${style__color_end__background}${style__color_end__foreground}" +style__color__sudo="${style__color__foreground_intense_yellow}" +style__color_end__sudo="${style__color_end__foreground}" +style__color__code="${style__color__dim}" +style__color_end__code="${style__color_end__intensity}" +style__color__code_dim="${style__color__dim}${style__color__foreground_gray}" +style__color_end__code_dim="${style__color_end__intensity}${style__color_end__foreground}" +style__color__code_notice="${style__color__dim}${style__color__foreground_intense_yellow}" # on dark theme, this is your eyes that need help +style__color_end__code_notice="${style__color_end__intensity}${style__color_end__foreground}" if test -n "${GITHUB_ACTIONS-}"; then - h1="${background_intense_white}${foreground_black}" - e1="${background_red}${foreground_black}" - error="${background_red}${foreground_black}" + style__color__header1="${style__color__background_intense_white}${style__color__foreground_black}" + style__color_end__header1="${style__color_end__background}${style__color_end__foreground}" + style__color__error1="${style__color__background_red}${style__color__foreground_black}" + style__color_end__error1="${style__color_end__background}${style__color_end__foreground}" + style__color__error="${style__color__background_red}${style__color__foreground_black}" + style__color_end__error="${style__color_end__background}${style__color_end__foreground}" elif test "$(get-terminal-theme || :)" = 'light'; then - # trim foreground_intense_yellow as it is unreadable on light theme - code_notice="${foreground_yellow}" - notice="${h2}${foreground_yellow}" - sudo="${foreground_yellow}" + # trim style__color__foreground_intense_yellow as it is unreadable on light theme + style__color__code_notice="${style__color__foreground_yellow}" + style__color_end__code_notice="${style__color_end__foreground}" + style__color__notice="${style__color__bold}${style__color__underline}${style__color__foreground_yellow}" + style__color_end__notice="${style__color_end__intensity}${style__color_end__underline}${style__color_end__foreground}" + style__color__sudo="${style__color__foreground_yellow}" + style__color_end__sudo="${style__color_end__foreground}" else # on dark theme on vscode - # background_intense_red forces black foreground, which black on red is unreadable, so adjust + # style__color__background_intense_red forces black foreground, which black on red is unreadable, so adjust if test "${TERM_PROGRAM-}" = vscode; then - error="${background_red}${foreground_intense_white}" + style__color__error="${style__color__background_red}${style__color__foreground_intense_white}" + style__color_end__error="${style__color_end__background}${style__color_end__foreground}" fi fi -# g1="${background_green}${intense_white}" - -# redacted, alternative to conceal, which respects color themes -redacted="${background_black}${foreground_black}" # don't use these in segments, as it prohibits alternative usage # instead, when things take a long time, @@ -161,41 +248,209 @@ redacted="${background_black}${foreground_black}" # ❌ # level 1 wrappers -h1_open="${reset}${h1}┌ ${reset}" -h1_close="${reset}${h1} ┐${reset}" -g1_open="${reset}${g1}└ ${reset}" -g1_close="${reset}${g1} ┘${reset}" -e1_open="${reset}${e1}└ ${reset}" -e1_close="${reset}${e1} ┘${reset}" -n1_open="${reset}${n1}└ ${reset}" -n1_close="${reset}${n1} ┘${reset}" +# hN = header level N +# gN = good level N (use to close a header element) +# eN = error level N (use to close a header element) +# nN = notice level N (use to close a header element) +style__nocolor__h1=$'\n┌ ' +style__nocolor_end__h1=' ┐' +style__color__h1=$'\n'"${style__color__header1}┌ " +style__color_end__h1=" ┐${style__color_end__header1}" + +style__nocolor__g1='└ ' +style__nocolor_end__g1=' ┘' +style__color__g1="${style__color__good1}└ " +style__color_end__g1=" ┘${style__color_end__good1}" + +style__nocolor__e1='└ ' +style__nocolor_end__e1=' ┘' +style__color__e1="${style__color__error1}└ " +style__color_end__e1=" ┘${style__color_end__error1}" + +style__nocolor__n1='└ ' +style__nocolor_end__n1=' ┘' +style__color__n1="${style__color__notice1}└ " +style__color_end__n1=" ┘${style__color_end__notice1}" # level 2 wrappers -h2_open="${reset}${bold}┌ ${reset}" -h2_close="${reset}${bold} ┐${reset}" -g2_open="${reset}${bold}${foreground_green}└ ${reset}" -g2_close="${reset}${bold}${foreground_green} ┘${reset}" -e2_open="${reset}${bold}${foreground_red}└ ${reset}" -e2_close="${reset}${bold}${foreground_red} ┘${reset}" -n2_open="${reset}${bold}${foreground_yellow}└ ${reset}" -n2_close="${reset}${bold}${foreground_yellow} ┘${reset}" +style__nocolor__h2='┌ ' +style__nocolor_end__h2=' ┐' +style__color__h2="${style__color__reset}${style__color__bold}┌ " +style__color_end__h2=" ┐${style__color__reset}" + +style__nocolor__g2='└ ' +style__nocolor_end__g2=' ┘' +style__color__g2="${style__color__reset}${style__color__bold}${style__color__foreground_green}└ " +style__color_end__g2=" ┘${style__color__reset}" + +style__nocolor__e2='└ ' +style__nocolor_end__e2=' ┘' +style__color__e2="${style__color__reset}${style__color__bold}${style__color__foreground_red}└ " +style__color_end__e2=" ┘${style__color__reset}" + +style__nocolor__n2='└ ' +style__nocolor_end__n2=' ┘' +style__color__n2="${style__color__reset}${style__color__bold}${style__color__foreground_yellow}└ " +style__color_end__n2=" ┘${style__color__reset}" # level 3 wrappers -h3_open="${reset}┌ ${reset}" -h3_close="${reset} ┐${reset}" -g3_open="${reset}${foreground_green}└ ${reset}" -g3_close="${reset}${foreground_green} ┘${reset}" -e3_open="${reset}${foreground_red}└ ${reset}" -e3_close="${reset}${foreground_red} ┘${reset}" -n3_open="${reset}${foreground_yellow}└ ${reset}" -n3_close="${reset}${foreground_yellow} ┘${reset}" - -# element wrappers -element_open="${reset}${dim}${bold}< ${reset}" -element_close="${reset}${dim}${bold} >${reset}" -element_slash_open="${reset}${dim}${bold}${reset}" - -# the resets allow these to work: -# echo-style --h1_open --h1='Setup Python' --h1_close $'\n' --g1_open --g1='Setup Python' --g1_close -# echo-style --element_slash_open --h3="this should not be dim" --element_slash_close "$status" +style__nocolor__h3='┌ ' +style__nocolor_end__h3=' ┐' +style__color__h3="${style__color__reset}┌ " +style__color_end__h3=" ┐${style__color__reset}" + +style__nocolor__g3='└ ' +style__nocolor_end__g3=' ┘' +style__color__g3="${style__color__reset}${style__color__foreground_green}└ " +style__color_end__g3=" ┘${style__color__reset}" + +style__nocolor__e3='└ ' +style__nocolor_end__e3=' ┘' +style__color__e3="${style__color__reset}${style__color__foreground_red}└ " +style__color_end__e3=" ┘${style__color__reset}" + +style__nocolor__n3='└ ' +style__nocolor_end__n3=' ┘' +style__color__n3="${style__color__reset}${style__color__foreground_yellow}└ " +style__color_end__n3=" ┘${style__color__reset}" + +# element +style__nocolor__element='< ' +style__nocolor_end__element=' >' +style__color__element="${style__color__dim}${style__color__bold}< ${style__color_end__intensity}" +style__color_end__element="${style__color__dim}${style__color__bold} >${style__color_end__intensity}" + +style__nocolor__slash_element='' +style__color__slash_element="${style__color__dim}${style__color__bold}${style__color_end__intensity}" + +style__nocolor__element_slash='< ' +style__nocolor_end__element_slash=' />' +style__color__element_slash="${style__color__dim}${style__color__bold}< ${style__color_end__intensity}" +style__color_end__element_slash="${style__color__dim}${style__color__bold} />${style__color_end__intensity}" + +# the style__color__resets allow these to work: +# echo-style --h1_begin --h1='Setup Python' --h1_end $'\n' --g1_begin --g1='Setup Python' --g1_end +# echo-style --element_slash_begin --h3="this should not be dim" --element_slash_end "$status" +# echo-style a --h1 --element c --red=d e + +# choose +# one hollow circle: ⚬ ○ ◯ ❍ +# two hollow circles: ◎ ⦾ ⊚ +# one hollow, one full: ☉ ⦿ ◉ +# one full: ● +# ▣ ▢ □ ⊡ +# ☑ ☒ ⌧ +# ✓ ✔ ✖ ✗ ✘ +# +# conclusions for cursor: +# doesn't space correctly in Terminal: ⸻ +# too small: → ☞ ➡ +# too unclear: ► +# gets turned into an emoji: ➡️ +# other options: ▶▷▸▹⏵⯈, '▶ ', ' ⏵ ', '‒⏵ ', '‒▶ ' + +# [ 5 above: 1 selected, 3 preferences] +# ... 5 above: 1 selected, 3 preferences ... +# └┘┌┐ 5 above: 1 selected, 3 preferences ... +# └ 5 above, 1 selected, 3 preferences ┘ +# ┌ 5 above | 1 selected | 3 preferences ┐ +# … +# [ no above ] +### +# ┌ BELOW: 376 below ∙ 45 selected ∙ 8 unselected defaults ┐ +# .. +# ├ ABOVE: 5 items ∙ 22 selected ┤ +# ├ SHOWN: 30 items ∙ 24 selected ∙ 8 unselected defaults ┤ +# ... +# ├ BELOW: 283 items ┤ +# ... +# └ ABOVE: 376 below ∙ 45 selected ∙ 8 unselected defaults ┘ +# ⏺ = too big +# ∶ +# ⌜ ⌝ ⌞ ⌟ +# ⌌ ⌍ ⌎ ⌏ +# ╭ ╮ ╯ ╰ + +# lines +style__icon_multi_selected='▣ ' +style__icon_multi_default='⊡ ' +style__icon_multi_active='⊡ ' +style__icon_multi_standard='□ ' +style__icon_single_selected='⦿ ' # only used in confirmation and linger +style__icon_single_default='⦾ ' +style__icon_single_active_required='◉ ' +style__icon_single_active_optional='⦿ ' +style__icon_single_standard='○ ' +style__color__result_line="$style__color__dim" +style__color_end__result_line="$style__color_end__intensity" +style__color__active_line="$style__color__invert" +style__color_end__active_line="$style__color_end__invert" +style__color__selected_line="$style__color__foreground_intense_green" +style__color_end__selected_line="$style__color_end__foreground" +style__color__default_line="$style__color__foreground_intense_yellow" +style__color_end__default_line="$style__color_end__foreground" +style__color__empty_line="$style__color__foreground_magenta" +style__color_end__empty_line="$style__color_end__foreground" +style__color__inactive_line='' +style__color_end__inactive_line='' + +# spacers +style__legend_legend_spacer=' ' +style__legend_key_spacer=' ' +style__key_key_spacer=' ' +style__indent_bar=' ' +style__indent_active='⏵ ' +style__indent_inactive=' ' +style__nocolor__count_spacer=' ∙ ' +style__color__count_spacer=" ${style__color__foreground_intense_black}∙${style__color_end__foreground} " + +# legend +style__color__legend="$style__color__dim" # dim is better than white, nice separation +style__color_end__legend="$style__color_end__intensity" +style__color__key="${style__color__foreground_black}${style__color__background_white} " +style__color_end__key=" ${style__color_end__foreground}${style__color_end__background}" +style__nocolor__key='[' +style__nocolor_end__key=']' + +# paging counts +style__color__count_more="$style__color__foreground_white" +style__color_end__count_more="$style__color_end__foreground" +style__color__count_selected="$style__color__foreground_green" +style__color_end__count_selected="$style__color_end__foreground" +style__color__count_default="$style__color__foreground_yellow" +style__color_end__count_default="$style__color_end__foreground" +style__color__count_empty="$style__color__foreground_magenta" +style__color_end__count_empty="$style__color_end__foreground" + +# paging headers +style__nocolor__bar_top='┌ ' +style__nocolor_end__bar_top=' ┐' +style__nocolor__bar_middle='├ ' +style__nocolor_end__bar_middle=' ┤' +style__nocolor__bar_bottom='└ ' +style__nocolor_end__bar_bottom=' ┘' +style__color__bar_top="${style__color__foreground_intense_black}┌${style__color_end__foreground} " +style__color_end__bar_top=" ${style__color__foreground_intense_black}┐${style__color_end__foreground}" +style__color__bar_middle="${style__color__foreground_intense_black}├${style__color_end__foreground} " +style__color_end__bar_middle=" ${style__color__foreground_intense_black}┤${style__color_end__foreground}" +style__color__bar_bottom="${style__color__foreground_intense_black}└${style__color_end__foreground} " +style__color_end__bar_bottom=" ${style__color__foreground_intense_black}┘${style__color_end__foreground}" + +# adjustments +if test "$(get-terminal-theme || :)" = 'light'; then + # counts + style__color__count_more="$style__color__foreground_intense_black" + style__color_end__count_more="$style__color_end__foreground" + # keys + style__color__legend="$style__color__foreground_intense_black" + style__color_end__legend="$style__color_end__foreground" + style__color__key="${style__background_intense_white} " + style__color_end__key="$style__color_end__background" + # lines + style__color__selected_line="$style__color__foreground_green" + style__color_end__selected_line="$style__color_end__foreground" + style__color__default_line="$style__color__foreground_yellow" + style__color_end__default_line="$style__color_end__foreground" +fi diff --git a/docs/scripting/styling.md b/docs/scripting/styling.md index a6f32b628..02b1a4b77 100644 --- a/docs/scripting/styling.md +++ b/docs/scripting/styling.md @@ -18,30 +18,30 @@ echo-style \ For complete details, refer to `echo-style --help`. -## [echo-segment](https://github.com/bevry/dorothy/blob/master/commands/echo-segment) +## [echo-style](https://github.com/bevry/dorothy/blob/master/commands/echo-style) -Use `echo-segment` to segment your output, such that sections of output are clearly visible, with their result clearly identified. +Use `echo-style` to segment your output, such that sections of output are clearly visible, with their result clearly identified. ```bash -echo-segment --h1='Birth of the human spirit' +echo-style --h1='Birth of the human spirit' echo-style --success='Woohoo, the human spirit was born!' ' ' --notice='Although... it was at the cost of the eviction, or rather the liberation, from eden.' -echo-segment --g1='Birth of the human spirit' -echo-segment --h1='Meaning of life calculator' +echo-style --g1='Birth of the human spirit' +echo-style --h1='Meaning of life calculator' echo-style --error='Uh, oh, 42 was rejected by the people.' -echo-segment --e1='Meaning of life calculator' +echo-style --e1='Meaning of life calculator' ``` -For complete details, refer to `echo-segment --help`. +For complete details, refer to `echo-style --help`. -## [echo-element](https://github.com/bevry/dorothy/blob/master/commands/echo-element) +## [echo-style](https://github.com/bevry/dorothy/blob/master/commands/echo-style) -Use `echo-element` as an alternative to `echo-segment`, when you wish to output a segment for say a command output, or a file's contents. +Use `echo-style` as an alternative to `echo-style`, when you wish to output a segment for say a command output, or a file's contents. ```bash file="$(fs-temp --file)" # self closing element -echo-element --openclose="$file" --status=2 +echo-style --element/="$file" --status=2 # write the file data cat <<-EOF > "$file" @@ -49,18 +49,18 @@ Lorem ipsum. EOF # open the element -echo-element --open="$file" +echo-style --element="$file" # output its contents echo-style --code="$(echo-trim-padding --stdin <"$file")" # close the element -echo-element --close="$file" +echo-style --/element="$file" # note that this example is contrived, # when outputting file content, use: echo-file -- "$file" ``` -For complete details, refer to `echo-element --help`. +For complete details, refer to `echo-style --help`. ## [echo-quote](https://github.com/bevry/dorothy/blob/master/commands/echo-quote)