From 7d722d7dfae4b3bf09202f0903adf47f4d0a9884 Mon Sep 17 00:00:00 2001 From: sloum Date: Sat, 14 Nov 2020 15:40:18 -0800 Subject: [PATCH] Adds a jump command to allow for navigating by history location as an alternate to a tabbed workflow --- bombadillo.1 | 8 ++++++++ client.go | 18 +++++++++++++++++- cmdparse/lexer.go | 2 +- help.go | 2 ++ pages.go | 14 +++++++++++++- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/bombadillo.1 b/bombadillo.1 index a66816d..c8e2d02 100644 --- a/bombadillo.1 +++ b/bombadillo.1 @@ -181,6 +181,14 @@ home Navigates to the document set by the \fIhomeurl\fP setting. \fIh\fP can be entered, rather than the full \fIhome\fP. .TP .B +jump +Navigates to the previous page in history from the current page. Useful for keeping the current page in your history while still browsing. +.TP +.B +jump [history location] +Navigates to the given history location. The history location should be an integer between 0 and 20. +.TP +.B purge * Deletes all pinned gemini server certificates. \fIp\fP can be used instead of the full \fIpurge\fP. .TP diff --git a/client.go b/client.go index 2617247..3ed3712 100644 --- a/client.go +++ b/client.go @@ -345,6 +345,14 @@ func (c *client) simpleCommand(action string) { c.search("", "", "?") case "HELP", "?": c.Visit(helplocation) + case "JUMP", "J": + err := c.PageState.CopyHistory(-1) + if err != nil { + c.SetMessage(err.Error(), false) + c.DrawMessage() + } else { + c.Draw() + } default: c.SetMessage(syntaxErrorMessage(action), true) c.DrawMessage() @@ -406,7 +414,6 @@ func (c *client) doCommand(action string, values []string) { fn = "index" } c.saveFile(u, fn) - default: c.SetMessage(syntaxErrorMessage(action), true) c.DrawMessage() @@ -641,6 +648,15 @@ func (c *client) doLinkCommand(action, target string) { link := links[num] c.SetMessage(fmt.Sprintf("[%d] %s", num+1, link), false) c.DrawMessage() + case "JUMP", "J": + num-- + err = c.PageState.CopyHistory(num) + if err != nil { + c.SetMessage(err.Error(), false) + c.DrawMessage() + } else { + c.Draw() + } case "WRITE", "W": links := c.PageState.History[c.PageState.Position].Links if len(links) < num || num < 1 { diff --git a/cmdparse/lexer.go b/cmdparse/lexer.go index 8b882c3..35a2b39 100644 --- a/cmdparse/lexer.go +++ b/cmdparse/lexer.go @@ -72,7 +72,7 @@ func (s *scanner) scanText() Token { "S", "SET", "R", "RELOAD", "SEARCH", "Q", "QUIT", "B", "BOOKMARKS", "H", "HOME", "?", "HELP", "C", "CHECK", - "P", "PURGE": + "P", "PURGE", "JUMP", "J": return Token{Action, capInput} } diff --git a/help.go b/help.go index ece82db..df66e88 100644 --- a/help.go +++ b/help.go @@ -12,6 +12,8 @@ var ERRS = map[string]string{ "CHECK": "`check [link_id]` or `check [setting]`", "H": "`h`", "HOME": "`home`", + "J": "`jump [[history_position]]`", + "JUMP": "`jump [[history_position]]`", "P": "`p [host]`", "PURGE": "`purge [host]`", "Q": "`q`", diff --git a/pages.go b/pages.go index 9fa6606..e4ef964 100644 --- a/pages.go +++ b/pages.go @@ -38,7 +38,7 @@ func (p *Pages) NavigateHistory(qty int) error { } // Add gets passed a Page, which gets added to the history -// arrayr. Add also updates the current length and position +// array. Add also updates the current length and position // of the Pages struct to which it belongs. Add also shifts // off array items if necessary. func (p *Pages) Add(pg Page) { @@ -92,6 +92,18 @@ func (p *Pages) Render(termHeight, termWidth int, color bool) []string { return p.History[p.Position].WrappedContent[pos:] } +func (p *Pages) CopyHistory(pos int) error { + if p.Length < 2 || pos > p.Position { + return fmt.Errorf("There are not enough history locations available") + } + if pos < 0 { + pos = p.Position-1 + } + + p.Add(p.History[pos]) + return nil +} + //------------------------------------------------\\ // + + + F U N C T I O N S + + + \\ //--------------------------------------------------\\