Skip to content

Commit

Permalink
prompt: accept more general "[TYPE:]SPEC" in "\g{...}" like "ble-face"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 19, 2023
1 parent 67cb967 commit 81b3b0e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -63,6 +63,7 @@
- syntax: highlight quotes of the `\?` form `#D1584` 5076a03
- syntax: recognize escape \" in double-quoted strings `#D1641` 4b71449
- prompt: support a new backslash sequence `\g{...}` `#D1609` be31391
- prompt: accept more general `[TYPE:]SPEC` in `\g{...}` like `ble-face` `#D1963` xxxxxxx
- complete: add a new option `bleopt complete_limit_auto_menu` `#D1618` 1829d80
- canvas: support grapheme clusters (motivated by huresche) `#D1619` c0d997b
- canvas (`ble/util/c2w`): use `EastAsianWidth` and `GeneralCategory` to mimic `wcwidth` `#D1645` 9a132b7
Expand Down
35 changes: 27 additions & 8 deletions note.txt
Expand Up @@ -1934,14 +1934,6 @@ bash_tips

2023-02-12

* prompt: \g{} は ble/color/setface/.spec2g を使う?
https://github.com/akinomyoga/ble.sh/issues/278

そうしたらカスタム face を指定できて、ユーザーが自分で定義する事に直接の意
義が出てくる。

* wiki: 他にも faces はあるという事を書く。

* blerc.template: update unicode versions

* README: Guix package の位置が変わっている。
Expand All @@ -1950,6 +1942,18 @@ bash_tips
以降では更に <(...) も関数名として使える。しかもこれらは `xxx`() や
<(...)() の形式でも定義できる。

現在の実装では関数名を function NAME まで一回の解析で進むようにしている。何
故だったか。何か理由があった気がするが、この取扱になっている限りはちゃんと
対応するのは難しい。過去の記録を調べる必要がある。

* histdb: bg process timeout

* complete: shopt -s extglob failglob で @(aa)() { echo; } という関数を作成し
て置くと screen -dr の補完の途中でエラーメッセージが表示される。何処から表
示されているのだろうか? 関数名を拾って更にその上でそれをパス名展開に晒して
いる箇所があるのだろうか? simple-word ではないので ble.sh の内部ではないの
ではないか…という気がするが分からない。

2023-02-06

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

2023-02-12

* prompt: \g{} は ble/color/setface/.spec2g を使う? [#D1963]
https://github.com/akinomyoga/ble.sh/issues/278

そうしたらカスタム face を指定できて、ユーザーが自分で定義する事に直接の意
義が出てくる。

* done: wiki: 他にも faces はあるという事を書く (motivated by bkerin)

2023-02-13 .spec2g は動的な face の為に算術式を返すので、color.sh の枠組み
の外側で算術式評価する様になっていると、後に face 継承などを実装した時に評
価文脈が違って変な事になる可能性がある。評価文脈をちゃんと把握する為に、算
術式評価した結果を返す関数を color.sh の側で用意してそれを呼び出す様にする
べきである。.spec2g は .spec2gexpr に改名し、それとは別に spec2g という関数
を用意してそれを呼び出させる事にした。

* syntax: 5.2 以降では (()) [[]] の直後は } 等が来ても良い [#D1962]
これの修正は簡単。

Expand Down
18 changes: 12 additions & 6 deletions src/color.sh
Expand Up @@ -1054,6 +1054,7 @@ function ble/color/face2g { ble/color/initialize-faces && ble/color/face2g
function ble/color/face2sgr { ble/color/initialize-faces && ble/color/face2sgr "$@"; }
function ble/color/iface2g { ble/color/initialize-faces && ble/color/iface2g "$@"; }
function ble/color/iface2sgr { ble/color/initialize-faces && ble/color/iface2sgr "$@"; }
function ble/color/spec2g { ble/color/initialize-faces && ble/color/spec2g "$@"; }

function ble/color/face2sgr-ansi { ble/color/initialize-faces && ble/color/face2sgr "$@"; }

Expand Down Expand Up @@ -1082,11 +1083,16 @@ function ble/color/initialize-faces {
function ble/color/iface2sgr {
ble/color/g2sgr "$((_ble_faces[$1]))"
}
## @fn ble/color/spec2g [TYPE:]SPEC
function ble/color/spec2g {
ble/color/setface/.spec2gexpr "$@" prefix-face
((ret=ret))
}

## @fn ble/color/setface/.spec2g spec
## @fn ble/color/setface/.spec2gexpr spec
## @var[out] ret
function ble/color/setface/.spec2g {
local spec=$1 value=${spec#*:}
function ble/color/setface/.spec2gexpr {
local spec=$1 value=${1#*:} opts=$2
case $spec in
(gspec:*) ble/color/gspec2g "$value" ;;
(g:*) ret=$(($value)) ;;
Expand All @@ -1098,7 +1104,7 @@ function ble/color/initialize-faces {
fi ;;
(copy:*|face:*|iface:*)
# `face:*' and `iface:*' are obsoleted forms.
[[ $spec == copy:* ]] ||
[[ $spec == copy:* || $spec == face:* && :$opts: == *:prefix-face:* ]] ||
ble/util/print "ble-face: \"${spec%%:*}:*\" is obsoleted. Use \"copy:*\" instead." >&2
if [[ ! ${value//[0-9]} ]]; then
ble/color/iface2g "$value"
Expand All @@ -1115,14 +1121,14 @@ function ble/color/initialize-faces {
local name=_ble_faces__$1 spec=$2 ret
(($name)) && return 0
(($name=++_ble_faces_count))
ble/color/setface/.spec2g "$spec"
ble/color/setface/.spec2gexpr "$spec"
_ble_faces[$name]=$ret
_ble_faces_def[$name]=$ret
}
function ble/color/setface {
local name=_ble_faces__$1 spec=$2 ret
if [[ ${!name} ]]; then
ble/color/setface/.spec2g "$spec"; _ble_faces[$name]=$ret
ble/color/setface/.spec2gexpr "$spec"; _ble_faces[$name]=$ret
else
local message="ble.sh: the specified face \`$1' is not defined."
if [[ $_ble_color_faces_initializing ]]; then
Expand Down
2 changes: 1 addition & 1 deletion src/edit.sh
Expand Up @@ -1008,7 +1008,7 @@ function ble/prompt/backslash:g {
if [[ ${tail:2} =~ $rex ]]; then
((i+=${#BASH_REMATCH}))
local ret
ble/color/gspec2g "${BASH_REMATCH[1]}"
ble/color/spec2g "${BASH_REMATCH[1]}"
ble/color/g2sgr-ansi "$ret"
ble/prompt/print "$ret"
else
Expand Down

0 comments on commit 81b3b0e

Please sign in to comment.