-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimterm-settings.php
More file actions
269 lines (236 loc) · 9.01 KB
/
simterm-settings.php
File metadata and controls
269 lines (236 loc) · 9.01 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
class SimTermSettings
{
private static $instance;
public static function getInstance()
{
if (self::$instance === null)
self::$instance = new SimTermSettings();
return self::$instance;
}
protected function __construct()
{
}
private function __clone()
{
}
private function __wakeup()
{
}
public function basic_registration()
{
/* Settings registration */
register_setting('simterm-settings',
'simterm-default-theme');
register_setting('simterm-settings',
'simterm-default-delay',
array($this, 'number_sanitize'));
register_setting('simterm-settings',
'simterm-command-prepend');
register_setting('simterm-settings',
'simterm-type-prepend');
/* New in 0.2 */
register_setting('simterm-settings',
'simterm-transform-chars',
array($this, 'bool_sanitize'));
register_setting('simterm-settings',
'simterm-output-delay-time',
array($this, 'number_sanitize'));
register_setting('simterm-settings',
'simterm-last-delay-time',
array($this, 'number_sanitize'));
register_setting('simterm-settings',
'simterm-typing-speed',
array($this, 'number_sanitize'));
register_setting('simterm-settings',
'simterm-window-title');
/* New in 0.3 */
register_setting('simterm-settings',
'simterm-window-statusbar',
array($this, 'bool_sanitize'));
register_setting('simterm-settings',
'simterm-default-animated',
array($this, 'bool_sanitize'));
/* --------------------------------------------- */
/* Config fields */
add_option('simterm-type-prepend', '>');
add_option('simterm-command-prepend', '$#');
add_option('simterm-default-delay', '400');
add_option('simterm-default-theme', 'light');
/* New in 0.2 */
add_option('simterm-transform-chars', true);
add_option('simterm-output-delay-time', 10);
add_option('simterm-last-delay-time', 10000);
add_option('simterm-typing-speed', 100);
add_option('simterm-window-title', __('Terminal', 'simterm'));
/* New in 0.3 */
add_option('simterm-window-statusbar', 0);
add_option('simterm-default-animated', 1);
/* -------------------------------------------- */
}
public function register()
{
$this->basic_registration();
/* Config sections */
add_settings_section('simterm-global-settings',
'SimTerm Configuration',
array($this, 'globalConfiguration'),
'simterm-settings');
/* New in 0.2 */
add_settings_field('simterm-default-theme',
__('Theme to use', 'simterm'),
array($this, 'config_default_theme'),
'simterm-settings',
'simterm-global-settings');
/* New in 0.3 */
add_settings_field('simterm-default-animated',
__('Animate windows by default', 'simterm'),
array($this, 'config_default_animate'),
'simterm-settings',
'simterm-global-settings');
add_settings_field('simterm-window-statusbar',
__('Show statusbar with options', 'simterm'),
array($this, 'config_window_statusbar'),
'simterm-settings',
'simterm-global-settings');
/* New in 0.3 */
add_settings_field('simterm-default-delay',
__('Default delay between lines', 'simterm'),
array($this, 'config_default_delay'),
'simterm-settings',
'simterm-global-settings');
/* New in 0.2 */
add_settings_field('simterm-output-delay-time',
__('Default delay between lines', 'simterm'),
array($this, 'config_output_delay'),
'simterm-settings',
'simterm-global-settings');
add_settings_field('simterm-last-delay-time',
__('Default delay for last line', 'simterm'),
array($this, 'config_last_delay'),
'simterm-settings',
'simterm-global-settings');
add_settings_field('simterm-typing-speed',
__('Default typing speed for commands and user input', 'simterm'),
array($this, 'config_typing_speed'),
'simterm-settings',
'simterm-global-settings');
/* New in 0.2 */
/* 0.1 options */
add_settings_field('simterm-command-prepend',
__('Command prepend character', 'simterm'),
array($this, 'config_command_prepend'),
'simterm-settings',
'simterm-global-settings');
add_settings_field('simterm-typing-prepend',
__('Type prepend character', 'simterm'),
array($this, 'config_type_prepend'),
'simterm-settings',
'simterm-global-settings');
/* New in 0.2 */
add_settings_field('simterm-transform-chars',
__('Transform characters', 'simterm'),
array($this, 'config_transform_characters'),
'simterm-settings',
'simterm-global-settings');
add_settings_field('simterm-window-title',
__('Terminal Window Title', 'simterm'),
array($this, 'config_window_title'),
'simterm-settings',
'simterm-global-settings');
}
public function no_sanitize($value)
{
}
public function number_sanitize($value)
{
return (is_numeric($value))?$value:0;
}
public function bool_sanitize($value)
{
return ( (isset( $value )) && ($value) ) ? true : false;
}
public function globalConfiguration()
{
echo SimTermView::render('settings/main');
}
public function register_settings_menu()
{
// add_menu_page('SimTerm Settings', 'SimTerm Settings', 'administrator', 'simterm-settings', array($this, 'globalSettingsPage'), plugins_url( 'simterm/img/icon.png' ));
add_options_page('SimTerm Settings', 'SimTerm settings', 'administrator', 'simterm-settings',array($this, 'globalSettingsPage'));
}
public function globalSettingsPage()
{
echo SimTermView::render('globalsettings');
}
public function config_transform_characters()
{
echo SimTermView::render('settings/checkbox', array('fieldId'=>'simterm-transform-chars', 'fieldText' => __('Fix special characters that look weird in a terminal window', 'simterm')));
}
public function config_window_statusbar()
{
echo SimTermView::render('settings/checkbox', array('default' => false, 'fieldId'=>'simterm-window-statusbar', 'fieldText' => __('Show window statusbar by default. The statusbar has some options to animate/display all/copy to clipboard', 'simterm')));
}
public function config_default_animate()
{
echo SimTermView::render('settings/checkbox', array('fieldId'=>'simterm-default-animated', 'fieldText' => __('Animate terminals by default', 'simterm')));
}
public function config_default_theme()
{
/* In the future, this themes may be extensions of this plugin */
echo SimTermView::render('settings/select', array('fieldId'=>'simterm-default-theme',
'options' => array('regular' => __('Regular', 'simterm'),
'ubuntu' => __('Ubuntu', 'simterm'),
'dark' => __('Dark', 'simterm'),
'light' => __('Light', 'simterm'),
'blue' => __('Blue', 'simterm')),
));
}
public function config_default_delay()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-default-delay',
'fieldText' => __('Delay in milliseconds by default', 'simterm')
));
}
public function config_output_delay()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-output-delay-time',
'fieldText' => __('Delay in milliseconds for multi-line outputs', 'simterm')
));
}
public function config_last_delay()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-last-delay-time',
'fieldText' => __('Delay in milliseconds for the last line. It can be something like 10000 (10 seconds) to wait before replaying animation', 'simterm')
));
}
public function config_typing_speed()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-typing-speed',
'fieldText' => __('Delay in milliseconds for any letter typed in commands and user input (defaults 100ms)', 'simterm')
));
}
public function config_command_prepend()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-command-prepend',
'fieldText' => __('Any of these characters may prepend a command input', 'simterm')
));
}
public function config_type_prepend()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-type-prepend',
'fieldText' => __('Any of these characters may prepend a type input', 'simterm')
));
}
public function config_window_title()
{
echo SimTermView::render('settings/text', array('fieldId'=>'simterm-window-title',
'fieldText' => __('Default window title', 'simterm')
));
}
function validTheme($theme)
{
static $validThemes = array('regular', 'light', 'dark', 'blue', 'ubuntu');
return (in_array($theme, $validThemes));
}
};