Adds a jump command to allow for navigating by history location as an alternate to a tabbed workflow

This commit is contained in:
sloum 2020-11-14 15:40:18 -08:00
parent ebcd1ff1d7
commit 7d722d7dfa
5 changed files with 41 additions and 3 deletions

View File

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

View File

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

View File

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

View File

@ -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`",

View File

@ -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 + + + \\
//--------------------------------------------------\\