ansi colors
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
code=118
|
||||
failure_type='SUBSHELL TERM'
|
||||
failure_payload='blabla'
|
||||
stack_sources=('file.bash' './lib/utility.bash' 'file.bash')
|
||||
stack_lines=(18 56 12)
|
||||
stack_functions=('f2' 'f1' '<main>')
|
||||
|
||||
# function ansi_block_continuation {
|
||||
# tput sc
|
||||
# tput cuu 1
|
||||
# BG=RED FG=BLACK style_ansi "\t╦"
|
||||
# tput rc
|
||||
# FG=RED style_ansi "\t║\n"
|
||||
# }
|
||||
|
||||
function ansi_block_error {
|
||||
BG=RED
|
||||
FG=BLACK
|
||||
PADDING=2
|
||||
|
||||
local content detail exit_code
|
||||
|
||||
content=$(style_ansi "$1")
|
||||
content=$(style_padding "$content")
|
||||
detail=$(BG=BLACK style_padding "$2")
|
||||
exit_code=$(FG=CYAN style_ansi " $3")
|
||||
BLOCK_CONTINUATION_COL=5 style_block "$content\t$detail$exit_code"
|
||||
ansi_reset
|
||||
FG=RED style_ansi " ║"
|
||||
echo
|
||||
}
|
||||
|
||||
function ansi_traces {
|
||||
local optional location sources lines functions
|
||||
declare -n sources=$1
|
||||
declare -n lines=$2
|
||||
declare -n functions=$3
|
||||
optional=false
|
||||
for i in "${!sources[@]}"; do
|
||||
FG=RED style_ansi " ╟─⟶"
|
||||
location=$(printf "%40s" "${sources[$i]}:${lines[$i]}")
|
||||
is_true "$optional" &&
|
||||
location=$(FG=GRAY STYLE=ITALIC style_ansi "$location") ||
|
||||
location=$(STYLE=ITALIC style_ansi "$location")
|
||||
builtin echo "${location} ${functions[$i]}"
|
||||
optional=true
|
||||
done
|
||||
}
|
||||
|
||||
function show_error {
|
||||
>&2 printf '\r'
|
||||
>&2 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||
>&2 ansi_traces stack_sources stack_lines stack_functions
|
||||
}
|
||||
|
||||
function echo_return {
|
||||
echo TEXT &&
|
||||
return 11
|
||||
return 1
|
||||
}
|
||||
|
||||
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||
|
||||
echo START
|
||||
|
||||
if echo_return; then
|
||||
echo YOUPI
|
||||
else
|
||||
echo ERROR
|
||||
fi
|
||||
|
||||
if echo_return; then
|
||||
echo YOUPI
|
||||
else
|
||||
echo ERROR
|
||||
fi
|
||||
# echo -n "standard flow:" && show_error
|
||||
# echo -n "starting subshell: $(show_error)"
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
PREFIX_NESTED="__nested__"
|
||||
INSPECT_SIMPLE='-> '
|
||||
INSPECT_NESTED='=> '
|
||||
INSPECT_END='~~~~'
|
||||
|
||||
function array_new {
|
||||
ref_name="$1"
|
||||
shift
|
||||
|
||||
[[ ${1:-} == -- ]] && shift
|
||||
[[ -v nested_count ]] && ((nested_count++)) || nested_count=1
|
||||
nested_name="${PREFIX_NESTED}$nested_count"
|
||||
declare -ga "$nested_name"
|
||||
declare -gn "$ref_name"="$nested_name"
|
||||
local -n internal="$nested_name"
|
||||
internal+=("$@")
|
||||
}
|
||||
|
||||
function array_inspect {
|
||||
local ref prefix i
|
||||
declare -n ref="$1"
|
||||
prefix="${2:-}"
|
||||
echo "${prefix}array '$1' contains ${#ref[@]} elements"
|
||||
for i in "${ref[@]}"; do
|
||||
if [[ -R $i ]]; then
|
||||
array_inspect "$i" "${prefix}${INSPECT_NESTED}"
|
||||
else
|
||||
echo "${prefix}${INSPECT_SIMPLE}${i}"
|
||||
fi
|
||||
done
|
||||
echo "${prefix}${INSPECT_END}"
|
||||
}
|
||||
|
||||
# initialization
|
||||
array_new mine0
|
||||
array_new mine1 -- 'Albert Dupontel' 20
|
||||
array_new mine2 -- 'Bob Sinclar' 24
|
||||
array_new mine3 -- 'Conrad Ademayor' 68 true
|
||||
array_new nested -- mine1 mine2 mine3
|
||||
array_inspect nested
|
||||
|
||||
# change values
|
||||
mine1[1]=$((mine1[1] - 2))
|
||||
mine2[2]=false
|
||||
mine3+=('UK')
|
||||
array_inspect nested
|
||||
|
||||
# nested twice
|
||||
declare -n other="${nested[1]:?}" # ':?' fix shellcheck issue
|
||||
array_inspect other
|
||||
array_new mine4 'Darryl' 30
|
||||
other+=(mine4)
|
||||
array_inspect nested
|
||||
|
||||
# CAN'T PREVENT LOOP!
|
||||
# other+=(nested)
|
||||
# array_inspect nested
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env miaou-bash
|
||||
|
||||
function write_text {
|
||||
for ((i = 0; i < 10000; i++)); do echo "this is plain text #$i"; done
|
||||
}
|
||||
|
||||
{
|
||||
echo A
|
||||
echo B
|
||||
}
|
||||
|
||||
rm -f _stdout
|
||||
time write_text >_stdout
|
||||
wc -l _stdout
|
||||
|
||||
echo -------
|
||||
rm _stdout
|
||||
time {
|
||||
write_text | tee /tmp/out.$$
|
||||
last_line=$(tail -n1 /tmp/out.$$)
|
||||
rm -f /tmp/out.$$
|
||||
} >_stdout
|
||||
wc -l _stdout
|
||||
|
||||
echo -------
|
||||
echo "last_line = $last_line"
|
||||
Reference in New Issue
Block a user