Skip to content

Commit 5973174

Browse files
yepzdkclaude
andcommitted
Fix raw terminal mode line breaks
Use \r\n instead of \n in RenderLive and RenderHistory when in raw terminal mode to fix display alignment issues. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0cdcd7b commit 5973174

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

internal/ui/history.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ import (
99
)
1010

1111
// RenderHistory renders the session history view with date grouping
12+
// When showFooter is true, uses \r\n for raw terminal mode
1213
func RenderHistory(sessions []session.HistorySession, days int, showFooter bool) {
14+
// Use \r\n when in interactive mode (showFooter=true means raw terminal)
15+
nl := "\n"
16+
if showFooter {
17+
nl = "\r\n"
18+
}
19+
1320
if len(sessions) == 0 {
14-
fmt.Printf("No sessions found in the past %d days.\n", days)
21+
fmt.Printf("No sessions found in the past %d days.%s", days, nl)
1522
return
1623
}
1724

1825
// Header
19-
fmt.Printf("%sSession History%s (past %d days)\n\n", Bold, Reset, days)
26+
fmt.Printf("%sSession History%s (past %d days)%s%s", Bold, Reset, days, nl, nl)
2027

2128
// Group sessions by date
2229
var currentGroup string
@@ -29,10 +36,10 @@ func RenderHistory(sessions []session.HistorySession, days int, showFooter bool)
2936
// Print date header when group changes
3037
if group != currentGroup {
3138
if currentGroup != "" {
32-
fmt.Println() // Empty line between groups
39+
fmt.Print(nl) // Empty line between groups
3340
}
34-
fmt.Printf("%s━━━ %s %s%s\n", Dim, group, strings.Repeat("━", 60-len(group)), Reset)
35-
fmt.Printf("%-27s %-10s %-10s %-6s %s\n", "PROJECT", "BRANCH", "DURATION", "MSGS", "CONTEXT")
41+
fmt.Printf("%s━━━ %s %s%s%s", Dim, group, strings.Repeat("━", 60-len(group)), Reset, nl)
42+
fmt.Printf("%-27s %-10s %-10s %-6s %s%s", "PROJECT", "BRANCH", "DURATION", "MSGS", "CONTEXT", nl)
3643
currentGroup = group
3744
}
3845

@@ -45,23 +52,24 @@ func RenderHistory(sessions []session.HistorySession, days int, showFooter bool)
4552
context = "-"
4653
}
4754

48-
fmt.Printf("%-27s %s%-10s%s %-10s %-6d %s\n",
55+
fmt.Printf("%-27s %s%-10s%s %-10s %-6d %s%s",
4956
truncate(s.Project, 27),
5057
Gray, truncate(s.GitBranch, 10), Reset,
5158
duration,
5259
s.MessageCount,
53-
truncate(context, 35))
60+
truncate(context, 35),
61+
nl)
5462

5563
totalDuration += s.Duration
5664
totalSessions++
5765
}
5866

5967
// Footer with totals
60-
fmt.Printf("\n%s%s%s\n", Dim, strings.Repeat("─", 70), Reset)
61-
fmt.Printf("%sTotal: %d sessions, %s%s\n", Dim, totalSessions, formatDuration(totalDuration), Reset)
68+
fmt.Printf("%s%s%s%s%s", nl, Dim, strings.Repeat("─", 70), Reset, nl)
69+
fmt.Printf("%sTotal: %d sessions, %s%s%s", Dim, totalSessions, formatDuration(totalDuration), Reset, nl)
6270

6371
if showFooter {
64-
fmt.Printf("\n%sPress l: live view | Ctrl+C: quit%s\n", Dim, Reset)
72+
fmt.Printf("%s%sl: live view | Ctrl+C: quit%s%s", nl, Dim, Reset, nl)
6573
}
6674
}
6775

internal/ui/ui.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func RenderJSON(sessions []session.Session) error {
6868
}
6969

7070
// RenderLive renders the live dashboard view
71+
// Uses \r\n for newlines to work correctly in raw terminal mode
7172
func RenderLive(sessions []session.Session) {
7273
// Set terminal title with status summary
7374
SetTerminalTitle(buildTerminalTitle(sessions))
@@ -76,7 +77,7 @@ func RenderLive(sessions []session.Session) {
7677
fmt.Print("\033[2J\033[H")
7778

7879
// Header
79-
fmt.Printf("%sClaude Code Sessions%s\n\n", Bold, Reset)
80+
fmt.Printf("%sClaude Code Sessions%s\r\n\r\n", Bold, Reset)
8081

8182
// Split sessions into active and inactive
8283
var active, inactive []session.Session
@@ -94,14 +95,14 @@ func RenderLive(sessions []session.Session) {
9495
fmt.Printf("%s%s Needs Input: %d%s ", Yellow, SymbolNeedsInput, counts[session.StatusNeedsInput], Reset)
9596
fmt.Printf("%s%s Waiting: %d%s ", Blue, SymbolWaiting, counts[session.StatusWaiting], Reset)
9697
fmt.Printf("%s%s Idle: %d%s ", Gray, SymbolIdle, counts[session.StatusIdle], Reset)
97-
fmt.Printf("%s%s Inactive: %d%s\n\n", Dim, SymbolInactive, len(inactive), Reset)
98+
fmt.Printf("%s%s Inactive: %d%s\r\n\r\n", Dim, SymbolInactive, len(inactive), Reset)
9899

99100
if len(active) == 0 {
100-
fmt.Printf("%sNo active Claude sessions.%s\n", Dim, Reset)
101+
fmt.Printf("%sNo active Claude sessions.%s\r\n", Dim, Reset)
101102
} else {
102103
// Column headers
103-
fmt.Printf("%-15s %-35s %-15s %s\n", "STATUS", "PROJECT", "LAST ACTIVITY", "LAST MESSAGE")
104-
fmt.Printf("%s\n", strings.Repeat("─", 95))
104+
fmt.Printf("%-15s %-35s %-15s %s\r\n", "STATUS", "PROJECT", "LAST ACTIVITY", "LAST MESSAGE")
105+
fmt.Printf("%s\r\n", strings.Repeat("─", 95))
105106

106107
for _, s := range active {
107108
symbol, color := getStatusDisplay(s.Status)
@@ -113,15 +114,15 @@ func RenderLive(sessions []session.Session) {
113114
desc = s.Task
114115
}
115116

116-
fmt.Printf("%s%s %-13s%s %-35s %-15s %s\n",
117+
fmt.Printf("%s%s %-13s%s %-35s %-15s %s\r\n",
117118
color, symbol, s.Status, Reset,
118119
formatProject(s, 35),
119120
elapsed,
120121
truncate(desc, 35))
121122
}
122123
}
123124

124-
fmt.Printf("\n%sh: history | Ctrl+C: quit%s\n", Dim, Reset)
125+
fmt.Printf("\r\n%sh: history | Ctrl+C: quit%s\r\n", Dim, Reset)
125126
}
126127

127128
// ClearScreen clears the terminal screen

0 commit comments

Comments
 (0)