wrap text in entry view

This commit is contained in:
Travis Shears 2025-10-05 16:47:03 +02:00
parent dc635db758
commit 0048f4a7ce
3 changed files with 12 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/wordwrap"
)
type EntryPageModel struct {
@ -20,6 +21,10 @@ func initialEntryPageModel() EntryPageModel {
return EntryPageModel{}
}
func wrapGemtxt(gemtxt string, width int) string {
return wordwrap.String(gemtxt, width)
}
func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPageModel, tea.Cmd) {
var (
cmd tea.Cmd
@ -28,7 +33,7 @@ func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPag
switch msg := msg.(type) {
case GemLogLoaded:
m.entry = msg.Log
m.viewport.SetContent(m.entry.Gemtxt)
m.viewport.SetContent(wrapGemtxt(m.entry.Gemtxt, m.viewport.Width))
case tea.KeyMsg:
if !active {
return m, nil
@ -54,7 +59,7 @@ func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPag
m.viewport = viewport.New(msg.Width, msg.Height-verticalMarginHeight)
m.viewport.YPosition = headerHeight
m.viewport.SetContent(m.entry.Gemtxt)
m.viewport.SetContent(wrapGemtxt(m.entry.Gemtxt, msg.Width))
m.ready = true
} else {
m.viewport.Width = msg.Width