Skip to content

Commit

Permalink
color: rearrange color table by "ble palette"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 19, 2023
1 parent e619e73 commit bb8541d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ble.pp
Expand Up @@ -2020,7 +2020,7 @@ function ble/dispatch {
(opt) bleopt "$@" ;;
(hook) blehook "$@" ;;
(sabbrev) ble-sabbrev "$@" ;;
(palette) ble-color-show "$@" ;;
(palette) ble-palette "$@" ;;
(help|--help) ble/dispatch/.help "$@" ;;
(version|--version) ble/util/print "ble.sh, version $BLE_VERSION (noarch)" ;;
(check|--test) ble/base/sub:test "$@" ;;
Expand Down
2 changes: 1 addition & 1 deletion contrib
Submodule contrib updated 1 files
+17 −6 colorglass.bash
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -221,6 +221,7 @@
- canvas: update Unicode version 15.0.0 `#D1880` 49e55f4
- decode (`vi_imap-rlfunc.txt`): update the widget for `backward-kill-word` as `kill-backward-{u => c}word` `#D1896` e19b796
- term (`_ble_term_TERM`): detect wezterm-20220408 `#D1909` 486564a
- color: rearrange color table by `ble palette` (suggested by stackoverflow/caoanan) `#D1961` xxxxxxx

## Fixes

Expand Down
13 changes: 7 additions & 6 deletions note.txt
Expand Up @@ -1947,15 +1947,10 @@ bash_tips
* README: Guix package の位置が変わっている。

* syntax: 関数名として function `xxx` 等も実は許されている。
5.3 以降では更に <(...) も関数名として使える。

* syntax: 5.2 以降では (()) [[]] の直後は } 等が来ても良い。

* ble palette
https://superuser.com/a/1512656/980046 コメント

色の排列を考え直す余地はある。現在は横幅 64 使っている。高さが 32 なのは実
は端末の 80x24 には入り切らない。

2023-02-06

* auto-complete: cd 等簡単に成否が分かる物については判定して除外する可能性
Expand Down Expand Up @@ -6682,6 +6677,12 @@ bash_tips

2023-02-12

* color: ble palette の並び方をより分りやすく (suggested by stackoverflow/caoanan) [#D1961]
https://superuser.com/a/1512656/980046 コメント by caoanan

色の排列を考え直す余地はある。現在は横幅 64 使っている。高さが 32 なのは実
は端末の 80x24 には入り切らない。

* syntax: 履歴展開 & "$!", heredoc [#D1960]

bash-4.1 以下で echo "$!" を実行しようとしても履歴展開周りで変な事が起こっ
Expand Down
60 changes: 57 additions & 3 deletions src/color.sh
Expand Up @@ -13,6 +13,8 @@ _ble_color_gflags_Blink=0x40
_ble_color_gflags_DecorationMask=0x77
_ble_color_gflags_FgMask=0x00000000FFFFFF00
_ble_color_gflags_BgMask=0x00FFFFFF00000000
_ble_color_gflags_FgShift=8
_ble_color_gflags_BgShift=32
_ble_color_gflags_FgIndexed=0x0100000000000000
_ble_color_gflags_BgIndexed=0x0200000000000000

Expand Down Expand Up @@ -72,17 +74,69 @@ function ble-color-show {
return "$?"
fi

local cols=16
local cols=$(((${COLUMNS:-80}-1)/4))
((cols<1?(cols=1):(cols>16&&(cols=16))))
local bg bg0 bgN ret gflags=$((_ble_color_gflags_BgIndexed|_ble_color_gflags_FgIndexed))
for ((bg0=0;bg0<256;bg0+=cols)); do
((bgN=bg0+cols,bgN<256||(bgN=256)))
for ((bg=bg0;bg<bgN;bg++)); do
ble/color/g2sgr "$((gflags|bg<<32))"
ble/color/g2sgr "$((gflags|bg<<_ble_color_gflags_BgShift))"
printf '%s%03d ' "$ret" "$bg"
done
printf '%s\n' "$_ble_term_sgr0"
for ((bg=bg0;bg<bgN;bg++)); do
ble/color/g2sgr "$((gflags|bg<<32|15<<8))"
ble/color/g2sgr "$((gflags|bg<<_ble_color_gflags_BgShift|15<<_ble_color_gflags_FgShift))"
printf '%s%03d ' "$ret" "$bg"
done
printf '%s\n' "$_ble_term_sgr0"
done
}
function ble-palette {
if (($#)); then
ble/base/print-usage-for-no-argument-command 'Update and reload ble.sh.' "$@"
return "$?"
fi

if ((${COLUMNS:-80}<80)); then
ble-color-show
return 0
fi

local ret gflags=$((_ble_color_gflags_BgIndexed|_ble_color_gflags_FgIndexed))
local l c bg
for ((l=0;l<2;l++)); do
for ((c=0;c<16;c++)); do
((bg=l/2*8+c))
ble/color/g2sgr "$((gflags|bg<<_ble_color_gflags_BgShift|(l%2?15:0)<<_ble_color_gflags_FgShift))"
printf '%s%03d ' "$ret" "$bg"
done
printf '%s\n' "$_ble_term_sgr0"
done

local l p B G R
for ((l=0;l<24;l++)); do
((G=l%12/2))
for ((p=0;p<3;p++)); do
((R=l>=12?3+p:p))
for ((B=0;B<6;B++)); do
((bg=16+R*36+G*6+B))
ble/color/g2sgr "$((gflags|bg<<_ble_color_gflags_BgShift|(l%2?15:0)<<_ble_color_gflags_FgShift))"
printf '%s%03d ' "$ret" "$bg"
done
if ((p+1<3)); then
printf '%s ' "$_ble_term_sgr0"
else
printf '%s\n' "$_ble_term_sgr0"
fi
done
done

local l c K
for ((l=0;l<4;l++)); do
for ((c=0;c<12;c++)); do
((K=l/2*12+c))
((bg=232+K))
ble/color/g2sgr "$((gflags|bg<<_ble_color_gflags_BgShift|(l%2?15:0)<<_ble_color_gflags_FgShift))"
printf '%s%03d ' "$ret" "$bg"
done
printf '%s\n' "$_ble_term_sgr0"
Expand Down

0 comments on commit bb8541d

Please sign in to comment.