elvish/edit/historyListing.go

45 lines
766 B
Go
Raw Normal View History

2016-02-14 15:52:31 +08:00
package edit
import "github.com/elves/elvish/store"
// Command history listing subosytem.
2016-02-27 22:20:11 +08:00
// Interface.
func startHistoryListing(ed *Editor) {
if ed.store == nil {
ed.notify("store not connected")
return
}
err := initHistoryListing(&ed.historyListing, ed.store)
if err != nil {
ed.notify("%s", err)
return
}
ed.mode = modeHistoryListing
}
func defaultHistoryListing(ed *Editor) {
ed.mode = modeInsert
ed.nextAction = action{actionType: reprocessKey}
}
// Implementation.
2016-02-14 15:52:31 +08:00
type historyListing struct {
all []string
}
2016-02-27 22:20:11 +08:00
func initHistoryListing(hl *historyListing, s *store.Store) error {
2016-02-14 15:52:31 +08:00
seq, err := s.NextCmdSeq()
if err != nil {
2016-02-27 22:20:11 +08:00
return err
2016-02-14 15:52:31 +08:00
}
cmds, err := s.Cmds(seq-100, seq)
if err != nil {
2016-02-27 22:20:11 +08:00
return err
2016-02-14 15:52:31 +08:00
}
2016-02-27 22:20:11 +08:00
hl.all = cmds
return nil
2016-02-14 15:52:31 +08:00
}