mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-17 13:55:08 +00:00
fix(easy-docker): handle missing terminal capabilities quietly
This commit is contained in:
parent
0a4b85f401
commit
ae75ca56e7
3 changed files with 102 additions and 7 deletions
|
|
@ -1,19 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ALT_SCREEN_ACTIVE=0
|
||||
CURSOR_HIDDEN=0
|
||||
|
||||
stdout_is_terminal() {
|
||||
[ -t 1 ]
|
||||
}
|
||||
|
||||
run_tput_quietly() {
|
||||
tput "$@" 2>/dev/null
|
||||
}
|
||||
|
||||
enter_alt_screen() {
|
||||
if [ -t 1 ] && command_exists tput; then
|
||||
tput smcup || true
|
||||
tput civis || true
|
||||
if ! stdout_is_terminal || ! command_exists tput; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if run_tput_quietly smcup; then
|
||||
ALT_SCREEN_ACTIVE=1
|
||||
fi
|
||||
|
||||
if run_tput_quietly civis; then
|
||||
CURSOR_HIDDEN=1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
leave_alt_screen() {
|
||||
if [ "${ALT_SCREEN_ACTIVE}" = "1" ] && command_exists tput; then
|
||||
tput cnorm || true
|
||||
tput rmcup || true
|
||||
ALT_SCREEN_ACTIVE=0
|
||||
if command_exists tput; then
|
||||
if [ "${CURSOR_HIDDEN}" = "1" ]; then
|
||||
run_tput_quietly cnorm || true
|
||||
fi
|
||||
|
||||
if [ "${ALT_SCREEN_ACTIVE}" = "1" ]; then
|
||||
run_tput_quietly rmcup || true
|
||||
fi
|
||||
fi
|
||||
|
||||
CURSOR_HIDDEN=0
|
||||
ALT_SCREEN_ACTIVE=0
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
|||
49
tests/easy-docker/25_screen_terminal.bats
Executable file
49
tests/easy-docker/25_screen_terminal.bats
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load 'test_helper.bash'
|
||||
|
||||
setup() {
|
||||
easy_docker_test_begin
|
||||
easy_docker_test_source_screen_modules_with_tty_stdout
|
||||
}
|
||||
|
||||
teardown() {
|
||||
easy_docker_test_end
|
||||
}
|
||||
|
||||
@test "enter_alt_screen suppresses tput stderr when terminfo is unavailable" {
|
||||
easy_docker_test_write_bin_command tput \
|
||||
'echo '"'"'tput: unknown terminal "xterm-256color"'"'"' >&2' \
|
||||
'exit 1'
|
||||
easy_docker_test_prepend_bin_dir
|
||||
|
||||
run enter_alt_screen
|
||||
[ "${status}" -eq 0 ]
|
||||
[ -z "${output}" ]
|
||||
}
|
||||
|
||||
@test "enter_alt_screen and leave_alt_screen track successful terminal state" {
|
||||
local log_file=""
|
||||
local expected_log=""
|
||||
|
||||
log_file="${EASY_DOCKER_TEST_TMPDIR}/tput.log"
|
||||
|
||||
easy_docker_test_write_bin_command tput \
|
||||
"printf '%s\\n' \"\${1:-}\" >>\"${log_file}\"" \
|
||||
'exit 0'
|
||||
easy_docker_test_prepend_bin_dir
|
||||
|
||||
enter_alt_screen
|
||||
[ "${ALT_SCREEN_ACTIVE}" = "1" ]
|
||||
[ "${CURSOR_HIDDEN}" = "1" ]
|
||||
|
||||
leave_alt_screen
|
||||
[ "${ALT_SCREEN_ACTIVE}" = "0" ]
|
||||
[ "${CURSOR_HIDDEN}" = "0" ]
|
||||
|
||||
expected_log=$'smcup\ncivis\ncnorm\nrmcup'
|
||||
|
||||
run cat "${log_file}"
|
||||
[ "${status}" -eq 0 ]
|
||||
[ "${output}" = "${expected_log}" ]
|
||||
}
|
||||
|
|
@ -136,6 +136,26 @@ easy_docker_test_source_gum_modules() {
|
|||
source "${repo_root}/scripts/easy-docker/lib/install/gum/ensure.sh"
|
||||
}
|
||||
|
||||
easy_docker_test_source_screen_modules() {
|
||||
local repo_root=""
|
||||
|
||||
repo_root="$(easy_docker_test_repo_root)"
|
||||
|
||||
easy_docker_test_source_common_modules
|
||||
|
||||
# shellcheck source=scripts/easy-docker/lib/app/screen.sh
|
||||
source "${repo_root}/scripts/easy-docker/lib/app/screen.sh"
|
||||
}
|
||||
|
||||
easy_docker_test_source_screen_modules_with_tty_stdout() {
|
||||
easy_docker_test_source_screen_modules
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
stdout_is_terminal() {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
easy_docker_test_create_repo_sandbox() {
|
||||
local sandbox_name="${1}"
|
||||
local sandbox_root=""
|
||||
|
|
|
|||
Loading…
Reference in a new issue