File tree 5 files changed +40
-3
lines changed
5 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 2
2
"UI" : {
3
3
"AmbiguousWidth" : " auto" ,
4
4
"HistoryLines" : 100000 ,
5
- "RTTVHeight" : 10
5
+ "RTTVHeight" : 10 ,
6
+ "Split" :false ,
7
+ "Separator" :" ;"
6
8
},
7
9
"Mud" : {
8
10
"Host" : " mud.pkuxkx.net" ,
Original file line number Diff line number Diff line change 2
2
AmbiguousWidth : auto
3
3
HistoryLines : 100000
4
4
RTTVHeight : 10
5
+ Split : true
6
+ Sparator : ;
5
7
MUD :
6
8
Host : mud.pkuxkx.net
7
9
Port : 8080
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ LOOP:
107
107
108
108
func (c * Client ) DoCmd (cmd string ) {
109
109
switch cmd {
110
- case "exit" , "quit " :
110
+ case "/ exit" :
111
111
c .quit <- true
112
112
return
113
113
case "/version" :
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ type Readline struct {
18
18
19
19
repeat bool
20
20
autoTrim bool
21
+
22
+ cmds []string
23
+ split bool
24
+ separator string
21
25
}
22
26
23
27
func NewReadline () * Readline {
@@ -29,6 +33,12 @@ func NewReadline() *Readline {
29
33
}
30
34
}
31
35
36
+ func (r * Readline ) SetSeparator (s string ) * Readline {
37
+ r .split = true
38
+ r .separator = s
39
+ return r
40
+ }
41
+
32
42
func (r * Readline ) SetRepeat (b bool ) * Readline {
33
43
r .repeat = b
34
44
return r
@@ -69,14 +79,24 @@ func (r *Readline) InputCapture(event *tcell.EventKey) *tcell.EventKey {
69
79
func (r * Readline ) Enter () string {
70
80
text := r .InputField .GetText ()
71
81
82
+ r .cmds = nil
83
+
72
84
if text != "" && r .autoTrim {
73
85
text = strings .TrimSpace (text )
74
86
// 如果 trim 之后变成了空串,则至少保留一个空格,以免用户发不出空格
75
87
if text == "" {
76
88
text = " "
89
+ }else if r .split && "" != r .separator {
90
+ //命令分割
91
+ r .cmds = strings .Split (text ,r .separator )
92
+ if len (r .cmds ) < 2 {
93
+ r .cmds = nil
94
+ }
77
95
}
78
96
}
79
97
98
+
99
+
80
100
last := ""
81
101
if len (r .history ) > 0 {
82
102
last = r .history [len (r .history )- 1 ]
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ type Config struct {
16
16
AmbiguousWidth string `flag:"|auto|二义性字符宽度,可选值: auto/single/double/space"`
17
17
HistoryLines int `flag:"|100000|历史记录保留行数"`
18
18
RTTVHeight int `flag:"|10|历史查看模式下实时文本区域高度"`
19
+ Split bool `flag:"|false|分割多个命令"`
20
+ Separator string `flag:"|;|自定义分隔符"`
19
21
}
20
22
21
23
type UI struct {
@@ -74,6 +76,11 @@ func (ui *UI) Create(title string) {
74
76
ui .ansiWriter = tview .ANSIWriter (ui .realtimeTV )
75
77
76
78
ui .cmdLine = NewReadline ()
79
+
80
+ if ui .config .Split {
81
+ ui .cmdLine .SetSeparator (ui .config .Separator )
82
+ }
83
+
77
84
ui .cmdLine .SetRepeat (true ).
78
85
SetAutoTrim (true ).
79
86
SetFieldBackgroundColor (tcell .ColorBlack ).
@@ -132,7 +139,13 @@ func (ui *UI) InputCapture(event *tcell.EventKey) *tcell.EventKey {
132
139
133
140
if key == tcell .KeyEnter {
134
141
cmd := ui .cmdLine .Enter ()
135
- ui .input <- cmd
142
+ if ui .config .Split && nil != ui .cmdLine .cmds {
143
+ for _ ,cmd := range ui .cmdLine .cmds {
144
+ ui .input <- cmd
145
+ }
146
+ }else {
147
+ ui .input <- cmd
148
+ }
136
149
return nil
137
150
}
138
151
You can’t perform that action at this time.
0 commit comments