From 25f6fbc47648ff6b049f46946abcfc64ca4c2cc5 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 23 Dec 2024 16:51:33 +0200 Subject: Excess messages now truncate instead of overflow viewport height --- internal/client/ui/core/chat/chat.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'internal/client/ui/core') diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index ab19069..d17b500 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -375,7 +375,25 @@ func (m *Model) renderMessages(height int) string { builder.WriteString(renderedGroups[i]) } - return builder.String() + result := builder.String() + + // Truncate any excess and show only the bottom + newlines := 0 + index := -1 + for i := len(result) - 1; i >= 0; i-- { + if result[i] == '\n' { + newlines++ + } + if newlines == height { + index = i + break + } + } + if index != -1 { + return result[index+1:] + } + + return result } func (m *Model) renderMessageGroup(group []data.Message, remaining *int, height int) string { -- cgit v1.3.1