1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 01:19:16 +00:00

fix: use \033[2K to fully clear spinner lines and prevent text remnants

Fixes text remnants and extra blank lines when spinner messages change.

Issues fixed:
1. Text remnants when switching from longer to shorter messages (e.g., 'Cleaning...ems...')
2. Extra blank lines appearing after section headers

Root causes:
- \033[K only clears from cursor to end of line, leaving remnants when new messages are shorter
- stop_section_spinner was clearing lines even when no spinner was running

Changes:
- lib/core/base.sh:
  - Changed stop_section_spinner(), safe_clear_line(), safe_clear_lines() to use \033[2K
  - Added guard in stop_section_spinner to only clear when spinner is actually running
- lib/core/ui.sh:
  - Clear line once when starting spinner (before loop) to ensure clean start
  - Normal spinner rotation uses \r without clearing (performance optimization)

Performance: Line clearing happens only once per spinner start, not on every loop iteration.

Fixes #390
This commit is contained in:
tw93
2026-01-30 18:16:31 +08:00
parent e81be16031
commit e12a40f6bf
3 changed files with 11 additions and 9 deletions

View File

@@ -301,6 +301,9 @@ start_inline_spinner() {
[[ -z "$chars" ]] && chars="|/-\\"
local i=0
# Clear line on first output to prevent text remnants from previous messages
printf "\r\033[2K" >&2 || true
# Cooperative exit: check for stop file instead of relying on signals
while [[ ! -f "$stop_file" ]]; do
local c="${chars:$((i % ${#chars})):1}"