diff --git a/bookmarks.go b/bookmarks.go index 8f8cc0d..0268378 100644 --- a/bookmarks.go +++ b/bookmarks.go @@ -11,6 +11,9 @@ import ( // + + + T Y P E S + + + \\ //--------------------------------------------------\\ +// Bookmarks represents the contents of the bookmarks +// bar, as well as its visibility, focus, and scroll +// state. type Bookmarks struct { IsOpen bool IsFocused bool @@ -24,6 +27,7 @@ type Bookmarks struct { // + + + R E C E I V E R S + + + \\ //--------------------------------------------------\\ +// Add a bookmark to the bookmarks struct func (b *Bookmarks) Add(v []string) (string, error) { if len(v) < 2 { return "", fmt.Errorf("Received %d arguments, expected 2+", len(v)) @@ -34,6 +38,7 @@ func (b *Bookmarks) Add(v []string) (string, error) { return "Bookmark added successfully", nil } +// Delete a bookmark from the bookmarks struct func (b *Bookmarks) Delete(i int) (string, error) { if i < len(b.Titles) && len(b.Titles) == len(b.Links) { b.Titles = append(b.Titles[:i], b.Titles[i+1:]...) @@ -44,6 +49,7 @@ func (b *Bookmarks) Delete(i int) (string, error) { return "", fmt.Errorf("Bookmark %d does not exist", i) } +// ToggleOpen toggles visibility state of the bookmarks bar func (b *Bookmarks) ToggleOpen() { b.IsOpen = !b.IsOpen if b.IsOpen { @@ -53,12 +59,15 @@ func (b *Bookmarks) ToggleOpen() { } } +// ToggleFocused toggles the focal state of the bookmarks bar func (b *Bookmarks) ToggleFocused() { if b.IsOpen { b.IsFocused = !b.IsFocused } } +// IniDump returns a string representing the current bookmarks +// in the format that .bombadillo.ini uses func (b Bookmarks) IniDump() string { if len(b.Titles) < 1 { return "" @@ -73,7 +82,7 @@ func (b Bookmarks) IniDump() string { return out } -// Get a list, including link nums, of bookmarks +// List returns a list, including link nums, of bookmarks // as a string slice func (b Bookmarks) List() []string { var out []string @@ -83,6 +92,8 @@ func (b Bookmarks) List() []string { return out } +// Render returns a string slice with the contents of each +// visual row of the bookmark bar. func (b Bookmarks) Render(termwidth, termheight int) []string { width := 40 termheight -= 3 @@ -128,14 +139,11 @@ func (b Bookmarks) Render(termwidth, termheight int) []string { return out } -// TODO handle scrolling of the bookmarks list -// either here with a scroll up/down or in the client -// code for scroll - //------------------------------------------------\\ // + + + F U N C T I O N S + + + \\ //--------------------------------------------------\\ +// MakeBookmarks creates a Bookmark struct with default values func MakeBookmarks() Bookmarks { return Bookmarks{false, false, 0, 0, make([]string, 0), make([]string, 0)} } diff --git a/client.go b/client.go index 952f9f6..35fd5af 100644 --- a/client.go +++ b/client.go @@ -385,10 +385,9 @@ func (c *client) doCommandAs(action string, values []string) { c.SetMessage(err.Error(), true) c.DrawMessage() return - } else { - c.SetMessage(msg, false) - c.DrawMessage() } + c.SetMessage(msg, false) + c.DrawMessage() err = saveConfig() if err != nil { @@ -437,7 +436,7 @@ func (c *client) doLinkCommandAs(action, target string, values []string) { return } - num -= 1 + num-- links := c.PageState.History[c.PageState.Position].Links if num >= len(links) || num < 0 { @@ -456,10 +455,9 @@ func (c *client) doLinkCommandAs(action, target string, values []string) { c.SetMessage(err.Error(), true) c.DrawMessage() return - } else { - c.SetMessage(msg, false) - c.DrawMessage() } + c.SetMessage(msg, false) + c.DrawMessage() err = saveConfig() if err != nil { @@ -564,10 +562,9 @@ func (c *client) doLinkCommand(action, target string) { c.SetMessage(err.Error(), true) c.DrawMessage() return - } else { - c.SetMessage(msg, false) - c.DrawMessage() } + c.SetMessage(msg, false) + c.DrawMessage() err = saveConfig() if err != nil { @@ -585,7 +582,7 @@ func (c *client) doLinkCommand(action, target string) { } c.Visit(c.BookMarks.Links[num]) case "CHECK", "C": - num -= 1 + num-- links := c.PageState.History[c.PageState.Position].Links if num >= len(links) || num < 0 { @@ -1052,6 +1049,7 @@ func (c *client) handleWeb(u Url) { // + + + F U N C T I O N S + + + \\ //--------------------------------------------------\\ +// Creates a client instance and names the client after the string that is passed in func MakeClient(name string) *client { c := client{0, 0, defaultOptions, "", false, MakePages(), MakeBookmarks(), MakeHeadbar(name), MakeFootbar(), gemini.MakeTofuDigest()} return &c diff --git a/footbar.go b/footbar.go index b0aef21..94140f5 100644 --- a/footbar.go +++ b/footbar.go @@ -9,6 +9,8 @@ import ( // + + + T Y P E S + + + \\ //--------------------------------------------------\\ +// Footbar deals with the values present in the +// client's footbar type Footbar struct { PercentRead string PageType string @@ -18,6 +20,8 @@ type Footbar struct { // + + + R E C E I V E R S + + + \\ //--------------------------------------------------\\ +// SetPercentRead sets the percentage of the current +// document the user has read func (f *Footbar) SetPercentRead(p int) { if p > 100 { p = 100 @@ -27,10 +31,14 @@ func (f *Footbar) SetPercentRead(p int) { f.PercentRead = strconv.Itoa(p) + "%" } +// SetPageType sets the current page's type +// NOTE: This is not currently in use func (f *Footbar) SetPageType(t string) { f.PageType = t } +// Render returns a string representing the visual display +// of the bookmarks bar func (f *Footbar) Render(termWidth, position int, theme string) string { pre := fmt.Sprintf("HST: (%2.2d) - - - %4s Read ", position+1, f.PercentRead) out := "\033[0m%*.*s " @@ -44,6 +52,7 @@ func (f *Footbar) Render(termWidth, position int, theme string) string { // + + + F U N C T I O N S + + + \\ //--------------------------------------------------\\ +// MakeFootbar returns a footbar with default values func MakeFootbar() Footbar { return Footbar{"---", "N/A"} } diff --git a/headbar.go b/headbar.go index 79ce11c..cd5eea2 100644 --- a/headbar.go +++ b/headbar.go @@ -8,6 +8,9 @@ import ( // + + + T Y P E S + + + \\ //--------------------------------------------------\\ +// Headbar represents the contents of the top bar of +// the client and contains the client name and the +// current URL type Headbar struct { title string url string @@ -17,19 +20,20 @@ type Headbar struct { // + + + R E C E I V E R S + + + \\ //--------------------------------------------------\\ +// Render returns a string with the contents of theHeadbar func (h *Headbar) Render(width int, theme string) string { maxMsgWidth := width - len([]rune(h.title)) - 2 if theme == "inverse" { return fmt.Sprintf("\033[7m%s▟\033[27m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url) - } else { - return fmt.Sprintf("%s▟\033[7m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url) } + return fmt.Sprintf("%s▟\033[7m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url) } //------------------------------------------------\\ // + + + F U N C T I O N S + + + \\ //--------------------------------------------------\\ +// MakeHeadbar returns a Headbar with default values func MakeHeadbar(title string) Headbar { return Headbar{title, ""} } diff --git a/main.go b/main.go index 54e7713..3c03392 100644 --- a/main.go +++ b/main.go @@ -82,9 +82,8 @@ func validateOpt(opt, val string) bool { } } return false - } else { - return true } + return true } func lowerCaseOpt(opt, val string) string { diff --git a/page.go b/page.go index 44ded97..891b86d 100644 --- a/page.go +++ b/page.go @@ -8,6 +8,9 @@ import ( // + + + T Y P E S + + + \\ //--------------------------------------------------\\ +// Page represents a visited URL's contents; including +// the raw content, wrapped content, link slice, URL, +// and the current scroll position type Page struct { WrappedContent []string RawContent string @@ -38,7 +41,7 @@ func (p *Page) ScrollPositionRange(termHeight int) (int, int) { return p.ScrollPosition, end } -// Performs a hard wrap to the requested +// WrapContent performs a hard wrap to the requested // width and updates the WrappedContent // of the Page struct width a string slice // of the wrapped data diff --git a/pages.go b/pages.go index e40ec93..90f570a 100644 --- a/pages.go +++ b/pages.go @@ -41,7 +41,7 @@ func (p *Pages) Add(pg Page) { } p.History[len(p.History)-1] = pg } else { - p.Position += 1 + p.Position++ p.Length = p.Position + 1 p.History[p.Position] = pg }