summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.gmi4
-rw-r--r--actions.go19
-rw-r--r--command.go40
-rw-r--r--help.go12
4 files changed, 57 insertions, 18 deletions
diff --git a/README.gmi b/README.gmi
index d03301d..6511bc2 100644
--- a/README.gmi
+++ b/README.gmi
@@ -45,8 +45,8 @@ The default action for a completely empty command is "print", which will display
* re[load]: re-request and re-display the current page
* r[oot]: go to the root of the current site, or /~username root if in a tilde-path
* R[oot]: go to /, ignoring tilde-paths
-* b[ack]: back in history
-* f[orward]: forward in history
+* b[ack] [N]: back in history
+* f[orward] [N]: forward in history
* n[ext]: go to the next link in the previous history page - see below (like "back" followed by "go N+1" where N is the link index we used to get to the current page)
* pre[vious]: go to the previous link in the previous history page - see below
* u[p]: go to the parent directory of the current page
diff --git a/actions.go b/actions.go
index 6e5c7dd..4a51ee6 100644
--- a/actions.go
+++ b/actions.go
@@ -243,19 +243,22 @@ func back(state *BrowserState) error {
return nil
}
-func Back(state *BrowserState) error {
- if err := back(state); err != nil {
- return err
+func Back(state *BrowserState, num int) error {
+ for i := 0; i < num; i += 1 {
+ if err := back(state); err != nil {
+ return err
+ }
}
-
return print(state)
}
-func Forward(state *BrowserState) error {
- if state.Forward == nil {
- return ErrNoNextHistory
+func Forward(state *BrowserState, num int) error {
+ for i := 0; i < num; i += 1 {
+ if state.Forward == nil {
+ return ErrNoNextHistory
+ }
+ state.History = state.Forward
}
- state.History = state.Forward
state.Modal = nil
return print(state)
diff --git a/command.go b/command.go
index ea7ee7c..c3396b2 100644
--- a/command.go
+++ b/command.go
@@ -43,11 +43,35 @@ func ParseCommand(line string) (*Command, error) {
}
case 'b':
if strings.HasPrefix("back", cmd) {
- return &Command{Name: "back"}, nil
+ fields := strings.Fields(rest)
+ switch len(fields) {
+ case 0:
+ return &Command{Name: "back"}, nil
+ case 1:
+ if _, err := strconv.Atoi(fields[0]); err != nil {
+ return nil, ErrInvalidArgs
+ }
+ return &Command{Name: "back", Args: fields}, nil
+ default:
+ return nil, ErrInvalidArgs
+
+ }
}
case 'f':
if strings.HasPrefix("forward", cmd) {
- return &Command{Name: "forward"}, nil
+ fields := strings.Fields(rest)
+ switch len(fields) {
+ case 0:
+ return &Command{Name: "forward"}, nil
+ case 1:
+ if _, err := strconv.Atoi(fields[0]); err != nil {
+ return nil, ErrInvalidArgs
+ }
+ return &Command{Name: "forward", Args: fields}, nil
+ default:
+ return nil, ErrInvalidArgs
+
+ }
}
case 'n':
if strings.HasPrefix("next", cmd) {
@@ -270,9 +294,17 @@ func RunCommand(conf *Config, cmd *Command, state *BrowserState) error {
case "reload":
return Reload(state, conf)
case "back":
- return Back(state)
+ num := 1
+ if len(cmd.Args) == 1 {
+ num, _ = strconv.Atoi(cmd.Args[0])
+ }
+ return Back(state, num)
case "forward":
- return Forward(state)
+ num := 1
+ if len(cmd.Args) == 1 {
+ num, _ = strconv.Atoi(cmd.Args[0])
+ }
+ return Forward(state, num)
case "next":
return Next(state, conf)
case "previous":
diff --git a/help.go b/help.go
index 9a72c56..ab36c7d 100644
--- a/help.go
+++ b/help.go
@@ -168,15 +168,19 @@ Navigates to the parent directory path of the current page's path.
`[1:],
"back": `
-b[ack]
-------
+b[ack] [N]
+----------
Navigates to the previous page in the browser history.
+
+With an integer argument, goes N positions back.
`[1:],
"forward": `
-f[orward]
----------
+f[orward] [N]
+-------------
Navigates to the next page in the browser history.
+
+With an integer argument, goes N positions forward.
`[1:],
"next": `