Skip to content
Myr

Sync pager viewport when starting up and resizing

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent 6ea16d0 · Browse files · 1 file+11 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−2 removed

  • other:+11 added−2 removed

1 file+11 added−2 removed

modified:examples/pager/main.go+11 added-2 removed
79 unmodified lines
8081func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {82 m, _ := mdl.(model)8384 var (85 cmd tea.Cmd86 cmds []tea.Cmd87 )8889 switch msg := msg.(type) {90 case tea.KeyMsg:91 if msg.Type == tea.KeyCtrlC {92 return m, tea.Quit
18 unmodified lines
111 m.viewport.Width = w112 m.viewport.Height = h - viewportBottomMargin113 }114115 // Render (or re-render) the whole viewport116 cmds = append(cmds, viewport.Sync(m.viewport))117118 case resizeMsg:119 return m, tea.Batch(getTerminalSize(), listenForResize())120 }121
1 unmodified line
123 // style navigation) it's important that the viewport's update function:124 //125 // * Recieves messages from the Bubble Tea runtime126 // * Returns commands to the Bubble Tea runtime119 var cmd tea.Cmd127 m.viewport, cmd = viewport.Update(msg, m.viewport)128 cmds = append(cmds, cmd)129122 return m, cmd130 return m, tea.Batch(cmds...)131}132133func view(mdl tea.Model) string {134 m, _ := mdl.(model)135 if m.err != nil {136 return "\nError:" + m.err.Error()137 } else if m.ready {138139 return viewport.View(m.viewport)140 return fmt.Sprintf(141 "── Mr. Pager ──\n\n%s\n\n── %3.f%% ──",142 viewport.View(m.viewport),143 m.viewport.ScrollPercent()*100,
16 unmodified lines