Skip to content

Commit

Permalink
util: fix a bug that old tty is used in new sessions (fixup 98835b5)
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 29, 2021
1 parent c2a84a2 commit 0e55b8e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
7 changes: 4 additions & 3 deletions memo/ChangeLog.md
Expand Up @@ -46,8 +46,8 @@
- util (`bleopt`): support option `-r` and `-u` and wildcards in option names
- util (`blehook`): hide internal hooks by default and support option `-a`
- util, color: fix argument analysis of `bleopt`, `blehook`, and `ble-face` (fixup c94d292) `#D1571` bb53271
- progcomp: support quoted commands and better `progcomp_alias` `#D1581` `#D1583` 0000000
- syntax: highlight quotes of the `\?` form `#D1584` 0000000
- progcomp: support quoted commands and better `progcomp_alias` `#D1581` `#D1583` dbe87c3
- syntax: highlight quotes of the `\?` form `#D1584` 5076a03

## Changes

Expand Down Expand Up @@ -139,7 +139,7 @@
- main: work around MSYS2 .inputrc (reported by n1kk) `#D1534` 9e786ae
- util (`modifyOtherKeys`): work around a quirk of Kitty (reported by NoahGorny) `#D1549` f599525
- global: work around empty `vi_imap` cache by `tmux-resurrect` `#D1562` 560160b
- decode: identify `kitty` and treat `\e[27u` as isolated ESC (reported by lyiriyah) [#D1585]
- decode: identify `kitty` and treat `\e[27u` as isolated ESC (reported by lyiriyah) `#D1585` c2a84a2

## Internal changes and fixes

Expand All @@ -163,6 +163,7 @@
- util (`ble/util/assign`): work around subshell conflicts `#D1578` 6e4bb12
- test (`test-canvas`): fix dependency on `ext/contra` `#D1525` c89aa23
- util: inherit special file descriptors `#D1552` 98835b5
- util: fix a bug that old tty is used in new sessions `#D1586` 0000000
- global: use `_ble_term_IFS` `#D1557` d23ad3c
- global: work around `localvar_inherit` for varname-list init `#D1566` 5c2edfc
- util: fix `ble/util/dense-array#fill-range` a46fdaf
Expand Down
24 changes: 24 additions & 0 deletions note.txt
Expand Up @@ -1442,8 +1442,22 @@ bash_tips

2021-05-29

* bleopt: wildcard を使った時に obsoleted な物も列挙されている
複数単語に展開された時にはフィルタする様にしたら良い。

* syntax: 単語が sabbrev に一致する場合には着色するのが親切だ

これは sabbrev に対する仕様拡張を行ってからでも遅くないのではないか。
ble/syntax/progcolor/word:default 辺りに修正を加えれば良い。
本来は progcolor よりも上の枠組みで着色したい気もするが
それだと layer を増やす必要がある。処理が重くなりそうである。

check-sabbrev 的な感じで付加的な処理として実装できれば良い。
そうすれば custom な着色関数からでも呼び出せる。
と思ったがちゃんと忘れずに呼び出すのも面倒である。
やはりもっと下の枠組みで提供するべきだろうか。
例えば、最終的に着色を格納する部分に介入してしまうという手もある。

2021-05-28

* 最下行で ble-reload すると statusline が重複してしまう。ble-detach して
Expand Down Expand Up @@ -4692,6 +4706,16 @@ bash_tips

2021-05-30

* util: stdin, stdout が継承されて新しい端末を開いても元端末に表示される [#D1586]

これは問題だ。取り敢えず inherit は基本的に止める方が良いのだろうか。
指定した fd が別の fd と一致しているかどうかを判定する方法は存在するだろうか。
というか端末 tty の結果が変わったら継承しないという具合にするのが良い気がする。
端末 tty を取得する方法はコマンド tty を実行するしかないのだろうか。

というか別に現在の 0 が端末であれば普通に上書きすれば良い気がする。
その様に修正した。

* decode: Kitty の modifyOtherKeys でまた問題が生じている (reported by lyiriyah) [#D1585]
https://github.com/akinomyoga/ble.sh/issues/118

Expand Down
24 changes: 16 additions & 8 deletions src/util.sh
Expand Up @@ -2785,16 +2785,21 @@ function ble/fd#alloc/.nextfd {
## @param[in] redirect
## リダイレクトを指定します。
## @param[in,opt] opts
## export
## 指定した変数を export します。
## inherit
## 既に fdvar が存在して有効な fd であれば何もしません。新しく fd を確保
## した場合には終了処理を登録せず、また fdvar を export します
## した場合には終了処理を登録しません。また上記の export を含みます
## share
## >&NUMBER の形式のリダイレクトの場合に fd を複製する代わりに単に NUMBER
## を fdvar に代入します。
## overwrite
## 既に fdvar が存在する場合その fd を上書きします。
_ble_util_openat_fdlist=()
function ble/fd#alloc {
local _ble_local_preserve=
if [[ :$3: == *:inherit:* ]]; then
[[ ${!1} ]] &&
[[ ${!1-} ]] &&
ble/fd#is-open "${!1}" &&
return 0
fi
Expand All @@ -2807,7 +2812,10 @@ function ble/fd#alloc {
fi
fi

if ((_ble_bash>=40100)) && [[ :$3: != *:base:* ]]; then
if [[ ${!1-} && :$3: == *:overwrite:* ]]; then
_ble_local_preserve=1
builtin eval "exec ${!1}$2"
elif ((_ble_bash>=40100)) && [[ :$3: != *:base:* ]]; then
builtin eval "exec {$1}$2"
else
ble/fd#alloc/.nextfd "$1"
Expand All @@ -2816,9 +2824,9 @@ function ble/fd#alloc {
builtin eval "exec ${!1}>&- ${!1}$2"
fi; local _ble_local_ext=$?

if [[ :$3: == *:inherit:* ]]; then
if [[ :$3: == *:inherit:* || :$3: == *:export:* ]]; then
export "$1"
else
elif [[ ! $_ble_local_preserve ]]; then
ble/array#push _ble_util_openat_fdlist "${!1}"
fi
return "$_ble_local_ext"
Expand Down Expand Up @@ -2846,17 +2854,17 @@ function ble/fd#close {
## @var _ble_util_fd_zero
## 既に定義されている場合は継承する
if [[ -t 0 ]]; then
ble/fd#alloc _ble_util_fd_stdin '<&0' base:inherit
ble/fd#alloc _ble_util_fd_stdin '<&0' base:overwrite:export
else
ble/fd#alloc _ble_util_fd_stdin '< /dev/tty' base:inherit
fi
if [[ -t 1 ]]; then
ble/fd#alloc _ble_util_fd_stdout '>&1' base:inherit
ble/fd#alloc _ble_util_fd_stdout '>&1' base:overwrite:export
else
ble/fd#alloc _ble_util_fd_stdout '> /dev/tty' base:inherit
fi
if [[ -t 2 ]]; then
ble/fd#alloc _ble_util_fd_stderr '>&2' base:inherit
ble/fd#alloc _ble_util_fd_stderr '>&2' base:overwrite:export
else
ble/fd#alloc _ble_util_fd_stderr ">&$_ble_util_fd_stdout" base:inherit:share
fi
Expand Down

0 comments on commit 0e55b8e

Please sign in to comment.