forked from Mirrors/bubbletea
Add header and footer to pager example
This commit is contained in:
parent
8539cfcf8c
commit
4d68ed07ef
|
@ -8,5 +8,5 @@ require (
|
|||
github.com/charmbracelet/bubbles v0.0.0-20200526000837-87c7cd778f80
|
||||
github.com/charmbracelet/bubbletea v0.6.4-0.20200525234836-3b8b011b5a26
|
||||
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
|
||||
github.com/muesli/termenv v0.5.3-0.20200526053627-d728968dcf83
|
||||
github.com/muesli/termenv v0.5.3-0.20200617154346-da5de72b61c0
|
||||
)
|
||||
|
|
|
@ -10,8 +10,10 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
|
|||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/muesli/termenv v0.5.2 h1:N1Y1dHRtx6OizOgaIQXd8SkJl4T/cCOV+YyWXiuLUEA=
|
||||
github.com/muesli/termenv v0.5.2/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/muesli/termenv v0.5.3-0.20200526053627-d728968dcf83 h1:AfshZBlqAwhCZ27NJ1aPlMcPBihF1squ1GpaollhLQk=
|
||||
github.com/muesli/termenv v0.5.3-0.20200526053627-d728968dcf83/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/muesli/termenv v0.5.3-0.20200617122104-66d435cfe924 h1:oQHK4eixHzrl+DmUKH0x7SJgbkQBiggektj3ChSuE9I=
|
||||
github.com/muesli/termenv v0.5.3-0.20200617122104-66d435cfe924/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/muesli/termenv v0.5.3-0.20200617154346-da5de72b61c0 h1:IASsj5pQ478TEN9TLiuhP+ugUQEotZ1QdzQvcJUQ1dM=
|
||||
github.com/muesli/termenv v0.5.3-0.20200617154346-da5de72b61c0/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU=
|
||||
github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -22,8 +24,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
|
||||
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
|
||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
|
@ -9,6 +9,11 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
const (
|
||||
viewportTopMargin = 2
|
||||
viewportBottomMargin = 2
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Load some text to render
|
||||
|
@ -88,14 +93,17 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
m.err = msg.Error()
|
||||
break
|
||||
}
|
||||
|
||||
viewportVerticalMargins := viewportTopMargin + viewportBottomMargin
|
||||
|
||||
w, h := msg.Size()
|
||||
if !m.ready {
|
||||
m.viewport = viewport.NewModel(w, h)
|
||||
m.viewport = viewport.NewModel(w, h-viewportVerticalMargins)
|
||||
m.viewport.SetContent(m.content)
|
||||
m.ready = true
|
||||
} else {
|
||||
m.viewport.Width = w
|
||||
m.viewport.Height = h
|
||||
m.viewport.Height = h - viewportVerticalMargins
|
||||
}
|
||||
|
||||
case resizeMsg:
|
||||
|
@ -110,7 +118,12 @@ func view(mdl tea.Model) string {
|
|||
if m.err != nil {
|
||||
return "\nError:" + m.err.Error()
|
||||
} else if m.ready {
|
||||
return "\n" + viewport.View(m.viewport)
|
||||
|
||||
return fmt.Sprintf(
|
||||
"── Mr. Pager ──\n\n%s\n\n── %3.f%% ──",
|
||||
viewport.View(m.viewport),
|
||||
m.viewport.ScrollPercent()*100,
|
||||
)
|
||||
}
|
||||
return "\nInitalizing..."
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue