mirror of
https://github.com/mjsarfatti/beddu.git
synced 2025-06-27 01:18:01 +02:00
Properly source modules
This commit is contained in:
parent
cdbc191d7b
commit
cb53800a20
15 changed files with 114 additions and 397 deletions
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# @private
|
||||
|
||||
[[ $BEDDU_SYMBOLS_LOADED ]] && return
|
||||
readonly BEDDU_SYMBOLS_LOADED=true
|
||||
|
||||
readonly _q='?'
|
||||
readonly _a='❯'
|
||||
readonly _o='◌'
|
||||
|
@ -9,5 +12,4 @@ readonly _mark='✓'
|
|||
readonly _warn='!'
|
||||
readonly _cross='✗'
|
||||
readonly _spinner='⣷⣯⣟⡿⢿⣻⣽⣾' # See for alternatives: https://antofthy.gitlab.io/info/ascii/Spinners.txt
|
||||
|
||||
export _q _a _o _O _mark _warn _cross _spinner
|
||||
readonly _spinner_frame_duration=0.1
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# movements.sh - Cursor helper functions
|
||||
|
||||
[[ $BEDDU_MOVEMENTS_LOADED ]] && return
|
||||
readonly BEDDU_MOVEMENTS_LOADED=true
|
||||
|
||||
# Move cursor up one line
|
||||
up() {
|
||||
printf "\033[A"
|
||||
|
@ -45,6 +48,3 @@ show_cursor() {
|
|||
hide_cursor() {
|
||||
printf "\033[?25l"
|
||||
}
|
||||
|
||||
# Export the functions so they are available to subshells
|
||||
export -f up down bol eol cl line show_cursor hide_cursor
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
# pen.sh - Print pretty text
|
||||
|
||||
# @depends on:
|
||||
# - _symbols.sh
|
||||
[[ $BEDDU_PEN_LOADED ]] && return
|
||||
readonly BEDDU_PEN_LOADED=true
|
||||
|
||||
# Print text with ANSI color codes and text formatting
|
||||
#
|
||||
|
@ -57,6 +57,3 @@ pen() {
|
|||
|
||||
printf "%b%s%b%b" "${format_code}" "${text}" "${reset_code}" "${new_line}"
|
||||
}
|
||||
|
||||
# Export the pen function so it's available to subshells
|
||||
export -f pen
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# run.sh - Execute commands with output/error capture
|
||||
|
||||
[[ $BEDDU_RUN_LOADED ]] && return
|
||||
readonly BEDDU_RUN_LOADED=true
|
||||
|
||||
# Execute a command with stdout and stderr capture capabilities
|
||||
#
|
||||
# Usage:
|
||||
|
@ -54,6 +57,3 @@ run() {
|
|||
rm -f "${stdout_file}" "${stderr_file}"
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Export the run function so it's available to subshells
|
||||
export -f run
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# check.sh - Print a success message
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - movements.sh
|
||||
# - _symbols.sh
|
||||
[[ $BEDDU_CHECK_LOADED ]] && return
|
||||
readonly BEDDU_CHECK_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
source "$SCRIPT_DIR/spin.sh"
|
||||
|
||||
# Print a checkmark with a message, and stop and replace the
|
||||
# spinner if it's running (relies on the spinner being the last
|
||||
|
@ -31,6 +36,3 @@ check() {
|
|||
pen -n green "${_mark:-✓} "
|
||||
pen "$@"
|
||||
}
|
||||
|
||||
# Export the check function so it can be used in other scripts
|
||||
export -f check
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# repen.sh - Overwrite the previous line with new text
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - movements.sh
|
||||
[[ $BEDDU_REPEN_LOADED ]] && return
|
||||
readonly BEDDU_REPEN_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
|
||||
# Move up one line, move to the beginning, clear the line, and print the text.
|
||||
#
|
||||
|
@ -20,6 +24,3 @@ repen() {
|
|||
upclear
|
||||
pen "$@"
|
||||
}
|
||||
|
||||
# Export the repen function so it can be used in other scripts
|
||||
export -f repen
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# spin.sh - Print a spinner with a message
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - movements.sh
|
||||
# - _symbols.sh
|
||||
[[ $BEDDU_SPIN_LOADED ]] && return
|
||||
readonly BEDDU_SPIN_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
|
||||
# Make sure the cursor is shown and the spinner stopped if the script exits abnormally
|
||||
trap spop EXIT INT TERM
|
||||
|
||||
# Module state variables
|
||||
_spinner_frame_duration=0.1
|
||||
_spinner_pid=""
|
||||
_frame_duration="${_spinner_frame_duration:-0.1}"
|
||||
|
||||
# Print a message with a spinner at the beginning
|
||||
#
|
||||
|
@ -30,7 +34,7 @@ _spinner_pid=""
|
|||
# check "Dependancies installed."
|
||||
spin() {
|
||||
local message=("$@")
|
||||
_spinner="${_spinner:-⣷⣯⣟⡿⢿⣻⣽⣾}"
|
||||
local spinner="${_spinner:-⣷⣯⣟⡿⢿⣻⣽⣾}"
|
||||
|
||||
# If there is already a spinner running, stop it
|
||||
if spinning; then
|
||||
|
@ -45,17 +49,17 @@ spin() {
|
|||
trap "show_cursor; exit 0" USR1
|
||||
|
||||
# Print the first frame of the spinner
|
||||
pen -n cyan "${_spinner:0:1} "
|
||||
pen -n cyan "${spinner:0:1} "
|
||||
pen "${message[@]}"
|
||||
|
||||
while true; do
|
||||
for ((i = 0; i < ${#_spinner}; i++)); do
|
||||
frame="${_spinner:$i:1}"
|
||||
for ((i = 0; i < ${#spinner}; i++)); do
|
||||
frame="${spinner:$i:1}"
|
||||
up
|
||||
bol
|
||||
pen -n cyan "${frame} "
|
||||
pen "${message[@]}"
|
||||
sleep $_spinner_frame_duration
|
||||
sleep "$_frame_duration"
|
||||
done
|
||||
done
|
||||
) &
|
||||
|
@ -73,7 +77,7 @@ spop() {
|
|||
kill -USR1 "${_spinner_pid}" 2>/dev/null
|
||||
|
||||
# Wait briefly for cleanup
|
||||
sleep $_spinner_frame_duration
|
||||
sleep "$_frame_duration"
|
||||
|
||||
# Ensure it's really gone
|
||||
if ps -p "${_spinner_pid}" >/dev/null 2>&1; then
|
||||
|
@ -92,6 +96,3 @@ spop() {
|
|||
spinning() {
|
||||
[[ -n "${_spinner_pid}" ]]
|
||||
}
|
||||
|
||||
# Export the functions so they are available to subshells
|
||||
export -f spin spop spinning
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# throw.sh - Print an throw message
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - movements.sh
|
||||
# - _symbols.sh
|
||||
[[ $BEDDU_THROW_LOADED ]] && return
|
||||
readonly BEDDU_THROW_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
source "$SCRIPT_DIR/spin.sh"
|
||||
|
||||
# Print an throwmark with a message, and stop and replace the
|
||||
# spinner if it's running (relies on the spinner being the last
|
||||
|
@ -31,6 +36,3 @@ throw() {
|
|||
pen -n red "${_cross:-✗} "
|
||||
pen "$@"
|
||||
}
|
||||
|
||||
# Export the throw function so it can be used in other scripts
|
||||
export -f throw
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# warn.sh - Print a warning message
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - movements.sh
|
||||
# - _symbols.sh
|
||||
[[ $BEDDU_WARN_LOADED ]] && return
|
||||
readonly BEDDU_WARN_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
source "$SCRIPT_DIR/spin.sh"
|
||||
|
||||
# Print a "!" with a message, and stop and replace the
|
||||
# spinner if it's running (relies on the spinner being
|
||||
|
@ -31,6 +36,3 @@ warn() {
|
|||
pen -n yellow bold italic "${_warn:-!} "
|
||||
pen italic "$@"
|
||||
}
|
||||
|
||||
# Export the warn function so it can be used in other scripts
|
||||
export -f warn
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# ask.sh - Get free text input from the user
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - _symbols.sh
|
||||
# - cursor.sh
|
||||
[[ $BEDDU_ASK_LOADED ]] && return
|
||||
readonly BEDDU_ASK_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
source "$SCRIPT_DIR/../02.ui/warn.sh"
|
||||
|
||||
# Ask a question and get a free text answer from the user
|
||||
#
|
||||
|
@ -42,6 +47,3 @@ ask() {
|
|||
# shellcheck disable=SC2034
|
||||
outvar="$answer"
|
||||
}
|
||||
|
||||
# Export the ask function so it's available to subshells
|
||||
export -f ask
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# choose.sh - Choose from a menu of options
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - _symbols.sh
|
||||
# - cursor.sh
|
||||
[[ $BEDDU_CHOOSE_LOADED ]] && return
|
||||
readonly BEDDU_CHOOSE_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
|
||||
# Print an interactive menu of options and return the selected option
|
||||
#
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
# confirm.sh - Read a yes/no confirmation from the user
|
||||
|
||||
# @depends on:
|
||||
# - pen.sh
|
||||
# - _symbols.sh
|
||||
# - movements.sh
|
||||
[[ $BEDDU_CONFIRM_LOADED ]] && return
|
||||
readonly BEDDU_CONFIRM_LOADED=true
|
||||
|
||||
SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
source "$SCRIPT_DIR/../00.utils/_symbols.sh"
|
||||
source "$SCRIPT_DIR/../00.utils/movements.sh"
|
||||
source "$SCRIPT_DIR/../01.core/pen.sh"
|
||||
source "$SCRIPT_DIR/../02.ui/warn.sh"
|
||||
|
||||
# Ask a question and get a yes/no answer from the user
|
||||
#
|
||||
|
@ -74,6 +79,3 @@ confirm() {
|
|||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Export the confirm function so it's available to subshells
|
||||
export -f confirm
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue