Skip to content

Commit edb21da

Browse files
committed
stty: avoid adjusting the "stty" state if it has never been modified
1 parent 38fe52b commit edb21da

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

docs/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
- syntax: fix infinite loop with `case a in \^J` `#D2361` 173ec27f
184184
- util (`ble/util/writearray`): fix a bug in use of gensub in gawk (reported by allenap, LeonardoMor, aaronjamt, ionesculiviucristian, Gabryx64) `#D2368`
185185
- complete: fix a bug that `mandb` record is generated as completions (reported by allenap) `#D2369` xxxxxxxx
186+
- stty: avoid adjusting the `stty` state if it has never been modified (reported by LEI) `#D2376` xxxxxxxx
186187

187188
## Compatibility
188189

note.txt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7950,6 +7950,46 @@ bash_tips
79507950
Done (実装ログ)
79517951
-------------------------------------------------------------------------------
79527952

7953+
2025-07-22
7954+
7955+
* stty: bash out/ble.sh --install で stty を呼び出している (reported by LEI) [#D2376]
7956+
https://github.com/akinomyoga/ble.sh/issues/609
7957+
7958+
本来は単にコマンドを実行するだけなので stty 等を変更する必要はない筈。これ
7959+
は再現できたので修正する。
7960+
7961+
どうやら EXIT -> ble/util/unload -> ble/term/stty/TRAPEXIT と呼び出している
7962+
様である。そもそも ble/util/unload は実際に line editor として使っていた時
7963+
の unload 用の関数である。という事を考えると、コマンド実行の時には処理する
7964+
必要性はないのではないか? と思ったが諸々の fd の処理や run の cleanup の事
7965+
を考えるとやはり処理の一部は --lib モードであったとしても実行するべき?
7966+
7967+
a 一つの方法は --lib モードで読み込んだ場合には unload の処理はスキップする
7968+
という方針。然し
7969+
7970+
b もう一つの方法は --lib モードで読み込んだ場合には unload は実行するけれど
7971+
も ble/term/stty/TRAPEXIT は省略するという方針。然し、この場合 --lib で読
7972+
み込んだ後に attach したり、将来的に textarea を部品として用いた時に
7973+
ble/term/stty の設定が残留してしまう原因になる。
7974+
7975+
c 或いは、一度でも ble/term/stty で設定を変更した事があれば ble/term/stty
7976+
を使って元に戻す処理を実行する? これの場合には一度でも呼び出されたという
7977+
事を記録しておく必要がある。
7978+
7979+
現状はどうなっていただろうか。現在の状態は _ble_term_stty_state で状態を
7980+
管理している。但し、 1 か空文字列かで区別している為、external/internal の
7981+
区別しかなくて、一度でも stty を調整したかどうかについては現状では分から
7982+
ない。
7983+
7984+
d 或いは 0 が tty に繋がっていれば強制的に ble/term/stty/TRAPEXIT を実行す
7985+
る。しかし、これだと一度も stty で状態を変更していないのに bash
7986+
out/ble.sh ... を実行しただけで stty の状態が変更されるということになる。
7987+
これは余り好ましくない。stty に関係のない処理を実行するだけで stty を触っ
7988+
てしまうのは良くない。
7989+
7990+
取り敢えず c の方針で実装した。_ble_term_stty_state は既定では空文字列で、
7991+
一度でも stty に触れたら 0 または 1 の値を持つように変更する事にした。
7992+
79537993
2025-07-20
79547994

79557995
* util (is-stdin-ready): sudo cmd ... の補完が動かなくなっている (reported by Jai-JAP, darukutsu) [#D2375]
@@ -17302,7 +17342,7 @@ bash_tips
1730217342
ている様な気がする。或いは、stty sane を実行する必要があるのだろうか?
1730317343
stty echo では駄目?
1730417344

17305-
そもそも問題のメッセージは ble/util/stty/TRAPEXIT の中から出力されている
17345+
そもそも問題のメッセージは ble/term/stty/TRAPEXIT の中から出力されている
1730617346
ので、この関数が呼び出されていないという事はないだろう。
1730717347

1730817348
うーん。どうも stty sane をより上で実行しても効果がない様だ。つまり、何処

src/util.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6878,7 +6878,11 @@ function bleopt/check:term_stty_restore {
68786878
}
68796879

68806880
## @var _ble_term_stty_state
6881-
## 現在 stty で制御文字の効果が解除されているかどうかを保持します。
6881+
## This variable retains the current stty state, such as whether effects of
6882+
## special control characters are turned off. When ble.sh has not modified
6883+
## the stty state, the variable is empty, "". When ble.sh has modified the
6884+
## stty for the internal state, the variable is set to "1". When ble.sh has
6885+
## modified the stty for the external state, the variable is set to "0".
68826886
##
68836887
## Note #D1238: arr=(...) の形式を用いると Bash 3.2 では勝手に ^? が ^A^? に化けてしまう
68846888
## 仕方がないので此処では ble/array#push を使って以下の配列を初期化する事にする。
@@ -6929,9 +6933,8 @@ function ble/term/stty/initialize {
69296933
_ble_term_stty_state=1
69306934
}
69316935
function ble/term/stty/leave {
6932-
[[ ! $_ble_term_stty_state ]] && return 0
6933-
_ble_term_stty_state=
6934-
6936+
((_ble_term_stty_state)) || return 0
6937+
_ble_term_stty_state=0
69356938
if [[ $bleopt_term_stty_restore && $_ble_term_stty_save ]]; then
69366939
ble/bin/stty "$_ble_term_stty_save"
69376940
else
@@ -6943,7 +6946,7 @@ function ble/term/stty/enter {
69436946
# around the problem that "checkwinsize" does not work in "bind -x" in Bash
69446947
# 5.2. The changes to this function needs to be also reflected in the later
69456948
# overwriting version of "ble/term/stty/enter".
6946-
[[ $_ble_term_stty_state ]] && return 0
6949+
((_ble_term_stty_state)) && return 0
69476950
if [[ $bleopt_term_stty_restore ]]; then
69486951
ble/term/stty/initialize
69496952
else
@@ -6956,12 +6959,19 @@ function ble/term/stty/finalize {
69566959
_ble_term_stty_save=
69576960
}
69586961
function ble/term/stty/TRAPEXIT {
6962+
if [[ ! $_ble_term_stty_state ]]; then
6963+
# Note: The empty "_ble_term_stty_state" means that the stty state has
6964+
# never been touched by ble.sh, so we do nothing in that case.
6965+
return 0
6966+
fi
6967+
69596968
# exit の場合は echo
69606969
if [[ $bleopt_term_stty_restore && $_ble_term_stty_save ]]; then
69616970
ble/bin/stty "$_ble_term_stty_save"
69626971
else
69636972
ble/bin/stty echo -nl "${_ble_term_stty_flags_leave[@]}"
69646973
fi
6974+
_ble_term_stty_state=0
69656975
}
69666976

69676977
function ble/term/update-winsize {
@@ -7074,7 +7084,7 @@ if ((50200<=_ble_bash&&_ble_bash<50300)); then
70747084
then
70757085
LINES=${ret[0]} COLUMNS=${ret[1]}
70767086
function ble/term/stty/enter {
7077-
[[ $_ble_term_stty_state ]] && return 0
7087+
((_ble_term_stty_state)) && return 0
70787088
local ret
70797089
if [[ $bleopt_term_stty_restore ]]; then
70807090
ble/term/stty/initialize

0 commit comments

Comments
 (0)