wrap text in entry view
This commit is contained in:
parent
dc635db758
commit
0048f4a7ce
3 changed files with 12 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue