feat: stabilize list output with fixed-height preview (5 lines, 300 chars)
Each session always occupies the same number of lines, preventing visual jitter between watch refreshes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
15
state.go
15
state.go
@@ -64,7 +64,7 @@ func DetectState(messages []JSONLMessage, now time.Time) SessionState {
|
||||
}
|
||||
|
||||
// ExtractPreview finds the last assistant text content and returns the first
|
||||
// 3 lines, truncated to 200 characters.
|
||||
// 5 lines, truncated to 300 characters.
|
||||
func ExtractPreview(messages []JSONLMessage) string {
|
||||
for i := len(messages) - 1; i >= 0; i-- {
|
||||
msg := messages[i]
|
||||
@@ -80,15 +80,18 @@ func ExtractPreview(messages []JSONLMessage) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
const previewLines = 5
|
||||
const previewMaxChars = 300
|
||||
|
||||
func truncatePreview(text string) string {
|
||||
lines := strings.SplitN(text, "\n", 4)
|
||||
if len(lines) > 3 {
|
||||
lines = lines[:3]
|
||||
lines := strings.SplitN(text, "\n", previewLines+1)
|
||||
if len(lines) > previewLines {
|
||||
lines = lines[:previewLines]
|
||||
}
|
||||
result := strings.Join(lines, "\n")
|
||||
|
||||
if len(result) > 200 {
|
||||
result = result[:200] + "..."
|
||||
if len(result) > previewMaxChars {
|
||||
result = result[:previewMaxChars] + "..."
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user