-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcf_params_gui.lua
206 lines (178 loc) · 3.96 KB
/
lcf_params_gui.lua
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env lua
require('workshop.base')
package.path = package.path .. ';./tek_project/?.lua'
local ui = require('tek.ui')
local group =
function(name, ...)
local result =
ui.Group:new(
{
Orientation = 'vertical',
Width = 'fill',
Legend = '',
}
)
result.Legend = name
result.Children = {...}
return result
end
local h_group =
function(header, ...)
local result = group(header, ...)
result.Orientation = 'horizontal'
return result
end
local v_group =
function(header, ...)
local result = group(header, ...)
result.Orientation = 'vertical'
return result
end
local populate_params = request('lcf_params_gui.populate_params')
local generate_snippet = request('lcf_params_gui.generate_snippet')
local app
local command_line_text =
-- ui.FloatText:new(
-- ui.Text:new(
ui.Input:new(
{
Style = 'font:ui-fixed',
}
)
local update_command_line_text =
function()
local config_params = populate_params(app)
local snippet = generate_snippet(config_params)
command_line_text:setValue('Text', snippet)
end
local add_notification =
function(obj, field_name, handler)
assert_table(obj)
assert_string(field_name)
assert_function(handler)
obj:addNotify(
field_name,
ui.NOTIFY_ALWAYS,
{
ui.NOTIFY_SELF,
ui.NOTIFY_FUNCTION,
handler,
}
)
end
local rb =
function(params)
local result = ui.RadioButton:new(params)
add_notification(result, 'Selected', update_command_line_text)
return result
end
local cm =
function(id, value, text)
local params =
{
Id = id,
Text = text,
Selected = value,
}
local result = ui.CheckMark:new(params)
add_notification(result, 'Selected', update_command_line_text)
return result
end
local default_slider_value = 96
local slider_value =
ui.Text:new(
{
Text = default_slider_value,
Width = 'fill',
}
)
local slider =
ui.ScrollBar:new(
{
Id = 'margins_max_line_len',
Kind = 'number',
Min = 15,
Max = 200,
Width = 'free',
Step = 1,
Value = default_slider_value,
}
)
add_notification(
slider,
'Value',
function(_)
slider_value:setValue('Text', slider.Value)
update_command_line_text()
end
)
local group_comments =
v_group(
'comments',
cm('keep_comments', true, 'Keep comments')
)
local group_unparsed_text =
v_group(
'unparsed text',
cm('keep_unparsed_text', true, 'Keep unparsed text')
)
local group_indent =
v_group(
'indent chunk',
rb({Text = 'tabulation', Id = 'indent_tab'}),
rb({Text = 'no indent', Id = 'indent_spc_0'}),
rb({Text = '1 space', Id = 'indent_spc_1'}),
rb({Text = '2 spaces', Id = 'indent_spc_2', Selected = true}),
rb({Text = '3 spaces', Id = 'indent_spc_3'}),
rb({Text = '4 spaces', Id = 'indent_spc_4'})
)
local group_margins =
v_group(
'margins',
h_group(
'Max line length',
slider_value,
slider
),
cm('count_indent_characters', true, 'Count indent characters')
)
group_margins.MinWidth = 400
local group_command_line = command_line_text
local group_main =
v_group(
nil,
h_group(
nil,
group_indent,
group_margins,
group_comments,
group_unparsed_text
),
v_group(
'Command line to type',
group_command_line
)
)
local window =
ui.Window:new(
{
Id = 'choices-window',
Title = '`lua.reformat` command-line parameters generator',
Status = 'hide',
HideOnEscape = true,
SizeButton = true,
Orientation = 'horizontal',
Children =
{
group_main,
},
}
)
app = ui.Application:new()
ui.Application.connect(window)
app:addMember(window)
window:setValue('Status', 'show')
update_command_line_text()
app:run()
local config_params = populate_params(app)
print(generate_snippet(config_params))