// save history func (o *opHistory) New(current []rune) (err error) { current = runes.Copy(current) // if just use last command without modify // just clean lastest history if back := o.history.Back(); back != nil { prev := back.Prev() if prev != nil { use := o.showItem(o.current.Value.(*hisItem)) if runes.Equal(use, prev.Value.(*hisItem).Source) { o.current = o.history.Back() o.current.Value.(*hisItem).Clean() o.historyVer++ return nil } } } if len(current) == 0 { o.current = o.history.Back() if o.current != nil { o.current.Value.(*hisItem).Clean() o.historyVer++ return nil } } if o.current != o.history.Back() { // move history item to current command currentItem := o.current.Value.(*hisItem) // set current to last item o.current = o.history.Back() current = runes.Copy(currentItem.Tmp) } // err only can be a IO error, just report err = o.Update(current, true) // push a new one to commit current command o.historyVer++ o.Push(nil) return }
func (o *opCompleter) OnComplete() { if o.IsInCompleteSelectMode() { o.doSelect() return } buf := o.op.buf rs := buf.Runes() if o.IsInCompleteMode() && runes.Equal(rs, o.candidateSource) { o.EnterCompleteSelectMode() o.doSelect() return } o.ExitCompleteSelectMode() o.candidateSource = rs newLines, offset := o.ac.Do(rs, buf.idx) if len(newLines) == 0 { o.ExitCompleteMode(false) return } // only Aggregate candidates in non-complete mode if !o.IsInCompleteMode() { if len(newLines) == 1 { buf.WriteRunes(newLines[0]) o.ExitCompleteMode(false) return } same, size := runes.Aggregate(newLines) if size > 0 { buf.WriteRunes(same) o.ExitCompleteMode(false) return } } o.EnterCompleteMode(offset, newLines) }
func (o *opHistory) NewHistory(current []rune) { // if just use last command without modify // just clean lastest history if back := o.history.Back(); back != nil { prev := back.Prev() if prev != nil { use := o.showItem(o.current.Value.(*hisItem)) if runes.Equal(use, prev.Value.(*hisItem).Source) { o.current = o.history.Back() o.current.Value.(*hisItem).Clean() o.historyVer++ return } } } if len(current) == 0 { o.current = o.history.Back() if o.current != nil { o.current.Value.(*hisItem).Clean() o.historyVer++ return } } if o.current != o.history.Back() { // move history item to current command use := o.current.Value.(*hisItem) o.current = o.history.Back() current = use.Tmp } o.UpdateHistory(current, true) // push a new one to commit current command o.historyVer++ o.PushHistory(nil) }