forked from mirror/readline
report error if it save history fail
This commit is contained in:
parent
01066143c6
commit
6368045a0b
16
history.go
16
history.go
|
@ -209,7 +209,7 @@ func (o *opHistory) debug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// save history
|
// save history
|
||||||
func (o *opHistory) New(current []rune) {
|
func (o *opHistory) New(current []rune) (err error) {
|
||||||
current = runes.Copy(current)
|
current = runes.Copy(current)
|
||||||
// if just use last command without modify
|
// if just use last command without modify
|
||||||
// just clean lastest history
|
// just clean lastest history
|
||||||
|
@ -221,7 +221,7 @@ func (o *opHistory) New(current []rune) {
|
||||||
o.current = o.history.Back()
|
o.current = o.history.Back()
|
||||||
o.current.Value.(*hisItem).Clean()
|
o.current.Value.(*hisItem).Clean()
|
||||||
o.historyVer++
|
o.historyVer++
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ func (o *opHistory) New(current []rune) {
|
||||||
if o.current != nil {
|
if o.current != nil {
|
||||||
o.current.Value.(*hisItem).Clean()
|
o.current.Value.(*hisItem).Clean()
|
||||||
o.historyVer++
|
o.historyVer++
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,11 +243,13 @@ func (o *opHistory) New(current []rune) {
|
||||||
current = runes.Copy(currentItem.Tmp)
|
current = runes.Copy(currentItem.Tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Update(current, true)
|
// err only can be a IO error, just report
|
||||||
|
err = o.Update(current, true)
|
||||||
|
|
||||||
// push a new one to commit current command
|
// push a new one to commit current command
|
||||||
o.historyVer++
|
o.historyVer++
|
||||||
o.Push(nil)
|
o.Push(nil)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *opHistory) Revert() {
|
func (o *opHistory) Revert() {
|
||||||
|
@ -255,7 +257,7 @@ func (o *opHistory) Revert() {
|
||||||
o.current = o.history.Back()
|
o.current = o.history.Back()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *opHistory) Update(s []rune, commit bool) {
|
func (o *opHistory) Update(s []rune, commit bool) (err error) {
|
||||||
s = runes.Copy(s)
|
s = runes.Copy(s)
|
||||||
if o.current == nil {
|
if o.current == nil {
|
||||||
o.Push(s)
|
o.Push(s)
|
||||||
|
@ -267,13 +269,15 @@ func (o *opHistory) Update(s []rune, commit bool) {
|
||||||
if commit {
|
if commit {
|
||||||
r.Source = s
|
r.Source = s
|
||||||
if o.fd != nil {
|
if o.fd != nil {
|
||||||
o.fd.Write([]byte(string(r.Source) + "\n"))
|
// just report the error
|
||||||
|
_, err = o.fd.Write([]byte(string(r.Source) + "\n"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
r.Tmp = append(r.Tmp[:0], s...)
|
r.Tmp = append(r.Tmp[:0], s...)
|
||||||
}
|
}
|
||||||
o.current.Value = r
|
o.current.Value = r
|
||||||
o.Compact()
|
o.Compact()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *opHistory) Push(s []rune) {
|
func (o *opHistory) Push(s []rune) {
|
||||||
|
|
|
@ -192,7 +192,8 @@ func (o *Operation) ioloop() {
|
||||||
}
|
}
|
||||||
o.outchan <- data
|
o.outchan <- data
|
||||||
if !o.cfg.DisableAutoSaveHistory {
|
if !o.cfg.DisableAutoSaveHistory {
|
||||||
o.history.New(data)
|
// ignore IO error
|
||||||
|
_ = o.history.New(data)
|
||||||
} else {
|
} else {
|
||||||
isUpdateHistory = false
|
isUpdateHistory = false
|
||||||
}
|
}
|
||||||
|
@ -407,8 +408,10 @@ func (op *Operation) SetConfig(cfg *Config) (*Config, error) {
|
||||||
return old, nil
|
return old, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Operation) SaveHistory(content string) {
|
// if err is not nil, it just mean it fail to write to file
|
||||||
o.history.New([]rune(content))
|
// other things goes fine.
|
||||||
|
func (o *Operation) SaveHistory(content string) error {
|
||||||
|
return o.history.New([]rune(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Operation) Refresh() {
|
func (o *Operation) Refresh() {
|
||||||
|
|
Loading…
Reference in New Issue