Skip to content

Commit

Permalink
canvas (auto c2w): work around combining chars applied to the previou…
Browse files Browse the repository at this point in the history
…s line
  • Loading branch information
akinomyoga committed Sep 21, 2021
1 parent c4d28f4 commit 1cbbecb
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
2 changes: 2 additions & 0 deletions memo/ChangeLog.md
Expand Up @@ -60,6 +60,8 @@
- 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` 0000000
- canvas (auto c2w): avoid duplicate requests `#D1649` 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
Expand Down
51 changes: 51 additions & 0 deletions note.txt
Expand Up @@ -5374,6 +5374,57 @@ bash_tips

2021-09-21

* contra oldbug: どうも新しい c2w が問題を起こしている [#D1649]

一番怪しいのは幅の自動判定である → 取り敢えず char_width_version を別の値
に設定すればずれは生じない事を確認した。最悪の場合には既定値を適当に設定す
る事にすれば良い。

% contra では問題は発生しない。という事は受信時の処理で何かがずれているという
% 事だろうか。というより contra も DSR(6) に対応した筈なのに反応していないの
% は何かと思ったら、実はそもそも最新版の contra に入れ替えていなかった。
% 2020-10 の contra を使っていた。contra を差し替えたら問題が消えてしまった。
%
% つまり screen と contra の不整合によって行がずれていただけという事だろうか。
% 取り敢えずこれは無視する事にする。

どうも Linux 上で動かしている時には問題は起こらないが、Cygwin 上で動かして
いると問題が生じる様である。screen / contra で発生する。contra, mintty,
screen / mintty では発生しない。うーん。tmux / contra でも発生しない。

screen で C-a C-a C-a C-a で一旦別の window に行って戻ってくると内容が変わっ
ている。つまり、これは screen の中の端末状態と contra の端末状態がずれてい
るという問題である。特に、screen に於いて変な濁点のような物が行末で出力され
ていて、contra は改行していると思っていて、screen は改行していないと思って
いる気がする。改めて座標計算を弄って調整する必要がある気がする。

どうやら問題の文字を出力すると発生するという事は確かだが不思議な現象が発生
している。問題の文字を出力しない様に ble.sh を修正すると、次の一回は未だ問
題が再現するが、それ以降は再現しなくなる。どういう事だろうか。。うーん。こ
れは単に画面上に問題の文字が残っていて既存の文字の振る舞いを見出していると
いう事の気がする。

また CPR を要求しなくても問題が発生しているので、これは DSR や CPR の問題で
はなくて純粋に文字列を出力した時の振る舞いが問題になっている。

うーん。0x3099 が問題の文字である。もしかすると行頭で 0x3099 を実行するとカー
ソルが前の位置に移動してしまうという事なのかもしれない。[] で囲んで出力する
様に修正したら問題なく動く様になった。

* char_width_{mode=auto,version=auto} とすると重複して要求が走ってしまう。
要求を省略する事はできないか。一つの方法は test-terminal.buff (旧
update.buff) を呼び出す前に未だ処理中であれば test-terminal.buff を呼び出
さないという物。というか、test-terminal.buff の側で処理中かどうかを検出す
れば良い気がする。

取り敢えず DSR を送った回数を記録しておいて、同じ数だけ CPR を受信した時
点で処理完了という事にする様に修正した。

動作確認もしておきたい。先ずは VoidLinux の各端末で version 判定できてい
るか確認する。OK. urxvt, st は version=13.0 で gnome-terminal は
version=14.0 になった。Fedora の上で実行した urxvt は 11.0 になった。ちゃ
んと区別できている様だ。

* cmap: home/end が openSUSE で効かない (reported by cornfeedhobo) [#D1648]
https://web.libera.chat/?channel=#bash-it

Expand Down
25 changes: 19 additions & 6 deletions src/canvas.sh
Expand Up @@ -360,6 +360,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 {
if [[ $bleopt_emoji_width ]] && ble/util/c2w/is-emoji "$1"; then
((ret=bleopt_emoji_width))
Expand All @@ -372,6 +373,11 @@ function ble/util/c2w/test-terminal.buff {
local opts=$1
local -a DRAW_BUFF=()
local ret saved_pos=

# 現在既に処理中の場合 DSR は省略。char_width_@=auto 等で一括して要
# 求した時などに一回だけ実行する為。
((_ble_util_c2w_auto_update_processing)) && return 0

[[ $_ble_attached ]] && { ble/canvas/panel/save-position goto-top-dock; saved_pos=$ret; }
ble/canvas/put.draw "$_ble_term_sc"
if ble/util/is-unicode-output; then
Expand All @@ -389,6 +395,7 @@ function ble/util/c2w/test-terminal.buff {
0x9FCD 0x1F93B 0x312E 0x312F 0x16FE2
0x32FF 0x31BB 0x9FFD)

_ble_util_c2w_auto_update_processing=${#codes[@]}
_ble_util_c2w_auto_update_result=()
if [[ :$opts: == *:first-line:* ]]; then
# 画面の右上で判定を行います。
Expand All @@ -407,13 +414,14 @@ function ble/util/c2w/test-terminal.buff {
ble/canvas/put-cup.draw 1 $((x0+1))
ble/canvas/put.draw "$_ble_term_el"
else
_ble_util_c2w_auto_update_x0=0
_ble_util_c2w_auto_update_x0=2
local code index=0
for code in "${codes[@]}"; do
ble/util/c2s $((code))
ble/canvas/put.draw "$_ble_term_cr$_ble_term_el$ret"
ble/canvas/put.draw "$_ble_term_cr$_ble_term_el[$ret]"
ble/term/CPR/request.draw "ble/util/c2w/test-terminal.hook $((index++))"
done
ble/canvas/put.draw "$_ble_term_cr$_ble_term_el"
fi
fi
ble/canvas/put.draw "$_ble_term_rc"
Expand All @@ -424,14 +432,18 @@ function ble/util/c2w/test-terminal.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
if ((index==0)) && [[ $bleopt_char_width_mode == auto ]]; then
if ((w==2)); then
((index==_ble_util_c2w_auto_update_processing-1)) || return 0

local -a ws=("${_ble_util_c2w_auto_update_result[@]}")
if [[ $bleopt_char_width_mode == auto ]]; then
if ((ws[0]==2)); then
bleopt char_width_mode=east
else
bleopt char_width_mode=west
fi
elif ((index==13)) && [[ $bleopt_char_width_version == auto ]]; then
local -a ws=("${_ble_util_c2w_auto_update_result[@]}")
fi

if [[ $bleopt_char_width_version == auto ]]; then
if ((ws[12]==2)); then
if ((ws[13]==2)); then
bleopt char_width_version=14.0
Expand Down Expand Up @@ -466,6 +478,7 @@ function ble/util/c2w/test-terminal.hook {
bleopt char_width_version=4.1
fi
fi
return 0
}

bleopt/declare -v grapheme_cluster extended
Expand Down

0 comments on commit 1cbbecb

Please sign in to comment.