Fix pager footer positioning

This commit is contained in:
Christian Rocha 2020-06-19 12:29:59 -04:00
parent 2a297fabad
commit 9cf57efe5f
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 7 additions and 11 deletions

View File

@ -22,6 +22,7 @@ func main() {
// Load some text to render // Load some text to render
content, err := ioutil.ReadFile("artichoke.md") content, err := ioutil.ReadFile("artichoke.md")
//content, err := ioutil.ReadFile("menagerie.txt")
if err != nil { if err != nil {
fmt.Println("could not load file:", err) fmt.Println("could not load file:", err)
os.Exit(1) os.Exit(1)
@ -130,18 +131,13 @@ func view(mdl tea.Model) string {
header := fmt.Sprintf("%s\n%s\n%s", headerTop, headerMid, headerBot) header := fmt.Sprintf("%s\n%s\n%s", headerTop, headerMid, headerBot)
footerTop := "╭──────╮" footerTop := "╭──────╮"
footerMid := "┤ %3.f%% │" footerMid := fmt.Sprintf("┤ %3.f%% │", m.viewport.ScrollPercent()*100)
footerBot := "╰──────╯" footerBot := "╰──────╯"
space := m.viewport.Width - runewidth.StringWidth(footerMid) gapSize := m.viewport.Width - runewidth.StringWidth(footerMid)
footerTop = strings.Repeat(" ", space) + footerTop footerTop = strings.Repeat(" ", gapSize) + footerTop
footerMid = strings.Repeat("─", space) + footerMid footerMid = strings.Repeat("─", gapSize) + footerMid
footerBot = strings.Repeat(" ", space) + footerBot footerBot = strings.Repeat(" ", gapSize) + footerBot
footer := footerTop + "\n" + footerMid + "\n" + footerBot footer := footerTop + "\n" + footerMid + "\n" + footerBot
return fmt.Sprintf( return fmt.Sprintf("%s\n%s\n%s", header, viewport.View(m.viewport), footer)
"%s\n%s\n%s",
header,
viewport.View(m.viewport),
fmt.Sprintf(footer, m.viewport.ScrollPercent()*100),
)
} }