diff --git a/.bash_colors b/.bash_colors new file mode 100644 index 0000000..d9cdbf3 --- /dev/null +++ b/.bash_colors @@ -0,0 +1,179 @@ +#!/bin/bash + +colors=(black red green yellow blue purple cyan white) +declare -A COL BG TEXT + +for c in ${!colors[@]} +do + COL[${colors[$c]}]="$(tput setaf $c)" + BG[${colors[$c]}]="$(tput setab $c)" +done +unset c + +COL[0]="$(tput sgr0)" + + +TEXT[underline]="$(tput smul)" +TEXT[no-underline]="$(tput rmul)" +TEXT[blink]="$(tput blink)" +TEXT[bold]="$(tput bold)" +TEXT[dim]="$(tput dim)" +TEXT[italic]="$(tput sitm)" +TEXT[reverse]="$(tput rev)" + +COL_show() +{ + for b in {0..7}; do + for c in {0..7};do + tput setaf $c + tput setab $b + printf $c + tput sgr0 + done + echo + done +} + + +COL.show() +{ + cap="${1:-8}" +# declare -p cap + + if [ "$cap" = 8 ]; then + for c in ${colors[@]}; do + echo -e ${COL[$c]}\${COL[$c]}${COL[0]}"\t"${BG[$c]}\${BG[$c]}${COL[0]} + done + + elif [ "$cap" = 256 ]; then + echo ${COL[0]}" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" + for n in {0..15}; do + printf "`tput setab $n`%s`tput sgr0`" " " + done + echo + echo 16 + for n in {0..5}; do + local from=$(($n * 36 + 16)) to=$(($n * 36 + 16 + 35)) +# declare -p from to + printf '%3s' $from + for nn in $(seq $from $to); do + printf "`tput setab $nn`%s`tput sgr0`" " " + done + echo $to + done + echo + echo 24 greys from 231 + '<1 to 24>' + for n in {232..256}; do + printf "`tput setab $n`%s`tput sgr0`" " " + done + echo + fi +} + +COL.greys(){ printf $((232+$1)); } +COL.rgb(){ echo $(( 16 + ($1*36) + ($2*6) + ($3) )); } + +COL.square(){ printf "${BG[$1]}%s" ' '; } +# COL.gradient (R|G|B) | ( R G | R B | G R | G B | B R | B G ) +COL.gradient() +{ + echo $# + local R=0 G=0 B=0 n a b + case $# in + + 1) for n in {0..5};do + [[ $1 = R ]] && R=$n + [[ $1 = G ]] && G=$n + [[ $1 = B ]] && B=$n + COL.square $R$G$B + done + echo ${COL[0]} + ;; + + 2) for a in {0..5};do + for b in {0..5};do + [[ $1 = R ]] && R=$b + [[ $2 = R ]] && R=$a + [[ $1 = G ]] && G=$b + [[ $2 = G ]] && G=$a + [[ $1 = B ]] && B=$b + [[ $2 = B ]] && B=$a + COL.square $R$G$B + done + echo ${COL[0]} + done + echo ${COL[0]} + ;; + + *) echo "help" ;; + + esac +} + +# RGB indexed colors for 256 colors terminals +for r in {0..5}; do + for g in {0..5}; do + for b in {0..5}; do + COL[$r$g$b]="$(tput setaf `COL.rgb $r $g $b`)" + BG[$r$g$b]="$(tput setab `COL.rgb $r $g $b`)" + done + done +done +unset r g b + +# Greys +for g in {0..23}; do + COL[grey$g]="$(tput setaf `COL.greys $g`)" + BG[grey$g]="$(tput setab `COL.greys $g`)" +done + +export COL BG TEXT # 'COL.show' 'COL.greys' 'COL.rgb' 'COL.square' 'COL.gradient' + + + + + + + + + + + + + + +#css() +#{ +# [[ ! -z $color ]] && printf ${COL[$color]} +# [[ ! -z $background ]] && printf ${BG[$background]} +# [[ ! -z $style ]] && printf ${COL[$style]} +## echo CSS +## printf ${COL[reset]} +#} +# +#style() +#{ +# local color background _style +# for kv in "$@";do +# case $kv in +# color=*) color=${kv} ;; +# esac +# done +#} + +#declare -A class=() + +#color=red +#class[title]=$(color=blue background=white style=underline css) + +#$(h1 class=title)Coucou$(/h1) +#echo "`css` +#Normal text ${class[title]}TITLE STYLE${COL[reset]}`css` and normal again +# +#" + + + + + + diff --git a/README.md b/README.md index e49f016..fb5ab36 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ # pxedit -Small bash experiment to draw pixel-art in terminal \ No newline at end of file +Small bash experiment to draw pixel-art in terminal + +## Usage + +```bash +git clone https://git.p2p.legal/dig/pxedit.git +source pxedit/pxview + +pxview pxedit/exemples/box.px +``` \ No newline at end of file diff --git a/pxview b/pxview new file mode 100644 index 0000000..c361155 --- /dev/null +++ b/pxview @@ -0,0 +1,29 @@ +#!/bin/bash +source ./.bash_colors > /dev/null + +pxview() +{ + +path="$1" +bmpx="$(cat "$path")" +palette=($(echo "$bmpx" | sed '1!d')) +bmpx="$(echo "$bmpx" | sed '1d')" +line1="$(echo "$bmpx" | sed '1!d')" +width=$(( $(echo "$line1" | wc -m) - 1 )) +background="${palette[0]}" + +#declare -p path palette bmpx width background +if [ $# > 1 ]; then + eval "$(for pal in "${@:2}";do printf 'palette%s ' "$pal";done)" +# declare -p palette +fi + +echo "$bmpx" | while read row; do + echo "$row" | while IFS= read -rN1 px; do +# echo ch: '"'$px'"' + COL.square ${palette[$px]} + done + echo ${COL[0]} +done + +}