Skip to content

Commit

Permalink
util (modifyOtherKeys): work around delayed terminal identification
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 10, 2022
1 parent 369f7c0 commit 14f3c81
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 34 deletions.
2 changes: 2 additions & 0 deletions docs/ChangeLog.md
Expand Up @@ -369,6 +369,8 @@
- history: work around broken timestamps in `HISTFILE` (reported by johnyaku) `#D1831` 5ef28eb
- progcomp: disable `command_not_found_handle` (reported by telometto, wisnoskij) `#D1834` 64d471a d5fe1d1 973ae8c
- complete: add completion integration with `zoxide` (reported by ferdinandyb) `#D1838` a96bafe
- util (`modifyOtherKeys`): work around delayed terminal identification `#D1842` XXXXXXX
- util (`modifyOtherKeys`): fix a bug that kitty protocol is never activated `#D1842` XXXXXXX

## Internal changes and fixes

Expand Down
9 changes: 9 additions & 0 deletions note.txt
Expand Up @@ -6461,6 +6461,15 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-07-11

* kitty の keyboard protocol が有効になっていなかった [#D1842]
https://github.com/akinomyoga/ble.sh/issues/209

返信を書いている時に kitty の振る舞いを確認していて気づいたのだがちゃんと
kitty Keyboard Protocol が有効になっていなかった。"push keyboard mode" の分
岐の条件が反転していた。

2022-07-10

* complete: "g add newdir/z[TAB]" とするとファイル名が消える [#D1841]
Expand Down
103 changes: 69 additions & 34 deletions src/util.sh
Expand Up @@ -6389,6 +6389,8 @@ function ble/term/DA2/notify {

# 外側の端末情報は以降では処理しない
((depth)) && return 0

ble/term/modifyOtherKeys/reset
fi

blehook/invoke DA2R
Expand Down Expand Up @@ -6503,47 +6505,79 @@ bleopt/declare -v term_modifyOtherKeys_external auto
bleopt/declare -v term_modifyOtherKeys_internal auto

_ble_term_modifyOtherKeys_current=
_ble_term_modifyOtherKeys_current_method=
_ble_term_modifyOtherKeys_current_TERM=
function ble/term/modifyOtherKeys/.update {
[[ $1 == "$_ble_term_modifyOtherKeys_current" ]] && return 0
[[ $1 == "$_ble_term_modifyOtherKeys_current" ]] &&
[[ $1 != 2 || $_ble_term_TERM == "$_ble_term_modifyOtherKeys_current_TERM" ]] &&
return 0

# Note: RLogin では modifyStringKeys (\e[>5m) も指定しないと駄目。
# また、RLogin は modifyStringKeys にすると S-数字 を
# 記号に翻訳してくれないので注意。
case $_ble_term_TERM in
(RLogin:*)
local previous=$_ble_term_modifyOtherKeys_current method
if [[ $1 == 2 ]]; then
case $_ble_term_TERM in
(RLogin:*) method=RLogin_modifyStringKeys ;;
(kitty:*)
local da2r
ble/string#split da2r ';' "$_ble_term_DA2R"
if ((da2r[2]>=23)); then
method=kitty_keyboard_protocol
else
method=kitty_modifyOtherKeys
fi ;;
(*)
method=modifyOtherKeys ;;
esac

# 別の方式で有効化されている時は先に解除しておく。
if ((_ble_term_modifyOtherKeys_current>=2)) &&
[[ $method != "$_ble_term_modifyOtherKeys_current_method" ]]
then
ble/term/modifyOtherKeys/.update 1
previous=1
fi
else
method=$_ble_term_modifyOtherKeys_current_method
fi
_ble_term_modifyOtherKeys_current=$1
_ble_term_modifyOtherKeys_current_method=$method
_ble_term_modifyOtherKeys_current_TERM=$_ble_term_TERM

case $method in
(RLogin_modifyStringKeys)
case $1 in
(0) ble/util/buffer $'\e[>5;0m' ;;
(1) ble/util/buffer $'\e[>5;1m' ;;
(2) ble/util/buffer $'\e[>5;1m\e[>5;2m' ;;
esac ;;
(kitty:*)
local da2r
ble/string#split da2r ';' "$_ble_term_DA2R"
if ((da2r[2]>=23)); then
# Note: Kovid removed the support for modifyOtherKeys in kitty 0.24 after
# vim has pointed out the quirk of kitty. The kitty keyboard mode only
# has push/pop operations so that their numbers need to be balanced.
case $1 in
(0|1) # pop keyboard mode
# When this is empty, ble.sh has not yet pushed any keyboard modes, so
# we just ignore the keyboard mode change.
[[ $_ble_term_modifyOtherKeys_current ]] || return 0

((_ble_term_modifyOtherKeys_current>=2)) &&
ble/util/buffer $'\e[<u' ;;
(2) # push keyboard mode
((_ble_term_modifyOtherKeys_current>=2)) &&
ble/util/buffer $'\e[>1u' ;;
esac
else
# Note #D1549: 1 では無効にならない。変な振る舞い。
# Note #D1626: 更に最近の kitty では \e[>4;0m でも駄目で \e[>4m としなければならない様だ。
case $1 in
(0|1) ble/util/buffer $'\e[>4;0m\e[>4m' ;;
(2) ble/util/buffer $'\e[>4;1m\e[>4;2m\e[m' ;;
esac
fi
_ble_term_modifyOtherKeys_current=$1
esac
;; # fallback to modifyOtherKeys
(kitty_modifyOtherKeys)
# Note: kitty has quirks in its implementation of modifyOtherKeys.
# Note #D1549: 1 では無効にならない。変な振る舞い。
# Note #D1626: 更に最近の kitty では \e[>4;0m でも駄目で \e[>4m としなければならない様だ。
case $1 in
(0|1) ble/util/buffer $'\e[>4;0m\e[>4m' ;;
(2) ble/util/buffer $'\e[>4;1m\e[>4;2m\e[m' ;;
esac
return 0 ;;
(kitty_keyboard_protocol)
# Note: Kovid removed the support for modifyOtherKeys in kitty 0.24 after
# vim has pointed out the quirk of kitty. The kitty keyboard mode only
# has push/pop operations so that their numbers need to be balanced.
case $1 in
(0|1) # pop keyboard mode
# When this is empty, ble.sh has not yet pushed any keyboard modes, so
# we just ignore the keyboard mode change.
[[ $previous ]] || return 0

((previous>=2)) &&
ble/util/buffer $'\e[<u' ;;
(2) # push keyboard mode
((previous>=2)) ||
ble/util/buffer $'\e[>1u' ;;
esac
return 0 ;;
esac

Expand All @@ -6556,8 +6590,6 @@ function ble/term/modifyOtherKeys/.update {
(1) ble/util/buffer $'\e[>4;1m\e[m' ;;
(2) ble/util/buffer $'\e[>4;1m\e[>4;2m\e[m' ;;
esac

_ble_term_modifyOtherKeys_current=$1
}
function ble/term/modifyOtherKeys/.supported {
# libvte は SGR(>4) を直接画面に表示してしまう。
Expand Down Expand Up @@ -6600,6 +6632,9 @@ function ble/term/modifyOtherKeys/leave {
fi
ble/term/modifyOtherKeys/.update "$value"
}
function ble/term/modifyOtherKeys/reset {
ble/term/modifyOtherKeys/.update "$_ble_term_modifyOtherKeys_current"
}

#---- Alternate Screen Buffer mode --------------------------------------------

Expand Down

0 comments on commit 14f3c81

Please sign in to comment.