Skip to content

Commit

Permalink
global: avoid directly using "/dev/tty"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 1, 2023
1 parent 8683c84 commit a835b83
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contrib
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -547,6 +547,7 @@
- util: support `bleopt debug_idle` `#D1945` fa10184
- global: work around bash-4.4 no-argument return in trap `#D1970` eb4ffce
- util: replace builtin `readonly` with a shell function (requested by mozirilla213) `#D1985` xxxxxxx
- global: avoid directly using `/dev/tty` `#D1986` xxxxxxx

## Contrib

Expand Down
2 changes: 1 addition & 1 deletion lib/core-complete.sh
Expand Up @@ -1528,7 +1528,7 @@ function ble/complete/action/quote-insert.batch/proc {
local fname_cands=$_ble_local_tmpfile
ble/util/conditional-sync \
'ble/complete/action/quote-insert.batch/awk < "$fname_cands"' \
'! ble/complete/check-cancel < /dev/tty' '' progressive-weight
'! ble/complete/check-cancel <&"$_ble_util_fd_stdin"' '' progressive-weight
local ext=$?

ble/util/assign/.rmtmp
Expand Down
11 changes: 9 additions & 2 deletions make_command.sh
Expand Up @@ -1129,8 +1129,15 @@ function sub:scan/check-todo-mark {
}
function sub:scan/a.txt {
echo "--- $FUNCNAME ---"
grc --color --exclude=./{test,ext} --exclude=./lib/test-*.sh --exclude=./make_command.sh --exclude=\*.md 'a\.txt|/dev/(pts/|pty)[0-9]*' |
grep -Ev "$rex_grep_head#|[[:space:]]#|DEBUG_LEAKVAR"
grc --color --exclude={test,ext,./lib/test-\*.sh,./make_command.sh,\*.md} --exclude=check-mem.sh 'a\.txt|/dev/(pts/|pty)[0-9]*|/dev/tty' |
sed -E 'h;s/'"$_make_rex_escseq"'//g
\Z^\./memo/Zd
s/^[^:]*:[0-9]+:[[:space:]]*//
\Z^[[:space:]]*#Zd
\ZDEBUG_LEAKVARZd
\Z\[\[ -t 4 && -t 5 ]]Zd
\Z^ble/fd#alloc .*Zd
g'
}

function sub:scan/bash300bug {
Expand Down
3 changes: 3 additions & 0 deletions note.txt
Expand Up @@ -6661,6 +6661,9 @@ bash_tips

2023-03-01

* global: コード中の /dev/tty は予め持っておいた fd に置き換えるべきなのでは [#D1986]
修正した。

* util: readonly を上書きする? (reqeusted by mozirilla213) [#D1985]
https://github.com/akinomyoga/ble.sh/issues/289

Expand Down
14 changes: 7 additions & 7 deletions src/edit.sh
Expand Up @@ -380,7 +380,7 @@ function ble/application/onwinch {
if ((50200<=_ble_bash&&_ble_bash<50300)); then
# Note: bash-5.2 では trap string / bind -x 内部で COLUMNS/LINES が更新さ
# れないので "$BASH" を起動して端末サイズを取得する。
builtin eval -- "$(ble/util/msleep 50; exec "$BASH" -O checkwinsize -c '(:); [[ $COLUMNS && $LINES ]] && printf %s "COLUMNS=$COLUMNS LINES=$LINES"' 2>/dev/tty)"
builtin eval -- "$(ble/util/msleep 50; exec "$BASH" -O checkwinsize -c '(:); [[ $COLUMNS && $LINES ]] && printf %s "COLUMNS=$COLUMNS LINES=$LINES"' 2>&"$_ble_util_fd_stderr")"
else
# 次の WINCH を待つと共にサブシェルで checkwinsize を誘発
(ble/util/msleep 50)
Expand Down Expand Up @@ -737,7 +737,7 @@ function ble/prompt/unit#update/.update-dependencies {
local ble_prompt_unit_processing=1
"${_ble_util_set_declare[@]//NAME/ble_prompt_unit_mark}" # WA #D1570 checked
elif ble/set#contains ble_prompt_unit_mark "$unit"; then
ble/util/print "ble/prompt: FATAL: detected cyclic dependency ($unit required by $ble_prompt_unit_parent)" >/dev/tty
ble/util/print "ble/prompt: FATAL: detected cyclic dependency ($unit required by $ble_prompt_unit_parent)" >&"$_ble_util_fd_stderr"
return 1
fi
local ble_prompt_unit_parent=$unit
Expand Down Expand Up @@ -1640,7 +1640,7 @@ if ble/is-function ble/util/idle.push; then
builtin exit 0 &>/dev/null
builtin exit 0 &>/dev/null' pre-flush
return 1 # exit に失敗した時
} >/dev/tty
} >&"$_ble_util_fd_stdout" 2>&"$_ble_util_fd_stderr"
function ble/prompt/timeout/check {
[[ $_ble_edit_lineno == "$_ble_prompt_timeout_lineno" ]] && return 0
_ble_prompt_timeout_lineno=$_ble_edit_lineno
Expand Down Expand Up @@ -6088,7 +6088,7 @@ function ble/exec/time/times.parse-time {
local msc=$((10#0${BASH_REMATCH[3]#?}))
((ret=(min*60+sec)*1000+msc))
return 0
} 2>/dev/tty
} 2>&"$_ble_util_fd_stderr"
function ble/exec/time/times.start {
builtin times >| "$_ble_exec_time_TIMES"
}
Expand Down Expand Up @@ -6442,13 +6442,13 @@ function ble-edit/exec:gexec/.TRAPDEBUG {
local sep=${_ble_term_setaf[6]}:
local lineno=${_ble_term_setaf[2]}${BLE_TRAP_LINENO[0]}
local func=${_ble_term_setaf[6]}' ('${_ble_term_setaf[4]}${BLE_TRAP_FUNCNAME[0]}${1:+ $1}${_ble_term_setaf[6]}')'
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$lineno$func$_ble_term_sgr0" >/dev/tty
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$lineno$func$_ble_term_sgr0" >&"$_ble_util_fd_stderr"
_ble_builtin_trap_postproc[_ble_trap_sig]="{ return $_ble_edit_exec_TRAPDEBUG_INT || break; } &>/dev/null"
elif ((depth==0)) && ! ble/string#match "$_ble_trap_bash_command" '^ble-edit/exec:gexec/\.'; then
# 一番外側で、ble-edit/exec:gexec/. 関数ではない時
local source=${_ble_term_setaf[5]}global
local sep=${_ble_term_setaf[6]}:
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$_ble_term_sgr0 $_ble_trap_bash_command" >/dev/tty
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$_ble_term_sgr0 $_ble_trap_bash_command" >&"$_ble_util_fd_stderr"
_ble_builtin_trap_postproc[_ble_trap_sig]="break &>/dev/null"
fi

Expand Down Expand Up @@ -6555,7 +6555,7 @@ function ble-edit/exec:gexec/.TRAPINT {
_ble_edit_exec_TRAPDEBUG_INT=$ext
ble-edit/exec:gexec/.TRAPDEBUG/trap
else
_ble_builtin_trap_postproc="{ return $ext || break; } &>/dev/tty"
_ble_builtin_trap_postproc="{ return $ext || break; } 2>&$_ble_util_fd_stderr"
fi
}
function ble-edit/exec:gexec/.TRAPINT/reset {
Expand Down
2 changes: 1 addition & 1 deletion src/history.sh
Expand Up @@ -100,7 +100,7 @@ if ((_ble_bash<40000)); then
true 100 progressive-weight:timeout=3000:SIGKILL
local ext=$?
if ((ext==142)); then
printf 'ble.sh: timeout: builtin history %s' "$*" >/dev/tty
printf 'ble.sh: timeout: builtin history %s' "$*" >&"$_ble_util_fd_stderr"
local ret=11
ble/builtin/trap/sig#resolve SIGSEGV
((ext=128+ret))
Expand Down

0 comments on commit a835b83

Please sign in to comment.