-
Notifications
You must be signed in to change notification settings - Fork 6
/
seter.go
48 lines (37 loc) · 975 Bytes
/
seter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package pcsliner
import (
"fmt"
"os"
)
// resetPCSLiner 重置 PCSLiner
func resetPCSLiner(oldLiner *PCSLiner) (newLiner *PCSLiner) {
newLiner = NewLiner()
if oldLiner == nil {
return
}
newLiner.Config = oldLiner.Config
// 重新设置历史
if newLiner.Config.historyFile != nil {
newLiner.SetHistory(newLiner.Config.historyFile.Name())
}
newLiner.State.SetCtrlCAborts(newLiner.Config.CtrlCAborts)
newLiner.State.SetCompleter(newLiner.Config.mainCompleter)
oldLiner.Config.historyFile.Close()
return
}
// SetHistory 设置历史记录保存文件
func (pl *PCSLiner) SetHistory(filePath string) (err error) {
if filePath == "" {
return fmt.Errorf("history file not set")
}
pl.Config.historyFile, err = os.Open(filePath)
if err != nil {
return err
}
pl.State.ReadHistory(pl.Config.historyFile)
return nil
}
func (pl *PCSLiner) SetMainCompleter(mc func(line string) []string) {
pl.Config.mainCompleter = mc
pl.State.SetCompleter(mc)
}