Skip to content

Commit

Permalink
echo-style: merge echo-element, echo-segment
Browse files Browse the repository at this point in the history
changes:
- deprecated `echo-element` and `echo-segment`, as they are now supported by `echo-style`
- `echo-style` and `styles.bash` updated for begin/end and color/nocolor styles
- `echo-style` updated to do the minimal writes for performance and simplicity
- `styles.bash` now has the `choose` styles, so `choose` theme can be customised by the user
- `choose` fixed and styled no selection / no items

/close #232
/ref #231 #188
  • Loading branch information
balupton committed Jul 1, 2024
1 parent e0670ed commit 2982177
Show file tree
Hide file tree
Showing 84 changed files with 1,453 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions commands.beta/eject-all
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ 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...')" \
--success="$(echo-style --success='Ejected.')" \
--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
Expand Down
14 changes: 7 additions & 7 deletions commands.beta/itunes-owners
Original file line number Diff line number Diff line change
Expand Up @@ -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='<string>file://(.+)</string>' --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
Expand Down Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions commands.beta/macos-state
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -283,7 +283,7 @@ function macos_state() (
else
echo-style --dim="Skipped..."
fi
echo-segment --g1 "$title"
echo-style --g1 "$title"
}

# ===============
Expand Down
4 changes: 2 additions & 2 deletions commands.beta/setup-server
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions commands/ask
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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_() (
Expand Down
Loading

0 comments on commit 2982177

Please sign in to comment.