func (o *opHistory) historyUpdatePath(path string) {
	o.fdLock.Lock()
	defer o.fdLock.Unlock()
	f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		return
	}
	o.fd = f
	r := bufio.NewReader(o.fd)
	total := 0
	for ; ; total++ {
		line, err := r.ReadString('\n')
		if err != nil {
			break
		}
		line = strings.TrimSpace(line)
		if len(line) == 0 {
			continue
		}
		o.Push([]rune(line))
		o.Compact()
	}
	if total > o.cfg.HistoryLimit {
		o.rewriteLocked()
	}
	o.historyVer++
	o.Push(nil)
	return
}
only called by newOpHistory
package readline
import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strings"
	"sync"
)
type hisItem struct {
	Source  []rune
	Version int64
	Tmp     []rune
}
func (h *hisItem) Clean() {
	h.Source = nil
	h.Tmp = nil
}
type opHistory struct {
	cfg        *Config
	history    *list.List
	historyVer int64
	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
}
func (o *opHistory) Reset() {
	o.history = list.New()
	o.current = nil
}
func (o *opHistory) IsHistoryClosed() bool {
	o.fdLock.Lock()
	defer o.fdLock.Unlock()
	return o.fd.Fd() == ^(uintptr(0))
}
func (o *opHistory) Init() {
	if o.IsHistoryClosed() {
		o.initHistory()
	}
}
func (o *opHistory) initHistory() {
	if o.cfg.HistoryFile != "" {
		o.historyUpdatePath(o.cfg.HistoryFile)
	}
}