Skip to content

Commit

Permalink
color: let "bleopt term_index_colors" override the default if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 16, 2022
1 parent 69013d9 commit 7d238c0
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 28 deletions.
17 changes: 11 additions & 6 deletions blerc
Expand Up @@ -692,12 +692,17 @@
##-----------------------------------------------------------------------------
## Color settings

## The setting "term_index_colors" specifies the number of index colors
## supported by you terminal. The value 256 is treated as xterm 256-color
## palette (16 basic + 6x6x6 color cube + 24 gray scale). The value 88 is
## treated as xterm 88-color palette (16 basic + 4x4x4 color cube + 8 gray
## scale). The value 0 means that the terminal does not support extra colors
## other than basic colors.
## The setting "term_index_colors" specifies the number of index colors used to
## specify colors in the terminal. The value "auto" means that the use of
## index colors are determined based on the terminfo database and the value of
## TERM shell variable. Otherwise, the value is evaluated as an arithmetic
## expression. When it is evaluated to 256, the index colors are assumed to be
## xterm 256-color palette (16 basic + 6x6x6 color cube + 24 gray scale). When
## it is evaluated to 88, the index colors are assumed to be xterm 88-color
## palette (16 basic + 4x4x4 color cube + 8 gray scale). When it is evaluated
## to 0, ble.sh will never use the index colors to set colors. When it is
## evaluated to other integers, the value specifies the maximum available
## index.

#bleopt term_index_colors=256

Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -198,6 +198,7 @@
- trap: fix a bug that `DEBUG` for internal commands clears `$?` `#D1867` a22c25b
- progcomp: reproduce arguments of completion functions passed by Bash `#D1872` 4d2dd35
- prompt: preserve transient prompt with `same-dir` after `clear-screen` `#D1876` xxxxxxx
- color: let `bleopt term_index_colors` override the default if specified `#D1878` xxxxxxx

## Fixes

Expand Down
78 changes: 78 additions & 0 deletions note.txt
Expand Up @@ -1855,6 +1855,12 @@ bash_tips
- leakvars
- keymap の移動 (これは別 commit にする?)

2022-09-15

* vim terminal や neovim terminal における keymap-timeout に対応する設定は何
か。調べてみると ttimeoutlen や timeoutlen という物がある様だが、これの設定
を変更しても振る舞いに変化はない気がする。後でちゃんと調べる必要がある。

2022-09-11

* 何らかの拍子に P[0 q の様な謎の文字列がユーザーコマンドの実行後に出力される
Expand Down Expand Up @@ -6591,6 +6597,78 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-09-16

* color: term_index_colors を優先する様に変更 (motivated by StavromulaBeta) [#D1878]

これで強制的に減色したい時にユーザーが term_index_colors を設定できる。

* [棄却] neovim terminal / vim-autocomplpop で i/a を入力した時の問題 [#D1877]
https://github.com/akinomyoga/ble.sh/issues/232

変な文字列が挿入・実行される

# これは報告者が使っている AutoComplPop というプラグインが古いのが原因だった

neovim は nvim というコマンドで起動する様だ。

再現しない。nvim-0.7.2, bash-5.2-rc2, としても再現しない。

* plain vimrc? .vimrc をコメントアウトして試したが再現しない。

* reject: 或いは i, a に対する delay が関係している可能性? 実際に操作してい
てい ESC がちゃんと即座に処理されていない気がする。
https://vi.stackexchange.com/questions/16148/slow-vim-escape-from-insert-mode
と思って ttimeoutlen や timeoutlen を短い値に変えてみたが振る舞い(遅延)に
変化は見られない。これらの設定は関係ないという事か?

* 27_feedPopup() という文字列が挿入されている。9_feedPopup で検索すると vim
の中にある自動補完の仕組みが関係している様な気がするが詳細はよく分からな
い。これでエラーが出ているという事は、実際に ble.sh がこの文字列を受信し
ているということである。vim の保管機能が意図しない形で ble.sh に対して送
信されて、変な文字列が挿入されると共に実行まで開始されている。

https://askubuntu.com/questions/382407/vim-autocomplpop-issues

このページを見る限り AutoComplPop という何かが関係している?
元々のページ at bitbucket は消滅している?

https://github.com/vim-scripts/AutoComplPop

ここを見ると最後に更新されているのは12年前。runtime path 以下にファイルを
コピーしろと書かれているが runtime path が何か分からない。検索すると
runtimepath という変数に入っているみたいだが、今度は runtimepath という変
数の値を取得する方法が分からない。と思ったら ":set runtimepath^M" で良い
様だ。set で右辺を指定しなければ現在の値が表示される。実際に表示してみる
と以下の様になっている。

# runtimepath=~/.config/nvim,/etc/xdg/nvim,~/.local/share/nvim/site,
# ~/.local/share/flatpak/exports/share/nvim/site,
# /var/lib/flatpak/exports/share/nvim/site,
# /usr/local/share/nvim/site,/usr/share/nvim/site,/usr/share/nvim/runtime,
# /usr/share/nvim/runtime/pack/dist/opt/matchit,/usr/lib/nvim,
# /usr/share/nvim/site/after,/usr/local/share/nvim/site/after,
# /var/lib/flatpak/exports/share/nvim/site/after,
# ~/.local/share/flatpak/exports/share/nvim/site/after,
# ~/.local/share/nvim/site/after,/etc/xdg/nvim/after,~/.config/nvim/after,
# /usr/share/vim/vimfiles/

取り敢えず .config/nvim に入れる。

OK 再現した。うーん。何故これが発生しているのだろうか。

うーん。然し、そもそも ble.sh をロードしていなかったとしても i または a
を押すと最後に実行したコマンドが強制的に実行される様である。これは変であ
る。そもそも ble.sh だけの問題ではない気がする。

検索すると https://github.com/othree/vim-autocomplpop/issues/9 で同じ現象
が報告されている。というかこれが acp の最新版なのではないか。これを入れて
みたところ、今度は ***** L9 library must be installed! ***** というメッセー
ジが表示される。検索してみたらこれは行番号ではなくて "L9" という名前のラ
イブラリらしい。同じエラーメッセージについての質問があった。

https://stackoverflow.com/questions/22902141/l9-library-must-be-installed-error-occurred

2022-09-14

* prompt: clear-screen 後は same-dir でも transient prompt を残しておく [#D1876]
Expand Down
54 changes: 32 additions & 22 deletions src/color.sh
Expand Up @@ -16,17 +16,15 @@ _ble_color_gflags_BgMask=0x00FFFFFF00000000
_ble_color_gflags_FgIndexed=0x0100000000000000
_ble_color_gflags_BgIndexed=0x0200000000000000

function ble/color/define-options {
local ncolor=0
if [[ $TERM == xterm* || $TERM == *-256color || $TERM == kterm* ]]; then
ncolor=256
elif [[ $TERM == *-88color ]]; then
ncolor=88
fi
bleopt/declare -v term_true_colors semicolon
bleopt/declare -v term_index_colors "$ncolor"
}
ble/color/define-options
_ble_color_index_colors_default=$_ble_term_colors
if [[ $TERM == xterm* || $TERM == *-256color || $TERM == kterm* ]]; then
_ble_color_index_colors_default=256
elif [[ $TERM == *-88color ]]; then
_ble_color_index_colors_default=88
fi

bleopt/declare -v term_true_colors semicolon
bleopt/declare -v term_index_colors auto

function bleopt/check:term_true_colors {
ble/color/g2sgr/.clear-cache
Expand Down Expand Up @@ -679,12 +677,14 @@ function ble/color/.color2sgr-impl {
ret=${_ble_term_sgr_af[ccode]}
fi
elif ((ccode<256)); then
if ((_ble_term_colors>=256||bleopt_term_index_colors==256)); then
local index_colors=$_ble_color_index_colors_default
[[ $bleopt_term_index_colors == auto ]] || ((index_colors=bleopt_term_index_colors))
if ((index_colors>=256)); then
ret="${prefix}8;5;$ccode"
elif ((_ble_term_colors>=88||bleopt_term_index_colors==88)); then
elif ((index_colors>=88)); then
ble/color/convert-color256-to-color88 "$ccode"
ret="${prefix}8;5;$ret"
elif ((ccode<_ble_term_colors||ccode<bleopt_term_index_colors)); then
elif ((ccode<index_colors)); then
ret="${prefix}8;5;$ccode"
elif ((_ble_term_colors>=16||_ble_term_colors==8)); then
if ((ccode>=16)); then
Expand Down Expand Up @@ -726,15 +726,25 @@ function ble/color/.color2sgr-impl {
ret="${prefix}8;2;$R;$G;$B"
elif [[ $bleopt_term_true_colors == colon ]]; then
ret="${prefix}8:2:$R:$G:$B"
elif ((_ble_term_colors>=256||bleopt_term_index_colors==256)); then
ble/color/convert-rgb24-to-color256 "$R" "$G" "$B"
ret="${prefix}8;5;$ret"
elif ((_ble_term_colors>=88||bleopt_term_index_colors==88)); then
ble/color/convert-rgb24-to-color88 "$R" "$G" "$B"
ret="${prefix}8;5;$ret"
else
ble/color/convert-rgb24-to-color256 "$R" "$G" "$B"
ble/color/.color2sgr-impl "$ret" "$prefix"
local index_colors=$_ble_color_index_colors_default
[[ $bleopt_term_index_colors == auto ]] || ((index_colors=bleopt_term_index_colors))
local index=
if ((index_colors>=256)); then
ble/color/convert-rgb24-to-color256 "$R" "$G" "$B"
index=$ret
elif ((index_colors>=88)); then
ble/color/convert-rgb24-to-color88 "$R" "$G" "$B"
index=$ret
else
ble/color/convert-rgb24-to-color256 "$R" "$G" "$B"
if ((ret<index_colors)); then
index=$ret
else
ble/color/.color2sgr-impl "$ret" "$prefix"
fi
fi
[[ $index ]] && ret="${prefix}8;5;$index"
fi
else
ret=${prefix}9
Expand Down

0 comments on commit 7d238c0

Please sign in to comment.