Skip to content
Myr

Add header and footer to pager example

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 8539cfc · Browse files · 3 files+23 added−10 removed
This commit

State

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

Diff stats

3 files+23 added−10 removed

  • other:+23 added−10 removed

3 files+23 added−10 removed

modified:examples/pager/main.go+16 added-3 removed
7 unmodified lines
8 "github.com/charmbracelet/bubbles/viewport"9 tea "github.com/charmbracelet/bubbletea"10)1112const (13 viewportTopMargin = 214 viewportBottomMargin = 215)1617func main() {1819 // Load some text to render20 content, err := ioutil.ReadFile("artichoke.md")
71 unmodified lines
92 if msg.Error() != nil {93 m.err = msg.Error()94 break95 }9697 viewportVerticalMargins := viewportTopMargin + viewportBottomMargin9899 w, h := msg.Size()100 if !m.ready {93 m.viewport = viewport.NewModel(w, h)101 m.viewport = viewport.NewModel(w, h-viewportVerticalMargins)102 m.viewport.SetContent(m.content)103 m.ready = true104 } else {105 m.viewport.Width = w98 m.viewport.Height = h106 m.viewport.Height = h - viewportVerticalMargins107 }108109 case resizeMsg:110 return m, tea.Batch(getTerminalSize(), listenForResize())
6 unmodified lines
117 m, _ := mdl.(model)118 if m.err != nil {119 return "\nError:" + m.err.Error()120 } else if m.ready {113 return "\n" + viewport.View(m.viewport)121122 return fmt.Sprintf(123 "── Mr. Pager ──\n\n%s\n\n── %3.f%% ──",124 viewport.View(m.viewport),125 m.viewport.ScrollPercent()*100,126 )127 }128 return "\nInitalizing..."129}130
11 unmodified lines
modified:examples/go.mod+1 added-1 removed
6 unmodified lines
7require (8 github.com/charmbracelet/bubbles v0.0.0-20200526000837-87c7cd778f809 github.com/charmbracelet/bubbletea v0.6.4-0.20200525234836-3b8b011b5a2610 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf177611 github.com/muesli/termenv v0.5.3-0.20200526053627-d728968dcf8311 github.com/muesli/termenv v0.5.3-0.20200617154346-da5de72b61c012)
modified:examples/go.sum+6 added-6 removed
8 unmodified lines
9github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=10github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=11github.com/muesli/termenv v0.5.2 h1:N1Y1dHRtx6OizOgaIQXd8SkJl4T/cCOV+YyWXiuLUEA=12github.com/muesli/termenv v0.5.2/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=13github.com/muesli/termenv v0.5.3-0.20200526053627-d728968dcf83 h1:AfshZBlqAwhCZ27NJ1aPlMcPBihF1squ1GpaollhLQk=14github.com/muesli/termenv v0.5.3-0.20200526053627-d728968dcf83/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=13github.com/muesli/termenv v0.5.3-0.20200617122104-66d435cfe924 h1:oQHK4eixHzrl+DmUKH0x7SJgbkQBiggektj3ChSuE9I=14github.com/muesli/termenv v0.5.3-0.20200617122104-66d435cfe924/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=15github.com/muesli/termenv v0.5.3-0.20200617154346-da5de72b61c0 h1:IASsj5pQ478TEN9TLiuhP+ugUQEotZ1QdzQvcJUQ1dM=16github.com/muesli/termenv v0.5.3-0.20200617154346-da5de72b61c0/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=17github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU=18github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA=19golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=20golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
2 unmodified lines
23golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=24golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=25golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=26golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=25golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=26golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=27golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=28golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=27golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=28golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=29golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=