Bookmarks can be scrolled when focused

This commit is contained in:
sloumdrone 2019-09-16 19:38:07 -07:00
parent 7e53ce6aea
commit 21fe5714a3
3 changed files with 93 additions and 48 deletions

View File

@ -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
}

View File

@ -103,7 +103,20 @@ func (c *client) Draw() {
}
}
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,6 +527,30 @@ func (c *client) search() {
}
func (c *client) Scroll(amount int) {
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 := c.BookMarks.Position + amount
if newScrollPosition < 0 {
newScrollPosition = 0
} else if newScrollPosition > bottom {
newScrollPosition = bottom
}
c.BookMarks.Position = newScrollPosition
c.Draw()
} else {
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
@ -545,8 +582,8 @@ func (c *client) Scroll(amount int) {
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) {

View File

@ -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) {