fix: Statusline gegen Format-String-Bug und Zeilenumbruch härten

Variablen wurden bisher in den printf-Format-String interpoliert.
Pfade mit % konnten dadurch als Format-Direktive interpretiert werden
und den TUI-Renderer von claude-code aus dem Tritt bringen.

Zusätzlich werden Pfade über 25 Zeichen gekürzt, damit die Statusline
auf schmalen Terminals nicht umbricht — die zusätzliche Zeile war
der wahrscheinliche Auslöser des Render-Drifts ("Ausgabe scrollt nach
oben aus dem sichtbaren Bereich").

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 08:22:03 +02:00
co-authored by Claude Opus 4.7
parent dbd833ae5b
commit bb91f1ed9f
+16 -10
View File
@@ -18,19 +18,26 @@ IFS=$'\t' read -r current_dir model total_input total_output context_size used_p
total_tokens=$(( (total_input + total_output) / 1000 ))
context_limit_k=$(( context_size / 1000 ))
cost_formatted=$(LC_NUMERIC=C awk "BEGIN {
cents = int($cost_usd * 100 + 0.5)
if (cents < 100) printf \"%d¢\", cents
else printf \"\$%.2f\", $cost_usd
}")
cost_formatted=$(LC_NUMERIC=C awk -v cost="$cost_usd" 'BEGIN {
cents = int(cost * 100 + 0.5)
if (cents < 100) printf "%d¢", cents
else printf "$%.2f", cost
}')
user=$(whoami)
host=$(hostname -s)
# Lange Pfade kürzen, damit die Statusline nie umbricht (sonst gerät der
# claude-code-Renderer aus dem Tritt, weil er 1 Zeile am unteren Rand erwartet).
display_dir=$current_dir
if [ ${#display_dir} -gt 25 ]; then
display_dir=".../$(basename "$(dirname "$current_dir")")/$(basename "$current_dir")"
fi
git_branch=""
if [ -n "$current_dir" ] && git -C "$current_dir" rev-parse --git-dir > /dev/null 2>&1; then
branch=$(git -C "$current_dir" branch --show-current 2>/dev/null)
[ -n "$branch" ] && git_branch=" \033[33m($branch)\033[00m"
[ -n "$branch" ] && printf -v git_branch ' \033[33m(%s)\033[00m' "$branch"
fi
chroot_prefix=""
@@ -38,7 +45,6 @@ if [ -r /etc/debian_chroot ]; then
chroot_prefix="($(cat /etc/debian_chroot))"
fi
printf "${chroot_prefix}\033[32m${user}@${host}\033[00m:\033[34m${current_dir}\033[00m${git_branch}"
printf " \033[90m|\033[00m \033[36m${model}\033[00m"
printf " \033[90m|\033[00m \033[35m${total_tokens}K/${context_limit_k}K (${used_percent}%%)\033[00m"
printf " \033[90m|\033[00m \033[33m${cost_formatted}\033[00m"
printf '%s\033[32m%s@%s\033[00m:\033[34m%s\033[00m%s \033[90m|\033[00m \033[36m%s\033[00m \033[90m|\033[00m \033[35m%dK/%dK (%d%%)\033[00m \033[90m|\033[00m \033[33m%s\033[00m' \
"$chroot_prefix" "$user" "$host" "$display_dir" "$git_branch" \
"$model" "$total_tokens" "$context_limit_k" "$used_percent" "$cost_formatted"