...
1 package emulator
2
3 import (
4 "strings"
5
6 "github.com/c-bata/go-prompt"
7 )
8
9
10 var commonKeyBindings = []prompt.KeyBind{
11 {
12
13 Key: prompt.ControlLeft,
14 Fn: func(b *prompt.Buffer) {
15 b.CursorLeft(len([]rune(b.Document().GetWordBeforeCursorWithSpace())))
16 },
17 },
18 {
19
20 Key: prompt.ControlRight,
21 Fn: func(b *prompt.Buffer) {
22 b.CursorRight(len([]rune(b.Document().GetWordAfterCursorWithSpace())))
23 },
24 },
25 }
26
27
28 var sessionKeyBindings = []prompt.KeyBind{
29 {
30
31 Key: prompt.ControlS,
32 Fn: func(b *prompt.Buffer) {
33
34 if strings.Contains(b.Document().CurrentLine(), sendOptionsSplitter) {
35 return
36 }
37
38 prompt.GoLineEnd(b)
39
40 w := b.Document().GetWordBeforeCursorWithSpace()
41 if len(w) == 0 || w[len(w)-1] != ' ' {
42 b.InsertText(" ", false, true)
43 }
44 b.InsertText(sendOptionsSplitter+" ", false, true)
45 },
46 },
47
48
49
50
51
52
53
54
55
56 {
57 Key: prompt.Left,
58 Fn: func(b *prompt.Buffer) {
59 l := len(sendOptionsSplitter)
60 if b.Document().GetWordBeforeCursor() == sendOptionsSplitter {
61 b.CursorLeft(l + 1)
62 }
63 },
64 },
65 {
66
67 Key: prompt.ControlB,
68 Fn: func(b *prompt.Buffer) {
69 l := len(sendOptionsSplitter)
70 if b.Document().GetWordBeforeCursor() == sendOptionsSplitter {
71 b.CursorLeft(l + 1)
72 }
73 },
74 },
75
76 {
77 Key: prompt.Right,
78 Fn: func(b *prompt.Buffer) {
79 l := len(sendOptionsSplitter)
80 if b.Document().GetWordAfterCursor() == sendOptionsSplitter {
81 b.CursorRight(l + 1)
82 }
83 },
84 },
85 {
86
87 Key: prompt.ControlF,
88 Fn: func(b *prompt.Buffer) {
89 l := len(sendOptionsSplitter)
90 if b.Document().GetWordAfterCursor() == sendOptionsSplitter {
91 b.CursorRight(l + 1)
92 }
93 },
94 },
95
96 {
97 Key: prompt.Backspace,
98 Fn: func(b *prompt.Buffer) {
99 l := len(sendOptionsSplitter)
100 if b.Document().GetWordBeforeCursor() == sendOptionsSplitter {
101 b.DeleteBeforeCursor(l + 1)
102 }
103 },
104 },
105 {
106
107 Key: prompt.ControlH,
108 Fn: func(b *prompt.Buffer) {
109 l := len(sendOptionsSplitter)
110 if b.Document().GetWordBeforeCursor() == sendOptionsSplitter {
111 b.DeleteBeforeCursor(l + 1)
112 }
113 },
114 },
115
116 {
117
118 Key: prompt.ControlD,
119 Fn: func(b *prompt.Buffer) {
120 l := len(sendOptionsSplitter)
121 if b.Document().GetWordAfterCursor() == sendOptionsSplitter {
122 b.Delete(l + 1)
123 }
124 },
125 },
126 {
127 Key: prompt.Delete,
128 Fn: func(b *prompt.Buffer) {
129 l := len(sendOptionsSplitter)
130 if b.Document().GetWordAfterCursor() == sendOptionsSplitter {
131 b.Delete(l + 1)
132 }
133 },
134 },
135 }
136
View as plain text