Skip to content

Commit d6463ef

Browse files
committed
fix: 修复菜单重绘时内容叠加问题
根因: tput sc/rc 在 macOS 终端不兼容,导致每次重绘在下方追加新行 修复: 使用 ANSI 转义码替代 tput sc/rc - printf '\033[%dA' 上移光标 - printf '\033[2K' 清除行内容
1 parent 2ac69f7 commit d6463ef

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

dist/quickstart.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ show_profile_menu() {
395395

396396
while [[ "$running" == "true" ]]; do
397397
debug_log "绘制菜单,光标位置: $cursor"
398-
tput sc 2>/dev/null || true
399398

400399
for ((i=0; i<num; i++)); do
401400
if [[ $i -eq $cursor ]]; then
@@ -443,8 +442,12 @@ show_profile_menu() {
443442
;;
444443
esac
445444

446-
tput rc 2>/dev/null || true
447-
tput cuu $num 2>/dev/null || true
445+
# 使用 ANSI 转义码上移光标并清除行
446+
printf '\033[%dA' "$num" >&2
447+
for ((i=0; i<num; i++)); do
448+
printf '\033[2K' >&2
449+
done
450+
printf '\033[%dA' "$num" >&2
448451
done
449452

450453
tput cnorm 2>/dev/null || true
@@ -502,7 +505,6 @@ show_software_menu() {
502505

503506
while [[ "$running" == "true" ]]; do
504507
debug_log "绘制软件菜单,光标: $cursor"
505-
tput sc 2>/dev/null || true
506508

507509
for ((i=0; i<num_items; i++)); do
508510
if [[ $i -eq $cursor ]]; then
@@ -570,8 +572,12 @@ show_software_menu() {
570572
;;
571573
esac
572574

573-
tput rc 2>/dev/null || true
574-
tput cuu $num_items 2>/dev/null || true
575+
# 使用 ANSI 转义码上移光标并清除行
576+
printf '\033[%dA' "$num_items" >&2
577+
for ((i=0; i<num_items; i++)); do
578+
printf '\033[2K' >&2
579+
done
580+
printf '\033[%dA' "$num_items" >&2
575581
done
576582

577583
tput cnorm 2>/dev/null || true

0 commit comments

Comments
 (0)