fix(tui): prefer readable chat details
This commit is contained in:
parent
483fd779fb
commit
58f51dcf0b
@ -2933,7 +2933,7 @@ func (m model) chatDetailLines(item Item, width int) []string {
|
||||
if thread := m.threadLines(item, width); len(thread) > 0 {
|
||||
lines = append(lines, "", dim(tuiRule(width)), bold("Thread"))
|
||||
lines = append(lines, thread...)
|
||||
} else if message := strings.TrimSpace(firstNonEmpty(item.Text, item.Detail, item.Title)); message != "" {
|
||||
} else if message := chatBodyText(item); message != "" {
|
||||
lines = append(lines, "", dim(tuiRule(width)), bold("Message"))
|
||||
lines = append(lines, chatBubbleLines(item, message, true, width)...)
|
||||
}
|
||||
@ -3138,7 +3138,7 @@ func (m model) threadLines(selected Item, width int) []string {
|
||||
if threadKey(item) != key {
|
||||
continue
|
||||
}
|
||||
text := firstNonEmpty(item.Text, item.Detail, item.Title)
|
||||
text := chatBodyText(item)
|
||||
lines = append(lines, chatBubbleLines(item, text, item.ID == selected.ID, width)...)
|
||||
}
|
||||
if len(lines) <= 1 {
|
||||
@ -3165,6 +3165,10 @@ func chatBubbleLines(item Item, text string, selected bool, width int) []string
|
||||
return lines
|
||||
}
|
||||
|
||||
func chatBodyText(item Item) string {
|
||||
return strings.TrimSpace(firstNonEmpty(item.Detail, item.Text, item.Title))
|
||||
}
|
||||
|
||||
func chatPropertyLines(item Item) []string {
|
||||
return compactNonEmpty([]string{
|
||||
fieldLine("channel", item.Container),
|
||||
|
||||
@ -425,6 +425,20 @@ func TestChatDetailDoesNotTreatMetadataAsMessageBody(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatDetailPrefersExplicitReadableDetail(t *testing.T) {
|
||||
m := newModel(Options{
|
||||
Title: "slacrawl archive",
|
||||
Layout: LayoutChat,
|
||||
Items: []Item{
|
||||
Row{Kind: "message", ID: "m1", Container: "general", Author: "alice", Title: "raw", Text: "<@U1> raw body", Detail: "Alice readable body"}.ItemForLayout(LayoutChat),
|
||||
},
|
||||
})
|
||||
joined := stripANSI(strings.Join(m.detailLinesForWidth(m.items[0], 60), "\n"))
|
||||
if !strings.Contains(joined, "Alice readable body") || strings.Contains(joined, "<@U1> raw body") {
|
||||
t.Fatalf("chat detail should prefer readable explicit detail:\n%s", joined)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetailModeToggleUsesCompactReadableDetail(t *testing.T) {
|
||||
m := newModel(Options{
|
||||
Title: "discrawl archive",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user