forked from mirror/readline
enabling disabling history (#102)
This commit is contained in:
parent
aee0fa669f
commit
af545c8af6
18
history.go
18
history.go
|
@ -27,12 +27,14 @@ type opHistory struct {
|
|||
current *list.Element
|
||||
fd *os.File
|
||||
fdLock sync.Mutex
|
||||
enable bool
|
||||
}
|
||||
|
||||
func newOpHistory(cfg *Config) (o *opHistory) {
|
||||
o = &opHistory{
|
||||
cfg: cfg,
|
||||
history: list.New(),
|
||||
enable: true,
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
@ -223,6 +225,16 @@ func (o *opHistory) Next() ([]rune, bool) {
|
|||
return runes.Copy(o.showItem(current.Value)), true
|
||||
}
|
||||
|
||||
// Disable the current history
|
||||
func (o *opHistory) Disable() {
|
||||
o.enable = false
|
||||
}
|
||||
|
||||
// Enable the current history
|
||||
func (o *opHistory) Enable() {
|
||||
o.enable = true
|
||||
}
|
||||
|
||||
func (o *opHistory) debug() {
|
||||
Debug("-------")
|
||||
for item := o.history.Front(); item != nil; item = item.Next() {
|
||||
|
@ -232,6 +244,12 @@ func (o *opHistory) debug() {
|
|||
|
||||
// save history
|
||||
func (o *opHistory) New(current []rune) (err error) {
|
||||
|
||||
// history deactivated
|
||||
if !o.enable {
|
||||
return nil
|
||||
}
|
||||
|
||||
current = runes.Copy(current)
|
||||
|
||||
// if just use last command without modify
|
||||
|
|
10
readline.go
10
readline.go
|
@ -295,3 +295,13 @@ func (i *Instance) SetConfig(cfg *Config) *Config {
|
|||
func (i *Instance) Refresh() {
|
||||
i.Operation.Refresh()
|
||||
}
|
||||
|
||||
// HistoryDisable the save of the commands into the history
|
||||
func (i *Instance) HistoryDisable() {
|
||||
i.Operation.history.Disable()
|
||||
}
|
||||
|
||||
// HistoryEnable the save of the commands into the history (default on)
|
||||
func (i *Instance) HistoryEnable() {
|
||||
i.Operation.history.Enable()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue