-
Notifications
You must be signed in to change notification settings - Fork 212
/
init.jline
185 lines (171 loc) · 5.44 KB
/
init.jline
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#
# All imports added here are imported also to your groovy shell
#
import java.nio.file.*
import java.util.regex.*
import org.jline.utils.*
PATH = [ROOT + 'scripts']
#
# console options
#
CONSOLE_OPTIONS = [:]
CONSOLE_OPTIONS.docs = [:]
CONSOLE_OPTIONS['docs'].put('jline','https://github.com/jline/jline3/wiki')
CONSOLE_OPTIONS['docs'].put('groovy','http://groovy-lang.org/documentation.html')
CONSOLE_OPTIONS['docs'].put('.*groovy/.*','http://docs.groovy-lang.org/latest/html/gapi/')
CONSOLE_OPTIONS['docs'].put('java.*',['https://docs.oracle.com/javase/8/docs/api/',
'http://docs.groovy-lang.org/latest/html/groovy-jdk/'])
CONSOLE_OPTIONS['docs'].put('.*/java.*','https://docs.oracle.com/javase/8/docs/api/')
CONSOLE_OPTIONS['docs'].put('org/jline/.*','https://www.javadoc.io/doc/org.jline/jline/latest/')
CONSOLE_OPTIONS.PRNT_COLORS = 'th=bold,!blue,~grey7,underline:rn=bold,!blue,~grey7:rs=,~grey15:mk=1;34:em=31:vs=32'
#
# customize prnt command
#
def _reader2map(reader){
def out = [:]
out['othersGroupName'] = reader.othersGroupName
out['keyMap'] = reader.keyMap
out['autosuggestion'] = reader.autosuggestion
out['terminal.kind'] = reader.terminal.kind
out
}
def _reader2string(reader){
def out = "["
out += 'othersGroupName:' + reader.othersGroupName + ', '
out += 'keyMap:' + reader.keyMap + ', '
out += 'autosuggestion:' + reader.autosuggestion + ', '
out += 'terminal.kind:' + reader.terminal.kind
out += ']'
out
}
def _number2date(number){
def out = null
try {
out = number instanceof Long ? new Date(number) : number
} catch (Exception e) {
out = number
}
new AttributedString(out.toString())
}
def _orgJline(p) {
def out = p
if (p.toString().startsWith('org.jline')) {
def m = Pattern.compile('(org\\.jline(\\.[a-z]+)*)(.*)').matcher(p.toString())
if (m.find()) {
def asb = new AttributedStringBuilder()
asb.append(m.group(1),AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW + AttributedStyle.BRIGHT))
asb.append(m.group(3))
out = asb.toAttributedString()
}
}
out
}
PRNT_OPTIONS = [:]
PRNT_OPTIONS.objectToMap = [:]
PRNT_OPTIONS.objectToString = [:]
PRNT_OPTIONS.highlightValue = [:]
PRNT_OPTIONS['objectToMap'].put(org.jline.reader.impl.LineReaderImpl, _reader2map)
PRNT_OPTIONS['objectToString'].put(org.jline.reader.impl.LineReaderImpl, _reader2string)
PRNT_OPTIONS['highlightValue'].put('time.*', _number2date)
PRNT_OPTIONS['highlightValue'].put('*', _orgJline)
PRNT_OPTIONS.valueStyle = 'GRON'
PRNT_OPTIONS.delimiter = '│'
GROOVY_OPTIONS = [:]
GROOVY_OPTIONS.identifiersCompletion = true
GROOVY_OPTIONS.allFieldsCompletion = false
GROOVY_OPTIONS.allMethodsCompletion = false
GROOVY_OPTIONS.metaMethodsCompletion = false
GROOVY_OPTIONS.allClassesCompletion = false
GROOVY_OPTIONS.allConstructorsCompletion = false
#
# custom Groovy pipes
#
pipe --delete *
pipe |. '.collect{' '}'
pipe |: '.collectEntries{' '}'
pipe |:: '.collectMany{' '}'
pipe |? '.findAll{' '}'
pipe |?1 '.find{' '}'
pipe |! '.each{' '}'
pipe |# '.take(' ')'
pipe |& '.' ' '
pipe grep '.collect{it.toString()}.findAll{it=~/' '/}'
alias null '|& identity{}'
alias xargs '|; %{0} %{1} %{2} %{3} %{4} %{5} %{6} %{7} %{8} %{9}'
alias sort '|& sort{def p = %{@}; p[0].startsWith("-") ? -it[p[0].substring(1)] : it[p[0]]}'
alias distinct '|& unique()'
#
# test-widget reads widget name from buffer and execute it
#
def _testWidget() {
def name = _buffer().toString().split('\\s+')[0]
_widget "$name"
}
#
# create _tailtip-toggle widget that changes also maximum candidates to display
#
def _tailTipToggle() {
def al = _reader.getWidgets().get('accept-line').toString()
def enabled = al == '_tailtip-accept-line'
if (enabled) {
_reader.setVariable('list-max',100)
_reader.option(org.jline.reader.LineReader.Option.INSERT_BRACKET, true)
} else {
_reader.setVariable('list-max',50)
_reader.option(org.jline.reader.LineReader.Option.INSERT_BRACKET, false)
}
_widget 'tailtip-toggle'
}
#
# widget functions to open web doc of jline and groovy
#
def _docJline() {
:doc jline
}
def _docGroovy() {
:doc groovy
}
#
# widget functions for groovy autosuggestion completion
#
def _toggleFields() {
GROOVY_OPTIONS.allFieldsCompletion = !GROOVY_OPTIONS.allFieldsCompletion
}
def _toggleMethods() {
GROOVY_OPTIONS.allMethodsCompletion = !GROOVY_OPTIONS.allMethodsCompletion
}
def _toggleMetaMethods() {
GROOVY_OPTIONS.metaMethodsCompletion = !GROOVY_OPTIONS.metaMethodsCompletion
}
def _toggleMenuList() {
def optAutoMenu = org.jline.reader.LineReader.Option.AUTO_MENU_LIST
_reader.option(optAutoMenu, !_reader.isSet(optAutoMenu))
}
#
# resolve function keys
#
def _getkey(name) {
def key
key=:tget $name
key.values()[0]
}
_f1 = _getkey('key_f1')
_f2 = _getkey('key_f2')
widget -N _test-widget _testWidget
widget -N _tailtip-toggle _tailTipToggle
widget -N _doc-jline _docJline
widget -N _doc-groovy _docGroovy
widget -N _toggle-fields _toggleFields
widget -N _toggle-methods _toggleMethods
widget -N _toggle-meta-methods _toggleMetaMethods
widget -N _toggle-menu-list _toggleMenuList
keymap '^[^x' _test-widget
keymap '^[s' _tailtip-toggle
keymap '^[f' _toggle-fields
keymap '^[g' _toggle-meta-methods
keymap '^[m' _toggle-methods
keymap '^[l' _toggle-menu-list
if (_f1 && _f2) {
:keymap $_f1 _doc-jline
:keymap $_f2 _doc-groovy
}