back and forward by N
This commit is contained in:
parent
684539c70d
commit
ceaaaaf695
|
@ -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
|
||||
|
|
19
actions.go
19
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)
|
||||
|
|
40
command.go
40
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":
|
||||
|
|
12
help.go
12
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": `
|
||||
|
|
Loading…
Reference in New Issue