Skip to content

Commit

Permalink
canvas: fix unupdated prompt on async wcwidth resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 20, 2022
1 parent 6d15782 commit e14fa5d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
11 changes: 6 additions & 5 deletions docs/ChangeLog.md
Expand Up @@ -133,7 +133,7 @@
- complete (`source:command`): exclude inactive aliases `#D1715` d6242a7
- complete (`source:command`): not quote aliases and keywords `#D1715` d6242a7
- highlight (`wtype=CTX_CMDI`): check alias names before shell expansions `#D1715` d6242a7
- util (`ble/is-alias`): fix a bug of unredirected error messages for bash-3.2 (fixup d6242a7) `#D1730` 0000000
- util (`ble/is-alias`): fix a bug of unredirected error messages for bash-3.2 (fixup d6242a7) `#D1730` 31372cb

## Fixes

Expand All @@ -154,7 +154,7 @@
- mandb: parse `--help` for specified commands `#D1693` e1ad2f1
- mandb: fix small issues of man-page analysis `#D1708` caa77bc
- mandb: insert a comma in brace expansions instead of a space `#D1719` 0ac7f03
- mandb: supprot man-page format of `rsync` `#D1733` 0000000
- mandb: support man-page format of `rsync` `#D1733` 7900144
- edit: work around the wrong job information of Bash in trap handlers (reported by 3ximus) `#D1435` `#D1436` bc4735e
- edit (command-help): work around the Bash bug that tempenv vanishes with `builtin eval` `#D1438` 8379d4a
- global: suppress missing locale errors (reported by 3ximus) `#D1440` 4d3c595
Expand Down Expand Up @@ -219,9 +219,10 @@
- highlight: fix a bug that arrays without the element `0` is not highlighted `#D1721` b0a0b6f
- util (visible-bell): erase visible-bell before running external commands `#D1723` 0da0c1c
- util (`ble/function`): work around `shopt -u extglob` `#D1725` 952c388
- syntax: fix uninitialized syntax-highlighting in bash-3.2 `#D1731` 0000000
- syntax: fix uninitialized syntax-highlighting in bash-3.2 `#D1731` e3f5bf7
- make: fix a bug that config update messages are removed on install `#D1736` 0000000
- util: fix bugs in conversions from `'` to `\''` `#D1739` 0000000
- canvas: fix unupdated prompt on async wcwidth resolution `#D1740` 0000000

## Documentation

Expand Down Expand Up @@ -285,7 +286,7 @@
- main: work around `XDG_RUNTIME_DIR` of a different user by `su` (reported by zim0369) `#D1712` 8d37048
- main (`ble/util/readlink`): work around non-standard or missing `readlink` (motivated by peterzky) `#D1720` a41279e
- menu (`menu-style:desc`): work around xenl quirks for relative cursor movements (reported by telometto) `#D1728` 3e136a6
- global: work around the arithmetic syntax error of `10#` in Bash-5.1 `#D1734` 0000000
- global: work around the arithmetic syntax error of `10#` in Bash-5.1 `#D1734` 7545ea3
- global: adjust implementations for Bash 5.2 `patsub_replacement` `#D1738` 0000000

## Internal changes and fixes
Expand Down Expand Up @@ -315,7 +316,7 @@
- util: fix leak variables `#D1643` fcf634b
- edit (`command-help`): use `ble/util/assign/.mktmp` to determine the temporary filename `#D1663` 1af0800
- make: update lint check `#D1709` 7e26dcd
- test: save the test log to a file `#D1735` 0000000
- test: save the test log to a file `#D1735` d8e6ea7
- benchmark: improve determination of the base time `#D1737` 0000000

## Contrib
Expand Down
47 changes: 47 additions & 0 deletions note.txt
Expand Up @@ -1688,6 +1688,25 @@ bash_tips
ToDo
-------------------------------------------------------------------------------

2022-01-20

* cygwin で root prompt mark が正しく表示されなくなっていると思ったが、よく考
えたら ${PS1@P} を使う様にしているからではないか。振る舞いを修正している物
が含まれている場合にも ${PS1@P} の仕様は無効化する必要がある。

つまり、cygwin, msys, etc において PS1 に \$ が含まれていたら駄目。

* bash-completion や oh-my-bash の version と terminal ID について C-xC-v で
出力したい。

* それを issue 報告に貼り付ける様にお願いする。

* terminal ID / version をちゃんと検出する様にする。DA2R も一緒に出力するべ
き。

* bash-it には version 等は存在しないのだろうか。うーん。だからといっていき
なり要求するのも違う気がする。

2022-01-19

* PS1 のディレクトリ名に特殊文字が含まれている場合の取り扱い
Expand Down Expand Up @@ -5825,6 +5844,34 @@ bash_tips

2022-01-20

* prompt: bash-it や oh-my-bash で最初のプロンプトの座標計算がずれる [#D1740]

ble.sh を読み込むと最初のプロンプトの表示がずれてしまう。これは ble.sh をロー
ドして最初にプロンプトを表示した時には未だ char_width_{mode,version} が解決
されていないので、既定の設定が使われて座標計算にずれが生じるのが原因である。

本来は bleopt_char_width_{mode,version} が変化していれば再描画される筈なの
であるが何故再描画が走らないのだろうか。取り敢えず
ble/prompt/unit:_ble_prompt_ps1/update の時点で char_width_@ が解説された後
に呼び出されていない。ble/prompt/unit#update _ble_prompt_ps1 は実行されてい
る。という事を考えると、の間で更新が棄却されているという事になる。

ohashref='$_ble_prompt_version::$prompt_ps1,$PWD' である。うーん。本来は
$_ble_prompt_version と同じ所で char_width_@ も参照するべきの気がする。→結
局 prompt_hashref_base に '$_ble_prompt_version' だけが入っていた所
に'$bleopt_char_width_mode,$bleopt_char_width_version' も追加する事で解決し
た。他にも LC_CTYPE が変わった時にも問題になるのではないか、と思ったが
LC_CTYPE がコマンド実行以外で勝手に切り替わる事もないと思われるの
で、_ble_prompt_version でカバーできていると考えるべきである。つまり、
bleopt_char_width_{mode,version} は非同期で変化する可能性があるのでそれに応
じて更新する必要があるという事。

と思ったが、bleopt_char_width_{mode,version} が変化するのは検出できるのだか
ら、其処で、_ble_prompt_version を更新すれば良いだけなのでは→その様に変更
する事にした。実は bleopt_char_width_{mode,version} の他にも
emoji_{opts,version} が存在した。これらも変化があればちゃんとプロンプトを更
新する必要がある可能性がある。全て対応した。ちゃんと動いている。

* bash-5.2 shopt patsub_replacement 対策 [#D1739]

これは #D1738 の一環として発見されたバグであるが bash-0.3 も修正しなければ
Expand Down
5 changes: 5 additions & 0 deletions src/canvas.sh
Expand Up @@ -62,6 +62,7 @@ function bleopt/check:char_width_mode {
(west) _ble_unicode_c2w_ambiguous=1 ;;
(east) _ble_unicode_c2w_ambiguous=2 ;;
esac
((_ble_prompt_version++))
ble/util/c2w/clear-cache
}

Expand Down Expand Up @@ -121,10 +122,12 @@ bleopt/declare -n char_width_version auto
function bleopt/check:char_width_version {
if [[ $value == auto ]]; then
ble && ble/util/c2w:auto/test.buff first-line
((_ble_prompt_version++))
ble/util/c2w/clear-cache
return 0
elif local ret; ble/unicode/c2w/version2index "$value"; then
_ble_unicode_c2w_version=$ret
((_ble_prompt_version++))
ble/util/c2w/clear-cache
return 0
else
Expand Down Expand Up @@ -207,6 +210,7 @@ function bleopt/check:emoji_version {
fi

_ble_unicode_EmojiStatus_version=$ret
((_ble_prompt_version++))
ble/util/c2w/clear-cache
return 0
}
Expand All @@ -223,6 +227,7 @@ function bleopt/check:emoji_opts {
local rex=':min=U\+([0-9a-fA-F]+):'
[[ :$value: =~ $rex ]] &&
_ble_unicode_EmojiStatus_xIsEmoji=$_ble_unicode_EmojiStatus_xIsEmoji'&&code>=0x'${BASH_REMATCH[1]}
((_ble_prompt_version++))
ble/util/c2w/clear-cache
return 0
}
Expand Down
3 changes: 2 additions & 1 deletion src/edit.sh
Expand Up @@ -1134,7 +1134,8 @@ function ble/prompt/.instantiate {
elif
local rows=${prompt_rows:-${LINES:-25}}
local cols=${prompt_cols:-${COLUMNS:-80}}
trace_hash=$opts:$rows,$cols:$bleopt_char_width_mode:$expanded
local bleopt=$bleopt_char_width_mode,$bleopt_char_width_version,$bleopt_emoji_version,$bleopt_emoji_opts
trace_hash=$opts#$rows,$cols#$bleopt#$expanded
[[ $trace_hash != "$trace_hash0" ]]
then
local trace_opts=$opts:prompt
Expand Down

0 comments on commit e14fa5d

Please sign in to comment.