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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
package Loadbars::HelpDispatch;
use strict;
use warnings;
use Loadbars::Constants;
use Loadbars::Shared;
sub create () {
my $hosts = '';
my $textdesc = <<END;
For more help please consult the manual page or press the 'h' hotkey during program execution and watch this terminal window.
END
# mode 1: Option is shown in the online help menu (stdout not sdl)
# mode 2: Option is shown in the 'usage' screen from the command line
# mode 4: Option is used to generate the GetOptions parameters for Getopt::Long
# Combinations: Like chmod(1)
my %d = (
cpuaverage => {
menupos => 3,
help => 'Num of cpu samples for avg. (more fluent animations)',
mode => 6,
type => 'i'
},
cpuaverage_hot_up => {
menupos => 4,
cmd => 'a',
help => 'Increases number of cpu samples for calculating avg. by 1',
mode => 1
},
cpuaverage_hot_dn => {
menupos => 5,
cmd => 'y',
help => 'Decreases number of cpu samples for calculating avg. by 1',
mode => 1
},
netaverage => {
menupos => 6,
help => 'Num of net samples for avg. (more fluent animations)',
mode => 6,
type => 'i'
},
netaverage_hot_up => {
menupos => 7,
cmd => 'd',
help => 'Increases number of net samples for calculating avg. by 1',
mode => 1
},
netaverage_hot_dn => {
menupos => 8,
cmd => 'c',
help => 'Decreases number of net samples for calculating avg. by 1',
mode => 1
},
netint => {
menupos => 6,
help => 'Interface to show netstats for (default: eth0)',
mode => 6,
type => 's'
},
netint_hot => {
menupos => 17,
cmd => 'n',
help => 'Iterate to next net interface',
mode => 1
},
netlink => {
menupos => 6,
help =>
'Force interface link speed (mbit, 10mbit, 100mbit, gbit, 10gbit or a mbytes/s number e.g. 3 for 3mbit)',
mode => 6,
type => 's'
},
netlink_hot_up => {
menupos => 9,
cmd => 'f',
help => 'Increases net interface link speed reference by factor 10',
mode => 1
},
netlink_hot_dn => {
menupos => 10,
cmd => 'v',
help => 'Decreases net interface link speed reference by factor 10',
mode => 1
},
barwidth => {
menupos => 11,
help => 'Set bar width',
mode => 6,
type => 'i'
},
windowwidth_hot_up => {
menupos => 90,
help => 'Increase window width by 100px',
cmd => 'right',
mode => 1,
},
windowwidth_hot_dn => {
menupos => 91,
help => 'Decrease window width by 100px',
cmd => 'left',
mode => 1,
},
windowheight_hot_up => {
menupos => 92,
help => 'Increase window height by 100px',
cmd => 'down',
mode => 1,
},
windowheight_hot_dn => {
menupos => 93,
help => 'Decrease window height by 100px',
cmd => 'up',
mode => 1,
},
cluster => {
menupos => 6,
help => 'Cluster name from /etc/clusters',
var => \$C{cluster},
mode => 6,
type => 's'
},
configuration => {
menupos => 6,
cmd => 'c',
help => 'Show current configuration',
mode => 4
},
extended => {
menupos => 6,
help => 'Toggle extended display (0 or 1)',
mode => 7,
type => 'i'
},
extended_hot => {
menupos => 23,
cmd => 'e',
help => 'Toggle extended mode',
mode => 1
},
hasagent => {
menupos => 10,
help => 'SSH key is already known by the SSH agent (0 or 1)',
mode => 6,
type => 'i'
},
height => {
menupos => 10,
help => 'Set windows height',
mode => 6,
type => 'i'
},
help_hot => {
menupos => 11,
cmd => 'h',
help => 'Prints this help screen',
mode => 1
},
hosts => {
menupos => 12,
help =>
'Comma sep. list of hosts; optional: user@ in front to each host',
var => \$hosts,
mode => 6,
type => 's'
},
maxwidth => {
menupos => 16,
help => 'Set max width',
mode => 6,
type => 'i'
},
quit_hot => { menupos => 16, cmd => 'q', help => 'Quits', mode => 1 },
writeconfig_hot => {
menupos => 16,
cmd => 'w',
help => 'Write config to config file',
mode => 1
},
showcores => {
menupos => 17,
help => 'Toggle core display (0 or 1)',
mode => 7,
type => 'i'
},
showcores_hot =>
{ menupos => 17, cmd => '1', help => 'Toggle show cores', mode => 1 },
showmem => {
menupos => 17,
help => 'Toggle mem display (0 or 1)',
mode => 7,
type => 'i'
},
showmem_hot =>
{ menupos => 17, cmd => '2', help => 'Toggle show mem', mode => 1 },
shownet => {
menupos => 17,
help => 'Toggle net display (0 or 1)',
mode => 7,
type => 'i'
},
shownet_hot =>
{ menupos => 17, cmd => '3', help => 'Toggle show net', mode => 1 },
sshopts =>
{ menupos => 20, help => 'Set SSH options', mode => 6, type => 's' },
title => {
menupos => 21,
help => 'Set title bar text',
mode => 6,
type => 's'
},
);
my %d_by_short = map {
$d{$_}{cmd} => $d{$_}
} grep {
exists $d{$_}{cmd}
} keys %d;
my $closure = sub ($;$) {
my ( $arg, @rest ) = @_;
if ( $arg eq 'command' ) {
my ( $cmd, @args ) = @rest;
my $cb = $d{$cmd};
$cb = $d_by_short{$cmd} unless defined $cb;
unless ( defined $cb ) {
system $cmd;
return 0;
}
if ( length $cmd == 1 ) {
for my $key ( grep { exists $d{$_}{cmd} } keys %d ) {
do { $cmd = $key; last } if $d{$key}{cmd} eq $cmd;
}
}
}
elsif ( $arg eq 'hotkeys' ) {
$textdesc . "Hotkeys:\n" . (
join "\n",
map {
"$_ - $d_by_short{$_}{help}"
} grep {
$d_by_short{$_}{mode} & 1 and exists $d_by_short{$_}{help};
} sort { $d_by_short{$a}{menupos} <=> $d_by_short{$b}{menupos} }
sort keys %d_by_short
);
}
elsif ( $arg eq 'usage' ) {
$textdesc . (
join "\n",
map {
if ( $_ eq 'help' )
{
"--$_ - $d{$_}{help}";
}
else {
"--$_ <ARG> - $d{$_}{help}";
}
} grep {
$d{$_}{mode} & 2
and exists $d{$_}{help}
} sort { $d{$a}{menupos} <=> $d{$b}{menupos} } sort keys %d
);
}
elsif ( $arg eq 'options' ) {
map {
"$_="
. $d{$_}{type} => (
defined $d{$_}{var}
? $d{$_}{var}
: \$C{$_}
);
} grep {
$d{$_}{mode} & 4 and exists $d{$_}{type};
} sort keys %d;
}
};
$d{configuration}{cb} = sub {
Loadbars::Main::say sort map {
"$_->[0] = $_->[1]"
} grep {
defined $_->[1]
} map {
[
$_ => exists $d{$_}{var}
? ${ $d{$_}{var} }
: $C{$_}
]
} keys %d;
};
return ( \$hosts, $closure );
}
1;
|