Browse Source

Bookmarks can be scrolled when focused

pull/40/head
sloumdrone 2 years ago
parent
commit
21fe5714a3
  1. 18
      bookmarks.go
  2. 95
      client.go
  3. 28
      cui/cui.go

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

95
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
}
newScrollPosition := page.ScrollPosition + amount
if newScrollPosition < 0 {
newScrollPosition = 0
} else if newScrollPosition > bottom {
newScrollPosition = bottom
}
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
}
c.PageState.History[c.PageState.Position].ScrollPosition = newScrollPosition
newScrollPosition := c.BookMarks.Position + amount
if newScrollPosition < 0 {
newScrollPosition = 0
} else if newScrollPosition > bottom {
newScrollPosition = bottom
}
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) {

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

Loading…
Cancel
Save