forked from sloum/bombadillo
Bookmarks can be scrolled when focused
This commit is contained in:
parent
7e53ce6aea
commit
21fe5714a3
18
bookmarks.go
18
bookmarks.go
|
@ -86,20 +86,24 @@ func (b Bookmarks) List() []string {
|
||||||
func (b Bookmarks) Render(termwidth, termheight int) []string {
|
func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
width := 40
|
width := 40
|
||||||
termheight -= 3
|
termheight -= 3
|
||||||
var wall, ceil, tr, tl, br, bl string
|
var walll, wallr, floor, ceil, tr, tl, br, bl string
|
||||||
if termwidth < 40 {
|
if termwidth < 40 {
|
||||||
width = termwidth
|
width = termwidth
|
||||||
}
|
}
|
||||||
if b.IsFocused {
|
if b.IsFocused {
|
||||||
wall = cui.Shapes["awall"]
|
walll = cui.Shapes["awalll"]
|
||||||
|
wallr = cui.Shapes["awallr"]
|
||||||
ceil = cui.Shapes["aceiling"]
|
ceil = cui.Shapes["aceiling"]
|
||||||
|
floor = cui.Shapes["afloor"]
|
||||||
tr = cui.Shapes["atr"]
|
tr = cui.Shapes["atr"]
|
||||||
br = cui.Shapes["abr"]
|
br = cui.Shapes["abr"]
|
||||||
tl = cui.Shapes["atl"]
|
tl = cui.Shapes["atl"]
|
||||||
bl = cui.Shapes["abl"]
|
bl = cui.Shapes["abl"]
|
||||||
} else {
|
} else {
|
||||||
wall = cui.Shapes["wall"]
|
walll = cui.Shapes["walll"]
|
||||||
|
wallr = cui.Shapes["wallr"]
|
||||||
ceil = cui.Shapes["ceiling"]
|
ceil = cui.Shapes["ceiling"]
|
||||||
|
floor = cui.Shapes["floor"]
|
||||||
tr = cui.Shapes["tr"]
|
tr = cui.Shapes["tr"]
|
||||||
br = cui.Shapes["br"]
|
br = cui.Shapes["br"]
|
||||||
tl = cui.Shapes["tl"]
|
tl = cui.Shapes["tl"]
|
||||||
|
@ -112,14 +116,14 @@ func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
out = append(out, top)
|
out = append(out, top)
|
||||||
marks := b.List()
|
marks := b.List()
|
||||||
for i := 0; i < termheight - 2; i++ {
|
for i := 0; i < termheight - 2; i++ {
|
||||||
if i + b.Position >= b.Length {
|
if i + b.Position >= len(b.Titles) {
|
||||||
out = append(out, fmt.Sprintf("%s%-*.*s%s", wall, contentWidth, contentWidth, "", wall ))
|
out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, "", wallr))
|
||||||
} else {
|
} 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)
|
out = append(out, bottom)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
95
client.go
95
client.go
|
@ -102,8 +102,21 @@ func (c *client) Draw() {
|
||||||
screen.WriteString(fmt.Sprintf("%-*.*s", contentWidth, contentWidth, " "))
|
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])
|
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")
|
screen.WriteString("\n")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -514,39 +527,63 @@ func (c *client) search() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Scroll(amount int) {
|
func (c *client) Scroll(amount int) {
|
||||||
var percentRead int
|
if c.BookMarks.IsFocused {
|
||||||
page := c.PageState.History[c.PageState.Position]
|
bottom := len(c.BookMarks.Titles) - c.Height + 5 // 3 for the three bars: top, msg, bottom
|
||||||
bottom := len(page.WrappedContent) - c.Height + 3 // 3 for the three bars: top, msg, bottom
|
if amount < 0 && c.BookMarks.Position == 0 {
|
||||||
if amount < 0 && page.ScrollPosition == 0 {
|
c.SetMessage("The bookmark ladder does not go up any further", false)
|
||||||
c.SetMessage("You are already at the top", false)
|
c.DrawMessage()
|
||||||
c.DrawMessage()
|
fmt.Print("\a")
|
||||||
fmt.Print("\a")
|
return
|
||||||
return
|
} else if (amount > 0 && c.BookMarks.Position == bottom) || bottom < 0 {
|
||||||
} else if (amount > 0 && page.ScrollPosition == bottom) || bottom < 0 {
|
c.SetMessage("Feel the ground beneath your bookmarks", false)
|
||||||
c.FootBar.SetPercentRead(100)
|
c.DrawMessage()
|
||||||
c.SetMessage("You are already at the bottom", false)
|
fmt.Print("\a")
|
||||||
c.DrawMessage()
|
return
|
||||||
fmt.Print("\a")
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
newScrollPosition := page.ScrollPosition + amount
|
newScrollPosition := c.BookMarks.Position + amount
|
||||||
if newScrollPosition < 0 {
|
if newScrollPosition < 0 {
|
||||||
newScrollPosition = 0
|
newScrollPosition = 0
|
||||||
} else if newScrollPosition > bottom {
|
} else if newScrollPosition > bottom {
|
||||||
newScrollPosition = bottom
|
newScrollPosition = bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
c.PageState.History[c.PageState.Position].ScrollPosition = newScrollPosition
|
c.BookMarks.Position = newScrollPosition
|
||||||
|
c.Draw()
|
||||||
if len(page.WrappedContent) < c.Height - 3 {
|
|
||||||
percentRead = 100
|
|
||||||
} else {
|
} else {
|
||||||
percentRead = int(float32(newScrollPosition + c.Height - 3) / float32(len(page.WrappedContent)) * 100.0)
|
var percentRead int
|
||||||
}
|
page := c.PageState.History[c.PageState.Position]
|
||||||
c.FootBar.SetPercentRead(percentRead)
|
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) {
|
func (c *client) displayConfigValue(setting string) {
|
||||||
|
|
28
cui/cui.go
28
cui/cui.go
|
@ -10,18 +10,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var Shapes = map[string]string{
|
var Shapes = map[string]string{
|
||||||
"wall": "╵",
|
"walll": "╎",
|
||||||
"ceiling": "╴",
|
"wallr": " ",
|
||||||
"tl": "┌",
|
"ceiling": " ",
|
||||||
"tr": "┐",
|
"floor": " ",
|
||||||
"bl": "└",
|
"tl": "╎",
|
||||||
"br": "┘",
|
"tr": " ",
|
||||||
"awall": "║",
|
"bl": "╎",
|
||||||
"aceiling": "═",
|
"br": " ",
|
||||||
"atl": "╔",
|
"awalll": "▌",
|
||||||
"atr": "╗",
|
"awallr": "▐",
|
||||||
"abl": "╚",
|
"aceiling": "▀",
|
||||||
"abr": "╝",
|
"afloor": "▄",
|
||||||
|
"atl": "▞",
|
||||||
|
"atr": "▜",
|
||||||
|
"abl": "▚",
|
||||||
|
"abr": "▟",
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawShape(shape string) {
|
func drawShape(shape string) {
|
||||||
|
|
Loading…
Reference in New Issue