From 21fe5714a396e78e1a161e1127bfd943aa92d616 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Mon, 16 Sep 2019 19:38:07 -0700 Subject: [PATCH] Bookmarks can be scrolled when focused --- bookmarks.go | 18 ++++++---- client.go | 95 ++++++++++++++++++++++++++++++++++++---------------- cui/cui.go | 28 +++++++++------- 3 files changed, 93 insertions(+), 48 deletions(-) diff --git a/bookmarks.go b/bookmarks.go index a3eb82d..9647725 100644 --- a/bookmarks.go +++ b/bookmarks.go @@ -86,20 +86,24 @@ func (b Bookmarks) List() []string { func (b Bookmarks) Render(termwidth, termheight int) []string { width := 40 termheight -= 3 - var wall, ceil, tr, tl, br, bl string + var walll, wallr, floor, ceil, tr, tl, br, bl string if termwidth < 40 { width = termwidth } if b.IsFocused { - wall = cui.Shapes["awall"] + walll = cui.Shapes["awalll"] + wallr = cui.Shapes["awallr"] ceil = cui.Shapes["aceiling"] + floor = cui.Shapes["afloor"] tr = cui.Shapes["atr"] br = cui.Shapes["abr"] tl = cui.Shapes["atl"] bl = cui.Shapes["abl"] } else { - wall = cui.Shapes["wall"] + walll = cui.Shapes["walll"] + wallr = cui.Shapes["wallr"] ceil = cui.Shapes["ceiling"] + floor = cui.Shapes["floor"] tr = cui.Shapes["tr"] br = cui.Shapes["br"] tl = cui.Shapes["tl"] @@ -112,14 +116,14 @@ func (b Bookmarks) Render(termwidth, termheight int) []string { out = append(out, top) marks := b.List() for i := 0; i < termheight - 2; i++ { - if i + b.Position >= b.Length { - out = append(out, fmt.Sprintf("%s%-*.*s%s", wall, contentWidth, contentWidth, "", wall )) + if i + b.Position >= len(b.Titles) { + out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, "", wallr)) } else { - out = append(out, fmt.Sprintf("%s%-*.*s%s", wall, contentWidth, contentWidth, marks[i + b.Position], wall )) + out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, marks[i + b.Position], wallr)) } } - bottom := fmt.Sprintf("%s%s%s", bl, strings.Repeat(ceil, contentWidth), br) + bottom := fmt.Sprintf("%s%s%s", bl, strings.Repeat(floor, contentWidth), br) out = append(out, bottom) return out } diff --git a/client.go b/client.go index 2800c35..372a00d 100644 --- a/client.go +++ b/client.go @@ -102,8 +102,21 @@ func (c *client) Draw() { screen.WriteString(fmt.Sprintf("%-*.*s", contentWidth, contentWidth, " ")) } } + + if c.Options["theme"] == "inverse" && !c.BookMarks.IsFocused { + screen.WriteString("\033[2;7m") + } else if !c.BookMarks.IsFocused { + screen.WriteString("\033[2m") + } screen.WriteString(bm[i]) + + if c.Options["theme"] == "inverse" && !c.BookMarks.IsFocused { + screen.WriteString("\033[7;22m") + } else if !c.BookMarks.IsFocused { + screen.WriteString("\033[0m") + } + screen.WriteString("\n") } } else { @@ -514,39 +527,63 @@ func (c *client) search() { } func (c *client) Scroll(amount int) { - var percentRead int - page := c.PageState.History[c.PageState.Position] - bottom := len(page.WrappedContent) - c.Height + 3 // 3 for the three bars: top, msg, bottom - if amount < 0 && page.ScrollPosition == 0 { - c.SetMessage("You are already at the top", false) - c.DrawMessage() - fmt.Print("\a") - return - } else if (amount > 0 && page.ScrollPosition == bottom) || bottom < 0 { - c.FootBar.SetPercentRead(100) - c.SetMessage("You are already at the bottom", false) - c.DrawMessage() - fmt.Print("\a") - return - } + if c.BookMarks.IsFocused { + bottom := len(c.BookMarks.Titles) - c.Height + 5 // 3 for the three bars: top, msg, bottom + if amount < 0 && c.BookMarks.Position == 0 { + c.SetMessage("The bookmark ladder does not go up any further", false) + c.DrawMessage() + fmt.Print("\a") + return + } else if (amount > 0 && c.BookMarks.Position == bottom) || bottom < 0 { + c.SetMessage("Feel the ground beneath your bookmarks", false) + c.DrawMessage() + fmt.Print("\a") + return + } - newScrollPosition := page.ScrollPosition + amount - if newScrollPosition < 0 { - newScrollPosition = 0 - } else if newScrollPosition > bottom { - newScrollPosition = bottom - } + newScrollPosition := c.BookMarks.Position + amount + if newScrollPosition < 0 { + newScrollPosition = 0 + } else if newScrollPosition > bottom { + newScrollPosition = bottom + } - c.PageState.History[c.PageState.Position].ScrollPosition = newScrollPosition - - if len(page.WrappedContent) < c.Height - 3 { - percentRead = 100 + c.BookMarks.Position = newScrollPosition + c.Draw() } else { - percentRead = int(float32(newScrollPosition + c.Height - 3) / float32(len(page.WrappedContent)) * 100.0) - } - c.FootBar.SetPercentRead(percentRead) + var percentRead int + page := c.PageState.History[c.PageState.Position] + bottom := len(page.WrappedContent) - c.Height + 3 // 3 for the three bars: top, msg, bottom + if amount < 0 && page.ScrollPosition == 0 { + c.SetMessage("You are already at the top", false) + c.DrawMessage() + fmt.Print("\a") + return + } else if (amount > 0 && page.ScrollPosition == bottom) || bottom < 0 { + c.FootBar.SetPercentRead(100) + c.SetMessage("You are already at the bottom", false) + c.DrawMessage() + fmt.Print("\a") + return + } - c.Draw() + newScrollPosition := page.ScrollPosition + amount + if newScrollPosition < 0 { + newScrollPosition = 0 + } else if newScrollPosition > bottom { + newScrollPosition = bottom + } + + c.PageState.History[c.PageState.Position].ScrollPosition = newScrollPosition + + if len(page.WrappedContent) < c.Height - 3 { + percentRead = 100 + } else { + percentRead = int(float32(newScrollPosition + c.Height - 3) / float32(len(page.WrappedContent)) * 100.0) + } + c.FootBar.SetPercentRead(percentRead) + c.Draw() + } } func (c *client) displayConfigValue(setting string) { diff --git a/cui/cui.go b/cui/cui.go index 5cb5d79..e6cfb1c 100644 --- a/cui/cui.go +++ b/cui/cui.go @@ -10,18 +10,22 @@ import ( ) var Shapes = map[string]string{ - "wall": "╵", - "ceiling": "╴", - "tl": "┌", - "tr": "┐", - "bl": "└", - "br": "┘", - "awall": "║", - "aceiling": "═", - "atl": "╔", - "atr": "╗", - "abl": "╚", - "abr": "╝", + "walll": "╎", + "wallr": " ", + "ceiling": " ", + "floor": " ", + "tl": "╎", + "tr": " ", + "bl": "╎", + "br": " ", + "awalll": "▌", + "awallr": "▐", + "aceiling": "▀", + "afloor": "▄", + "atl": "▞", + "atr": "▜", + "abl": "▚", + "abr": "▟", } func drawShape(shape string) {