From a3047f566e398418ca8708050a05202fc92f0f45 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 26 Sep 2021 11:13:23 +0900 Subject: [PATCH] canvas (c2w:auto): send "DSR(6)" in the internal state --- docs/ChangeLog.md | 5 +++-- note.txt | 23 +++++++++++++++++++++++ src/canvas.sh | 46 +++++++++++++++++++++++----------------------- src/edit.sh | 1 + 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 529af600..9fad3348 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -63,8 +63,9 @@ - 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 - - canvas (auto c2w): work around combining chars applied to the previous line `#D1649` 1cbbecb - - canvas (auto c2w): avoid duplicate requests `#D1649` 1cbbecb + - canvas (c2w:auto): work around combining chars applied to the previous line `#D1649` 1cbbecb + - canvas (c2w:auto): avoid duplicate requests `#D1649` 1cbbecb 0000000 + - canvas (c2w:auto): send DSR(6) in the internal state `#D1664` 0000000 - rlfunc: support vi word operations in `emacs` keymap (requested by SolarAquarion) `#D1624` 21d636a - edit: support `TMOUT` for the session timeout `#D1631` 0e16dbd - edit: support bash-5.2 `READLINE_ARGUMENT` `#D1638` d347fb3 diff --git a/note.txt b/note.txt index 2c4f55dc..c36bbbc2 100644 --- a/note.txt +++ b/note.txt @@ -5395,6 +5395,24 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2021-09-27 + + * canvas: 文字幅判定の為の CPR は internal 状態で実行したい [#D1664] + + CPR が画面に出力されてしまうのは stty echo の時に DSR(6) が出力されるから。 + ちゃんと internal state の時に CPR が出力される様にすれば防げるのではないか。 + 後で何処から出力されているかを確認する。 + + と思ったが、CPR の遅延があるのでそれによって表示されているだけかもしれない。 + その場合には対策できないかもしれないができるだけ早い段階で DSR を送信してお + く事はできる。 + + うーん。或いは、コマンド実行が終了した時点で char_width_mode=auto もしくは + char_width_version=auto になっている時に初めて要求を出すというのは一つの手 + である。 + + * done: refactor: 関数名を変更する c2w+ -> c2w: + 2021-09-26 * edit (command-help): use ble/util/assign/.mktmp to determine the temporary filename [#D1663] @@ -5972,6 +5990,11 @@ bash_tips version=14.0 になった。Fedora の上で実行した urxvt は 11.0 になった。ちゃ んと区別できている様だ。 + x 2021-09-26 と思ったら auto が1度処理されると二度と処理されない。 + + そもそも request が送信されていない気がする。 + →これは簡単なミスだった。修正した。 + * cmap: home/end が openSUSE で効かない (reported by cornfeedhobo) [#D1648] https://web.libera.chat/?channel=#bash-it diff --git a/src/canvas.sh b/src/canvas.sh index b6b6e535..14fb561f 100644 --- a/src/canvas.sh +++ b/src/canvas.sh @@ -47,21 +47,18 @@ function ble/util/c2w/clear-cache { ## east または west を自動判定します。 ## bleopt_char_width_mode=emacs ## emacs で用いられている既定の文字幅の設定です -## 定義 ble/util/c2w+$bleopt_char_width_mode +## 定義 ble/util/c2w:$bleopt_char_width_mode bleopt/declare -n char_width_mode auto function bleopt/check:char_width_mode { - if ! ble/is-function "ble/util/c2w+$value"; then - ble/util/print "bleopt: Invalid value char_width_mode='$value'. A function 'ble/util/c2w+$value' is not defined." >&2 + if ! ble/is-function "ble/util/c2w:$value"; then + ble/util/print "bleopt: Invalid value char_width_mode='$value'. A function 'ble/util/c2w:$value' is not defined." >&2 return 1 fi case $value in (auto) _ble_unicode_c2w_ambiguous=1 - if [[ $_ble_attached ]]; then - ble/util/c2w/test-terminal.buff first-line - ble/util/buffer.flush >&2 - fi ;; + ble && ble/util/c2w:auto/test.buff first-line ;; (west) _ble_unicode_c2w_ambiguous=1 ;; (east) _ble_unicode_c2w_ambiguous=2 ;; esac @@ -73,7 +70,7 @@ function bleopt/check:char_width_mode { function ble/util/c2w { ret=${_ble_util_c2w_cache[$1]:-${_ble_util_c2w[$1]}} if [[ ! $ret ]]; then - "ble/util/c2w+$bleopt_char_width_mode" "$1" + "ble/util/c2w:$bleopt_char_width_mode" "$1" _ble_util_c2w_cache[$1]=$ret fi } @@ -123,10 +120,7 @@ _ble_unicode_c2w_custom=() bleopt/declare -n char_width_version auto function bleopt/check:char_width_version { if [[ $value == auto ]]; then - if [[ $_ble_attached ]]; then - ble/util/c2w/test-terminal.buff first-line - ble/util/buffer.flush >&2 - fi + ble && ble/util/c2w:auto/test.buff first-line ble/util/c2w/clear-cache return 0 elif local ret; ble/unicode/c2w/version2index "$value"; then @@ -258,7 +252,7 @@ function ble/util/c2w/is-emoji { # ---- char_width_mode ---- -function ble/util/c2w+west { +function ble/util/c2w:west { if [[ $bleopt_emoji_width ]] && ble/util/c2w/is-emoji "$1"; then ((ret=bleopt_emoji_width)) else @@ -266,7 +260,7 @@ function ble/util/c2w+west { fi } -function ble/util/c2w+east { +function ble/util/c2w:east { if [[ $bleopt_emoji_width ]] && ble/util/c2w/is-emoji "$1"; then ((ret=bleopt_emoji_width)) else @@ -274,7 +268,7 @@ function ble/util/c2w+east { fi } -## @fn ble/util/c2w+emacs +## @fn ble/util/c2w:emacs ## emacs-24.2.1 default char-width-table ## @var[out] ret _ble_util_c2w_emacs_wranges=( @@ -287,7 +281,7 @@ _ble_util_c2w_emacs_wranges=( 1591 1593 1595 1597 1599 1600 1602 1603 1611 1612 1696 1698 1714 1716 1724 1726 1734 1736 1739 1740 1742 1744 1775 1776 1797 1799 1856 1857 1858 1859 1898 1899 1901 1902 1903 1904) -function ble/util/c2w+emacs { +function ble/util/c2w:emacs { local code=$1 # bash-4.0 bug workaround @@ -361,7 +355,7 @@ function ble/util/c2w+emacs { _ble_util_c2w_auto_update_x0=0 _ble_util_c2w_auto_update_result=() _ble_util_c2w_auto_update_processing=0 -function ble/util/c2w+auto { +function ble/util/c2w:auto { if [[ $bleopt_emoji_width ]] && ble/util/c2w/is-emoji "$1"; then ((ret=bleopt_emoji_width)) else @@ -369,7 +363,13 @@ function ble/util/c2w+auto { fi } -function ble/util/c2w/test-terminal.buff { +function ble/util/c2w:auto/check { + [[ $bleopt_char_width_mode == auto || $bleopt_char_width_version == auto ]] && + ble/util/c2w:auto/test.buff + return 0 +} + +function ble/util/c2w:auto/test.buff { local opts=$1 local -a DRAW_BUFF=() local ret saved_pos= @@ -409,7 +409,7 @@ function ble/util/c2w/test-terminal.buff { ble/canvas/put.draw "$_ble_term_el" ble/util/c2s $((code)) ble/canvas/put.draw "$ret" - ble/term/CPR/request.draw "ble/util/c2w/test-terminal.hook $((index++))" + ble/term/CPR/request.draw "ble/util/c2w/test.hook $((index++))" done ble/canvas/put-cup.draw 1 $((x0+1)) ble/canvas/put.draw "$_ble_term_el" @@ -419,7 +419,7 @@ function ble/util/c2w/test-terminal.buff { for code in "${codes[@]}"; do ble/util/c2s $((code)) ble/canvas/put.draw "$_ble_term_cr$_ble_term_el[$ret]" - ble/term/CPR/request.draw "ble/util/c2w/test-terminal.hook $((index++))" + ble/term/CPR/request.draw "ble/util/c2w/test.hook $((index++))" done ble/canvas/put.draw "$_ble_term_cr$_ble_term_el" fi @@ -428,11 +428,12 @@ function ble/util/c2w/test-terminal.buff { [[ $_ble_attached ]] && ble/canvas/panel/load-position.draw "$saved_pos" ble/canvas/bflush.draw } -function ble/util/c2w/test-terminal.hook { +function ble/util/c2w/test.hook { local index=$1 l=$2 c=$3 local w=$((c-1-_ble_util_c2w_auto_update_x0)) _ble_util_c2w_auto_update_result[index]=$w ((index==_ble_util_c2w_auto_update_processing-1)) || return 0 + _ble_util_c2w_auto_update_processing=0 local -a ws=("${_ble_util_c2w_auto_update_result[@]}") if [[ $bleopt_char_width_mode == auto ]]; then @@ -731,8 +732,7 @@ function ble/unicode/GraphemeCluster/match { # ble/canvas/attach function ble/canvas/attach { - [[ $bleopt_char_width_mode == auto || $bleopt_char_width_version == auto ]] && - ble/util/c2w/test-terminal.buff + ble/util/c2w:auto/check } #------------------------------------------------------------------------------ diff --git a/src/edit.sh b/src/edit.sh index 56eda14f..c3336b16 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -5387,6 +5387,7 @@ function ble-edit/exec:gexec/.end { ble-edit/bind/.check-detach && return 0 ble/term/enter ble-edit/exec:gexec/TERM/enter || return 0 # rebind に失敗した時 .tail せずに抜ける + ble/util/c2w:auto/check [[ $1 == restore ]] && return 0 # Note: 前回の呼出で .end に失敗した時 #D1170 ble-edit/bind/.tail # flush will be called here }