Skip to content

Commit

Permalink
canvas (c2w:auto): send "DSR(6)" in the internal state
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Oct 4, 2021
1 parent 1af0800 commit a3047f5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
5 changes: 3 additions & 2 deletions docs/ChangeLog.md
Expand Up @@ -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 <kbd>DSR(6)</kbd> 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
Expand Down
23 changes: 23 additions & 0 deletions note.txt
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
46 changes: 23 additions & 23 deletions src/canvas.sh
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -258,23 +252,23 @@ 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
ble/unicode/c2w "$1"
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
ble/unicode/c2w "$1"
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=(
Expand All @@ -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
Expand Down Expand Up @@ -361,15 +355,21 @@ 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
ble/unicode/c2w "$1"
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=
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

#------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/edit.sh
Expand Up @@ -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
}
Expand Down

0 comments on commit a3047f5

Please sign in to comment.