diff --git a/display.go b/display.go index 0769ba2..a53e06b 100644 --- a/display.go +++ b/display.go @@ -92,10 +92,12 @@ func DisplaySessionInfos(w io.Writer, sessions []SessionInfo, noColor bool, now fmt.Fprintf(w, "[%s] %s%s%s%s%s\n", stateStr, s.Cwd, branch, workspace, label, waiting) - if s.Preview != "" { - lines := strings.Split(s.Preview, "\n") - for _, line := range lines { - fmt.Fprintf(w, " %s\n", line) + lines := strings.Split(s.Preview, "\n") + for i := 0; i < previewLines; i++ { + if i < len(lines) && lines[i] != "" { + fmt.Fprintf(w, " %s\n", lines[i]) + } else { + fmt.Fprintln(w) } } } diff --git a/state.go b/state.go index 6993167..5cf1035 100644 --- a/state.go +++ b/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 } diff --git a/state_test.go b/state_test.go index 66ce4ba..9437aed 100644 --- a/state_test.go +++ b/state_test.go @@ -151,13 +151,13 @@ func TestExtractPreview(t *testing.T) { Type: "assistant", Message: &MessagePayload{ Role: "assistant", - Content: []ContentBlock{{Type: "text", Text: "Voici le resultat\nLigne 2\nLigne 3\nLigne 4\nLigne 5"}}, + Content: []ContentBlock{{Type: "text", Text: "Voici le resultat\nLigne 2\nLigne 3\nLigne 4\nLigne 5\nLigne 6\nLigne 7"}}, }, }, } preview := ExtractPreview(msgs) - want := "Voici le resultat\nLigne 2\nLigne 3" + want := "Voici le resultat\nLigne 2\nLigne 3\nLigne 4\nLigne 5" if preview != want { t.Errorf("ExtractPreview = %q, want %q", preview, want) } @@ -179,7 +179,7 @@ func TestExtractPreview_NoAssistant(t *testing.T) { } func TestExtractPreview_LongText(t *testing.T) { - // Text longer than 200 chars should be truncated + // Text longer than 300 chars should be truncated longText := "" for i := 0; i < 100; i++ { longText += "abcde " @@ -194,7 +194,7 @@ func TestExtractPreview_LongText(t *testing.T) { }} preview := ExtractPreview(msgs) - if len(preview) > 203 { // 200 + "..." + if len(preview) > 303 { // 300 + "..." t.Errorf("preview too long: %d chars", len(preview)) } if preview[len(preview)-3:] != "..." {