refact with bes-color dependency
This commit is contained in:
parent
84df431633
commit
6269f31733
5
bes.ini
5
bes.ini
|
@ -1,10 +1,13 @@
|
|||
[project]
|
||||
vendor = bes
|
||||
name = echo
|
||||
version = 1.1
|
||||
version = 1.2
|
||||
license = "GNU GPL v3"
|
||||
author = a-Sansara
|
||||
type = library
|
||||
homepage = "https://git.pluie.org/meta-tech/bes-echo"
|
||||
description = "bash bes display utility library"
|
||||
keywords = "bash, bes"
|
||||
|
||||
[require]
|
||||
bes.color = 1.1
|
||||
|
|
128
src/echo.sh
128
src/echo.sh
|
@ -1,4 +1,3 @@
|
|||
#!/bin/bash
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# @author a-Sansara - https://git.pluie.org/meta-tech/bes-echo
|
||||
|
@ -9,80 +8,49 @@
|
|||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.boot ()
|
||||
{
|
||||
BES_TERM_WIDTH=${BES_TERM_WIDTH:-105}
|
||||
BES_NOCOLOR=${BES_NOCOLOR:-0}
|
||||
|
||||
if [ "$BES_NOCOLOR" -eq 0 ]; then
|
||||
Cok="\033[0;38;5;43m"; Cko="\033[0;38;5;217m"
|
||||
Coff="\033[m"; Ctitle="\033[1;48;5;24;1;38;5;15m"
|
||||
Cdone="\033[1;48;5;36;1;38;5;15m"; Cfail="\033[1;48;5;196;1;38;5;15m"
|
||||
Cspe="\033[1;38;5;223m"; Citem="\033[1;38;5;214m"
|
||||
Cval="\033[1;38;5;215m"; Cusa="\033[1;38;5;214m"
|
||||
Cbra="\033[1;38;5;203m"; Crepo="\033[1;38;5;223m"
|
||||
Cmeta="\033[1;38;5;30m"; Ctext="\033[1;38;5;30m"
|
||||
Copt="\033[1;38;5;81m"; Csep="\033[1;38;5;241m"
|
||||
Cerr="\033[1;38;5;196m"; Ccom="\033[0;38;5;139m"
|
||||
Csection="\033[1;38;5;97m"; Caction="\033[0;38;5;37m"
|
||||
fi
|
||||
BES_TERM_WIDTH=${COLUMNS:-130}
|
||||
BES_TERM_WIDTH=$(($BES_TERM_WIDTH - 20))
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo ()
|
||||
function echo.msg ()
|
||||
{
|
||||
local msg=${1:-''}
|
||||
local isAction=${2:-'0'}
|
||||
local symbol=${3:-' *'}
|
||||
if [ ! "$BES_NOCOLOR" = 1 ]; then
|
||||
local c=" "
|
||||
if [ -z "$isAction" ] || [ "$isAction" = 1 ]; then
|
||||
c=$Caction
|
||||
fi
|
||||
if [ ! "$isAction" = 0 ]; then
|
||||
c=" $Citem$symbol $c"
|
||||
fi
|
||||
echo -e " $c$msg$Coff"
|
||||
else
|
||||
if [ ! "$isAction" = 0 ]; then
|
||||
msg=" $symbol $msg"
|
||||
fi
|
||||
echo -e "$msg"
|
||||
fi
|
||||
local c=${2:-}
|
||||
local m=${1:-}
|
||||
echo -e " $c$m$Coff"
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.action ()
|
||||
function echo.state ()
|
||||
{
|
||||
bes.echo "$1" 1
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.title ()
|
||||
{
|
||||
echo
|
||||
bes.echo " ${Citem}☪ ${Csection}$1 ${Cspe}$2${Coff}"
|
||||
echo
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.keyval ()
|
||||
{
|
||||
local c=': '
|
||||
if [ ! "$BES_NOCOLOR" = 1 ]; then
|
||||
c="$Citem: ${Cval}"
|
||||
fi
|
||||
local len="%-15s "
|
||||
# printf "%s %s [UP]\n" $PROC_NAME "${line:${#PROC_NAME}}"
|
||||
bes.echo "$(printf $len $1) $c$2 " 1 " "
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.state ()
|
||||
{
|
||||
local len=8
|
||||
printf "%0.s " $(seq 1 $(($BES_TERM_WIDTH-${len})))
|
||||
local len=14
|
||||
echo -en " $Csep"
|
||||
printf "%0.s-" $(seq 1 $(($BES_TERM_WIDTH-${len})))
|
||||
if [ "$1" = 0 ]; then
|
||||
echo -e "${Cdone} OK ${Coff}"
|
||||
echo -e "$Coff $Cdone OK $Coff\n"
|
||||
else
|
||||
echo -e "${Cfail} KO ${Coff}"
|
||||
echo -e "$Coff $Cfail KO $Coff\n"
|
||||
fi
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.rs ()
|
||||
function echo.action ()
|
||||
{
|
||||
local symbol=${3:-*}
|
||||
local color=${4:-Citem}
|
||||
echo -e " $Csymbol$symbol ${Caction}$1 ${!color}$2$Coff"
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function echo.title ()
|
||||
{
|
||||
echo -e "\n $Csymbol☪ $Ctitle$1 $Coff$Cspe$2$Coff\n"
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function echo.keyval ()
|
||||
{
|
||||
local len=${3:-20}
|
||||
local c="$Ckey: ${Cval}"
|
||||
echo -e " $Ckey $(printf "%-${len}s " "$1") ${c}${2} $Coff"
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function echo.rs ()
|
||||
{
|
||||
local rs=${1:-0}
|
||||
if [ "$rs" -eq 0 ]; then
|
||||
|
@ -92,7 +60,7 @@ function bes.echo.rs ()
|
|||
fi
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.error ()
|
||||
function echo.error ()
|
||||
{
|
||||
local leave=${2:-0}
|
||||
echo -e "\n${Cerr} error : ${Coff}\n\t$1 ${Coff}\n"
|
||||
|
@ -101,42 +69,30 @@ function bes.echo.error ()
|
|||
fi
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.sepline ()
|
||||
function echo.sepline ()
|
||||
{
|
||||
local char=${1:-'_'}
|
||||
local width=${2:-$BES_TERM_WIDTH}
|
||||
echo -ne "${Csep} "
|
||||
echo -ne "${Cheadline} "
|
||||
printf "%0.s$char" $(seq 1 $width)
|
||||
echo -e "${Coff}"
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.app ()
|
||||
function echo.app ()
|
||||
{
|
||||
local msg=${1:-''}
|
||||
local version=${2:-''}
|
||||
local author=${3:-'a-Sansara'}
|
||||
local license=${3:-'GNU GPL v3'}
|
||||
if [ ! -z "$2" ]; then
|
||||
msg="$msg ${Cval}v$version"
|
||||
fi
|
||||
local len="$1${version}license : GNU GPL v3 author:$author"
|
||||
bes.echo.sepline
|
||||
echo -ne "\n $Ctitle $msg $Coff"
|
||||
local len="$1${version}license : $license author:$author"
|
||||
echo.sepline
|
||||
echo -ne "\n $Chead $msg $Coff"
|
||||
printf "%0.s " $(seq 1 $(($BES_TERM_WIDTH-${#len}-15)))
|
||||
echo -e " ${Cmeta}license : ${Coff}GNU GPL v3 ${Cmeta}author : ${Cval}$author"
|
||||
bes.echo.sepline
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function bes.echo.colormap ()
|
||||
{
|
||||
for fgbg in 38 48 ; do
|
||||
for color in {0..256} ; do
|
||||
echo -en "\e[${fgbg};5;${color}m ${color}\t\e[0m"
|
||||
if [ $((($color + 1) % 7)) == 0 ] ; then
|
||||
echo
|
||||
fi
|
||||
done
|
||||
echo
|
||||
done
|
||||
echo -e " ${Cmeta}license : ${Coff}$license ${Cmeta}author : ${Cval}$author"
|
||||
echo.sepline
|
||||
}
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
bes.echo.boot
|
||||
|
|
Loading…
Reference in New Issue
Block a user