-
-
Notifications
You must be signed in to change notification settings - Fork 989
Expand file tree
/
Copy pathbtop_menu.cpp
More file actions
1884 lines (1793 loc) · 59.5 KB
/
btop_menu.cpp
File metadata and controls
1884 lines (1793 loc) · 59.5 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright 2021 Aristocratos (jakob@qvantnet.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
indent = tab
tab-size = 4
*/
#include "btop_menu.hpp"
#include "btop_config.hpp"
#include "btop_draw.hpp"
#include "btop_log.hpp"
#include "btop_shared.hpp"
#include "btop_theme.hpp"
#include "btop_tools.hpp"
#include <errno.h>
#include <signal.h>
#include <array>
#include <cmath>
#include <filesystem>
#include <iostream>
#include <unordered_map>
#include <utility>
#include <fmt/format.h>
using std::array;
using std::ceil;
using std::max;
using std::min;
using std::ref;
using std::views::iota;
using namespace Tools;
namespace fs = std::filesystem;
namespace Menu {
atomic<bool> active (false);
string bg;
bool redraw{true};
int currentMenu = -1;
msgBox messageBox;
int signalToSend{};
int signalKillRet{};
const array<string, 32> P_Signals = {
"0",
#ifdef __linux__
#if defined(__hppa__)
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGSTKFLT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGXCPU",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGUSR1",
"SIGUSR2", "SIGCHLD", "SIGPWR", "SIGVTALRM",
"SIGPROF", "SIGIO", "SIGWINCH", "SIGSTOP",
"SIGTSTP", "SIGCONT", "SIGTTIN", "SIGTTOU",
"SIGURG", "SIGXFSZ", "SIGSYS"
#elif defined(__mips__)
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGUSR1",
"SIGUSR2", "SIGCHLD", "SIGPWR", "SIGWINCH",
"SIGURG", "SIGIO", "SIGSTOP", "SIGTSTP",
"SIGCONT", "SIGTTIN", "SIGTTOU", "SIGVTALRM",
"SIGPROF", "SIGXCPU", "SIGXFSZ"
#elif defined(__alpha__)
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG",
"SIGSTOP", "SIGTSTP", "SIGCONT", "SIGCHLD",
"SIGTTIN", "SIGTTOU", "SIGIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGPWR", "SIGUSR1", "SIGUSR2"
#elif defined (__sparc__)
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG",
"SIGSTOP", "SIGTSTP", "SIGCONT", "SIGCHLD",
"SIGTTIN", "SIGTTOU", "SIGIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGLOST", "SIGUSR1", "SIGUSR2"
#else
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGBUS", "SIGFPE",
"SIGKILL", "SIGUSR1", "SIGSEGV", "SIGUSR2",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGSTKFLT",
"SIGCHLD", "SIGCONT", "SIGSTOP", "SIGTSTP",
"SIGTTIN", "SIGTTOU", "SIGURG", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGIO", "SIGPWR", "SIGSYS"
#endif
#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__APPLE__)
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG",
"SIGSTOP", "SIGTSTP", "SIGCONT", "SIGCHLD",
"SIGTTIN", "SIGTTOU", "SIGIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGINFO", "SIGUSR1", "SIGUSR2"
#else
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "7", "SIGFPE",
"SIGKILL", "10", "SIGSEGV", "12",
"SIGPIPE", "SIGALRM", "SIGTERM", "16",
"17", "18", "19", "20",
"21", "22", "23", "24",
"25", "26", "27", "28",
"29", "30", "31"
#endif
};
std::unordered_map<string, Input::Mouse_loc> mouse_mappings;
const array<array<string, 3>, 3> menu_normal = {
array<string, 3>{
"┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐",
"│ │├─┘ │ ││ ││││└─┐",
"└─┘┴ ┴ ┴└─┘┘└┘└─┘"
},
{
"┬ ┬┌─┐┬ ┌─┐",
"├─┤├┤ │ ├─┘",
"┴ ┴└─┘┴─┘┴ "
},
{
"┌─┐ ┬ ┬ ┬┌┬┐",
"│─┼┐│ │ │ │ ",
"└─┘└└─┘ ┴ ┴ "
}
};
const array<array<string, 3>, 3> menu_selected = {
array<string, 3>{
"╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗",
"║ ║╠═╝ ║ ║║ ║║║║╚═╗",
"╚═╝╩ ╩ ╩╚═╝╝╚╝╚═╝"
},
{
"╦ ╦╔═╗╦ ╔═╗",
"╠═╣╠╣ ║ ╠═╝",
"╩ ╩╚═╝╩═╝╩ "
},
{
"╔═╗ ╦ ╦ ╦╔╦╗ ",
"║═╬╗║ ║ ║ ║ ",
"╚═╝╚╚═╝ ╩ ╩ "
}
};
const array<int, 3> menu_width = {19, 12, 12};
const vector<array<string, 2>> help_text = {
{"Mouse 1", "Clicks buttons and selects in process list."},
{"Mouse scroll", "Scrolls any scrollable list/text under cursor."},
{"Esc, m", "Toggles main menu."},
{"p", "Cycle view presets forwards."},
{"shift + p", "Cycle view presets backwards."},
{"1", "Toggle CPU box."},
{"2", "Toggle MEM box."},
{"3", "Toggle NET box."},
{"4", "Toggle PROC box."},
{"5", "Toggle GPU box."},
{"d", "Toggle disks view in MEM box."},
{"F2, o", "Shows options."},
{"F1, ?, h", "Shows this window."},
{"ctrl + z", "Sleep program and put in background."},
{"ctrl + r", "Reloads config file from disk."},
{"q, ctrl + c", "Quits program."},
{"+, -", "Add/Subtract 100ms to/from update timer."},
{"Up, Down", "Select in process list."},
{"Enter", "Show detailed information for selected process."},
{"Spacebar", "Expand/collapse the selected process in tree view."},
{"C", "Expand/collapse the selected process' children."},
{"Pg Up, Pg Down", "Jump 1 page in process list."},
{"Home, End", "Jump to first or last page in process list."},
{"Left, Right", "Select previous/next sorting column."},
{"b, n", "Select previous/next network device."},
{"i", "Toggle disks io mode with big graphs."},
{"z", "Toggle totals reset for current network device"},
{"a", "Toggle auto scaling for the network graphs."},
{"y", "Toggle synced scaling mode for network graphs."},
{"f, /", "To enter a process filter. Start with ! for regex."},
{"F", "Follow selected process."},
{"u", "Pause process list."},
{"g", "Toggle GPU-only process filter."},
{"delete", "Clear any entered filter."},
{"c", "Toggle per-core cpu usage of processes."},
{"r", "Reverse sorting order in processes box."},
{"e", "Toggle processes tree view."},
{"%", "Toggles memory display mode in processes box."},
{"Selected +, -", "Expand/collapse the selected process in tree view."},
{"Selected t", "Terminate selected process with SIGTERM - 15."},
{"Selected k", "Kill selected process with SIGKILL - 9."},
{"Selected s", "Select or enter signal to send to process."},
{"Selected N", "Select new nice value for selected process."},
{"", " "},
{"", "For bug reporting and project updates, visit:"},
{"", "https://github.com/aristocratos/btop"},
};
const vector<vector<vector<string>>> categories = {
{
{"color_theme",
"Set color theme.",
"",
"Choose from all theme files in (usually)",
"\"/usr/[local/]share/btop/themes\" and",
"\"~/.config/btop/themes\".",
"",
"\"Default\" for builtin default theme.",
"\"TTY\" for builtin 16-color theme.",
"",
"For theme updates see:",
"https://github.com/aristocratos/btop"},
{"theme_background",
"If the theme set background should be shown.",
"",
"Set to False if you want terminal background",
"transparency."},
{"truecolor",
"Sets if 24-bit truecolor should be used.",
"",
"Will convert 24-bit colors to 256 color",
"(6x6x6 color cube) if False.",
"",
"Set to False if your terminal doesn't have",
"truecolor support and can't convert to",
"256-color."},
{"force_tty",
"TTY mode.",
"",
"Set to true to force tty mode regardless",
"if a real tty has been detected or not.",
"",
"Will force 16-color mode and TTY theme,",
"set all graph symbols to \"tty\" and swap",
"out other non tty friendly symbols."},
{"vim_keys",
"Enable vim keys.",
"Set to True to enable \"h,j,k,l\" keys for",
"directional control in lists.",
"",
"Conflicting keys for",
"h (help) and k (kill)",
"is accessible while holding shift."},
{"disable_mouse",
"Disable all mouse events."},
{"disable_presets",
"Disable the presets.",
"",
"\"Off\" All presets are enabled.",
"",
"\"Default\" preset is disabled.",
"",
"\"Custom\" presets are disabled.",
"",
"\"All\" presets are disabled."},
{"presets",
"Define presets for the layout of the boxes.",
"",
"Preset 0 is always all boxes shown with",
"default settings.",
"Max 9 presets.",
"",
"Format: \"box_name:P:G,box_name:P:G\"",
"P=(0 or 1) for alternate positions.",
"G=graph symbol to use for box.",
"",
"Use whitespace \" \" as separator between",
"different presets.",
"",
"Example:",
"\"mem:0:tty,proc:1:default cpu:0:braille\""},
{"shown_boxes",
"Manually set which boxes to show.",
"",
"Available values are \"cpu mem net proc\".",
#ifdef GPU_SUPPORT
"Or \"gpu0\" through \"gpu5\" for GPU boxes.",
#endif
"Separate values with whitespace.",
"",
"Toggle between presets with key \"p\"."},
{"update_ms",
"Update time in milliseconds.",
"",
"Recommended 2000 ms or above for better",
"sample times for graphs.",
"",
"Min value: 100 ms",
"Max value: 86400000 ms = 24 hours."},
{"rounded_corners",
"Rounded corners on boxes.",
"",
"True or False",
"",
"Is always False if TTY mode is ON."},
{"terminal_sync",
"Output synchronization.",
"",
"Use terminal synchronized output sequences",
"to reduce flickering on supported terminals.",
"",
"True or False."},
{"graph_symbol",
"Default symbols to use for graph creation.",
"",
"\"braille\", \"block\" or \"tty\".",
"",
"\"braille\" offers the highest resolution but",
"might not be included in all fonts.",
"",
"\"block\" has half the resolution of braille",
"but uses more common characters.",
"",
"\"tty\" uses only 3 different symbols but will",
"work with most fonts.",
"",
"Note that \"tty\" only has half the horizontal",
"resolution of the other two,",
"so will show a shorter historical view."},
{"clock_format",
"Draw a clock at top of screen.",
"(Only visible if cpu box is enabled!)",
"",
"Formatting according to strftime, empty",
"string to disable.",
"",
"Custom formatting options:",
"\"/host\" = hostname",
"\"/user\" = username",
"\"/uptime\" = system uptime",
"",
"Examples of strftime formats:",
"\"%X\" = locale HH:MM:SS",
"\"%H\" = 24h hour, \"%I\" = 12h hour",
"\"%M\" = minute, \"%S\" = second",
"\"%d\" = day, \"%m\" = month, \"%y\" = year"},
{"base_10_sizes",
"Use base 10 for bits and bytes sizes.",
"",
"Uses KB = 1000 instead of KiB = 1024,",
"MB = 1000KB instead of MiB = 1024KiB,",
"and so on.",
"",
"True or False."},
{"background_update",
"Update main ui when menus are showing.",
"",
"True or False.",
"",
"Set this to false if the menus is flickering",
"too much for a comfortable experience."},
{"show_battery",
"Show battery stats.",
"(Only visible if cpu box is enabled!)",
"",
"Show battery stats in the top right corner",
"if a battery is present."},
{"selected_battery",
"Select battery.",
"",
"Which battery to use if multiple are present.",
"Can be both batteries and UPS.",
"",
"\"Auto\" for auto detection."},
{"show_battery_watts",
"Show battery power.",
"",
"Show discharge power when discharging.",
"Show charging power when charging."},
{"log_level",
"Set loglevel for error.log",
"",
"\"ERROR\", \"WARNING\", \"INFO\" and \"DEBUG\".",
"",
"The level set includes all lower levels,",
"i.e. \"DEBUG\" will show all logging info."},
{"save_config_on_exit",
"Save config on exit.",
"",
"Automatically save current settings to",
"config file on exit.",
"",
"When this is toggled from True to False",
"a save is immediately triggered.",
"This way a manual save can be done by",
"toggling this setting on and off again."}
},
{
{"cpu_bottom",
"Cpu box location.",
"",
"Show cpu box at bottom of screen instead",
"of top."},
{"graph_symbol_cpu",
"Graph symbol to use for graphs in cpu box.",
"",
"\"default\", \"braille\", \"block\" or \"tty\".",
"",
"\"default\" for the general default symbol.",},
{"cpu_graph_upper",
"Cpu upper graph.",
"",
"Sets the CPU/GPU stat shown in upper half of",
"the CPU graph.",
"",
"CPU:",
"\"total\" = Total cpu usage. (Auto)",
"\"user\" = User mode cpu usage.",
"\"system\" = Kernel mode cpu usage.",
"+ more depending on kernel.",
#ifdef GPU_SUPPORT
"",
"GPU:",
"\"gpu-totals\" = GPU usage split by device.",
"\"gpu-vram-totals\" = VRAM usage split by GPU.",
"\"gpu-pwr-totals\" = Power usage split by GPU.",
"\"gpu-average\" = Avg usage of all GPUs.",
"\"gpu-vram-total\" = VRAM usage of all GPUs.",
"\"gpu-pwr-total\" = Power usage of all GPUs.",
"Not all stats are supported on all devices."
#endif
},
{"cpu_graph_lower",
"Cpu lower graph.",
"",
"Sets the CPU/GPU stat shown in lower half of",
"the CPU graph.",
"",
"CPU:",
"\"total\" = Total cpu usage.",
"\"user\" = User mode cpu usage.",
"\"system\" = Kernel mode cpu usage.",
"+ more depending on kernel.",
#ifdef GPU_SUPPORT
"",
"GPU:",
"\"gpu-totals\" = GPU usage split/device. (Auto)",
"\"gpu-vram-totals\" = VRAM usage split by GPU.",
"\"gpu-pwr-totals\" = Power usage split by GPU.",
"\"gpu-average\" = Avg usage of all GPUs.",
"\"gpu-vram-total\" = VRAM usage of all GPUs.",
"\"gpu-pwr-total\" = Power usage of all GPUs.",
"Not all stats are supported on all devices."
#endif
},
{"cpu_invert_lower",
"Toggles orientation of the lower CPU graph.",
"",
"True or False."},
{"cpu_single_graph",
"Completely disable the lower CPU graph.",
"",
"Shows only upper CPU graph and resizes it",
"to fit to box height.",
"",
"True or False."},
#ifdef GPU_SUPPORT
{"show_gpu_info",
"Show gpu info in cpu box.",
"",
"Toggles gpu stats in cpu box and the",
"gpu graph (if \"cpu_graph_lower\" is set to",
"\"Auto\").",
"",
"\"Auto\" to show when no gpu box is shown.",
"\"On\" to always show.",
"\"Off\" to never show."},
#endif
{"check_temp",
"Enable cpu temperature reporting.",
"",
"True or False."},
{"cpu_sensor",
"Cpu temperature sensor.",
"",
"Select the sensor that corresponds to",
"your cpu temperature.",
"",
"Set to \"Auto\" for auto detection."},
{"show_coretemp",
"Show temperatures for cpu cores.",
"",
"Only works if check_temp is True and",
"the system is reporting core temps."},
{"cpu_core_map",
"Custom mapping between core and coretemp.",
"",
"Can be needed on certain cpus to get correct",
"temperature for correct core.",
"",
"Use lm-sensors or similar to see which cores",
"are reporting temperatures on your machine.",
"",
"Format: \"X:Y\"",
"X=core with wrong temp.",
"Y=core with correct temp.",
"Use space as separator between multiple",
"entries.",
"",
"Example: \"4:0 5:1 6:3\""},
{"temp_scale",
"Which temperature scale to use.",
"",
"Celsius, default scale.",
"",
"Fahrenheit, the american one.",
"",
"Kelvin, 0 = absolute zero, 1 degree change",
"equals 1 degree change in Celsius.",
"",
"Rankine, 0 = absolute zero, 1 degree change",
"equals 1 degree change in Fahrenheit."},
{"show_cpu_freq",
"Show CPU frequency.",
"",
"Can cause slowdowns on systems with many",
"cores and certain kernel versions."},
#ifdef __linux__
{"freq_mode",
"How the CPU frequency will be displayed.",
"",
"First, get the frequency from the first",
"core.",
"",
"Range, show the lowest and the highest",
"frequency.",
"",
"Lowest, the lowest frequency.",
"",
"Highest, the highest frequency.",
"",
"Average, sum and divide."},
#endif
{"custom_cpu_name",
"Custom cpu model name in cpu percentage box.",
"",
"Empty string to disable."},
{"show_uptime",
"Shows the system uptime in the CPU box.",
"",
"Can also be shown in the clock by using",
"\"/uptime\" in the formatting.",
"",
"True or False."},
{"show_cpu_watts",
"Shows the CPU power consumption in watts.",
"",
"Requires running `make setcap` or",
"`make setuid` or running with sudo.",
"",
"True or False."},
},
#ifdef GPU_SUPPORT
{
{"nvml_measure_pcie_speeds",
"Measure PCIe throughput on NVIDIA cards.",
"",
"May impact performance on certain cards.",
"",
"True or False."},
{"rsmi_measure_pcie_speeds",
"Measure PCIe throughput on AMD cards.",
"",
"May impact performance on certain cards.",
"",
"True or False."},
{"graph_symbol_gpu",
"Graph symbol to use for graphs in gpu box.",
"",
"\"default\", \"braille\", \"block\" or \"tty\".",
"",
"\"default\" for the general default symbol.",},
{"gpu_mirror_graph",
"Horizontally mirror the GPU graph.",
"",
"True or False."},
{"shown_gpus",
"Manually set which gpu vendors to show.",
"",
"Available values are",
"\"nvidia\", \"amd\", \"intel\",",
"and \"apple\".",
"Separate values with whitespace.",
"",
"A restart is required to apply changes."},
{"custom_gpu_name0",
"Custom gpu0 model name in gpu stats box.",
"",
"Empty string to disable."},
{"custom_gpu_name1",
"Custom gpu1 model name in gpu stats box.",
"",
"Empty string to disable."},
{"custom_gpu_name2",
"Custom gpu2 model name in gpu stats box.",
"",
"Empty string to disable."},
{"custom_gpu_name3",
"Custom gpu3 model name in gpu stats box.",
"",
"Empty string to disable."},
{"custom_gpu_name4",
"Custom gpu4 model name in gpu stats box.",
"",
"Empty string to disable."},
{"custom_gpu_name5",
"Custom gpu5 model name in gpu stats box.",
"",
"Empty string to disable."},
},
#endif
{
{"mem_below_net",
"Mem box location.",
"",
"Show mem box below net box instead of above."},
{"graph_symbol_mem",
"Graph symbol to use for graphs in mem box.",
"",
"\"default\", \"braille\", \"block\" or \"tty\".",
"",
"\"default\" for the general default symbol.",},
{"mem_graphs",
"Show graphs for memory values.",
"",
"True or False."},
{"show_disks",
"Split memory box to also show disks.",
"",
"True or False."},
{"show_io_stat",
"Toggle IO activity graphs.",
"",
"Show small IO graphs that for disk activity",
"(disk busy time) when not in IO mode.",
"",
"True or False."},
{"io_mode",
"Toggles io mode for disks.",
"",
"Shows big graphs for disk read/write speeds",
"instead of used/free percentage meters.",
"",
"True or False."},
{"io_graph_combined",
"Toggle combined read and write graphs.",
"",
"Only has effect if \"io mode\" is True.",
"",
"True or False."},
{"io_graph_speeds",
"Set top speeds for the io graphs.",
"",
"Manually set which speed in MiB/s that",
"equals 100 percent in the io graphs.",
"(100 MiB/s by default).",
"",
"Format: \"device:speed\" separate disks with",
"whitespace \" \".",
"",
"Example: \"/dev/sda:100, /dev/sdb:20\"."},
{"show_swap",
"If swap memory should be shown in memory box.",
"",
"True or False."},
{"swap_disk",
"Show swap as a disk.",
"",
"Ignores show_swap value above.",
"Inserts itself after first disk."},
{"only_physical",
"Filter out non physical disks.",
"",
"Set this to False to include network disks,",
"RAM disks and similar.",
"",
"True or False."},
{"use_fstab",
"(Linux) Read disks list from /etc/fstab.",
"",
"This also disables only_physical.",
"",
"True or False."},
{"zfs_hide_datasets",
"(Linux) Hide ZFS datasets in disks list.",
"",
"Setting this to True will hide all datasets,",
"and only show ZFS pools.",
"",
"(IO stats will be calculated per-pool)",
"",
"True or False."},
{"disk_free_priv",
"(Linux) Type of available disk space.",
"",
"Set to true to show how much disk space is",
"available for privileged users.",
"",
"Set to false to show available for normal",
"users."},
{"disks_filter",
"Optional filter for shown disks.",
"",
"Should be full path of a mountpoint.",
"Separate multiple values with",
"whitespace \" \".",
"",
"Only disks matching the filter will be shown.",
"Prepend \033[3mexclude=\033[23m to only show disks ",
"not matching the filter.",
"",
"Examples:",
"/boot /home/user",
"exclude=/boot /home/user"},
{"zfs_arc_cached",
"(Linux) Count ZFS ARC as cached memory.",
"",
"Add ZFS ARC used to cached memory and",
"ZFS ARC available to available memory.",
"These are otherwise reported by the Linux",
"kernel as used memory.",
"",
"True or False."},
},
{
{"graph_symbol_net",
"Graph symbol to use for graphs in net box.",
"",
"\"default\", \"braille\", \"block\" or \"tty\".",
"",
"\"default\" for the general default symbol.",},
{"swap_upload_download",
"Swap the positions of the upload and download",
"graphs.",
"",
"This allows for a more \"intuitive\" view",
"with download being down, on the bottom."},
{"net_download",
"Fixed network graph download value.",
"",
"Value in Mebibits, default \"100\".",
"",
"Can be toggled with auto button."},
{"net_upload",
"Fixed network graph upload value.",
"",
"Value in Mebibits, default \"100\".",
"",
"Can be toggled with auto button."},
{"net_auto",
"Start in network graphs auto rescaling mode.",
"",
"Ignores any values set above at start and",
"rescales down to 10Kibibytes at the lowest.",
"",
"True or False."},
{"net_sync",
"Network scale sync.",
"",
"Syncs the scaling for download and upload to",
"whichever currently has the highest scale.",
"",
"True or False."},
{"net_iface",
"Network Interface.",
"",
"Manually set the starting Network Interface.",
"",
"Will otherwise automatically choose the NIC",
"with the highest total download since boot."},
{"base_10_bitrate",
"Base 10 bitrate",
"",
"True: Use SI prefixes for bitrates",
" (1000Kbps = 1Mbps)",
"False: Use binary prefixes for bitrates",
" (1024Kibps = 1Mibps)",
"Auto: Use the General -> Base 10 Sizes",
" setting for bitrates",
"",
"True, False, or Auto",},
},
{
{"proc_left",
"Proc box location.",
"",
"Show proc box on left side of screen",
"instead of right."},
{"graph_symbol_proc",
"Graph symbol to use for graphs in proc box.",
"",
"\"default\", \"braille\", \"block\" or \"tty\".",
"",
"\"default\" for the general default symbol.",},
{"proc_sorting",
"Processes sorting option.",
"",
"Possible values:",
"\"pid\", \"program\", \"arguments\", \"threads\",",
"\"user\", \"memory\", \"gpu\",",
"\"gpu memory\", \"cpu lazy\" and",
"\"cpu direct\".",
"",
"\"cpu lazy\" updates top process over time.",
"\"cpu direct\" updates top process",
"directly."},
{"proc_reversed",
"Reverse processes sorting order.",
"",
"True or False."},
{"proc_tree",
"Processes tree view.",
"",
"Set true to show processes grouped by",
"parents with lines drawn between parent",
"and child process."},
{"proc_aggregate",
"Aggregate child's resources in parent.",
"",
"In tree-view, include all child resources",
"with the parent even while expanded."},
{"proc_colors",
"Enable colors in process view.",
"",
"True or False."},
{"proc_gradient",
"Enable process view gradient fade.",
"",
"Fades from top or current selection.",
"Max fade value is equal to current themes",
"\"inactive_fg\" color value."},
{"proc_per_core",
"Process usage per core.",
"",
"If process cpu usage should be of the core",
"it's running on or usage of the total",
"available cpu power.",
"",
"If true and process is multithreaded",
"cpu usage can reach over 100%."},
{"proc_mem_bytes",
"Show memory as bytes in process list.",
" ",
"Will show percentage of total memory",
"if False."},
{"keep_dead_proc_usage",
"Cpu and Mem usage for dead processes",
"",
"Set true if process should preserve the cpu",
"and memory usage of when it died while",
"paused."},
{"proc_cpu_graphs",
"Show cpu graph for each process.",
"",
"True or False"},
{"proc_gpu_graphs",
"Show gpu graph for each process.",
"",
"True or False"},
{"proc_gpu_only",
"Show only GPU-active processes.",
"",
"When enabled, only processes with",
"non-zero GPU usage or GPU memory",
"allocation are shown."},
{"proc_filter_kernel",
"(Linux) Filter kernel processes from output.",
"",
"Set to 'True' to filter out internal",
"processes started by the Linux kernel."},
{"proc_follow_detailed",
"Follow selected process with detailed view",
"",
"If set to 'True' then when opening the",
"detailed view, the process will be",
"followed in the list. Pressing enter",
"again will close the detailed view",
"and stop following the process."},
}
};
msgBox::msgBox() {}
msgBox::msgBox(int width, int boxtype, const vector<string>& content, const std::string_view title)
: width(width), boxtype(boxtype) {
auto tty_mode = Config::getB("tty_mode");
auto rounded = Config::getB("rounded_corners");
const auto& right_up = (tty_mode or not rounded ? Symbols::right_up : Symbols::round_right_up);
const auto& left_up = (tty_mode or not rounded ? Symbols::left_up : Symbols::round_left_up);
const auto& right_down = (tty_mode or not rounded ? Symbols::right_down : Symbols::round_right_down);
const auto& left_down = (tty_mode or not rounded ? Symbols::left_down : Symbols::round_left_down);
height = content.size() + 7;
x = Term::width / 2 - width / 2;
y = Term::height/2 - height/2;
if (boxtype == 2) selected = 1;
button_left = left_up + Symbols::h_line * 6 + Mv::l(7) + Mv::d(2) + left_down + Symbols::h_line * 6 + Mv::l(7) + Mv::u(1) + Symbols::v_line;
button_right = Symbols::v_line + Mv::l(7) + Mv::u(1) + Symbols::h_line * 6 + right_up + Mv::l(7) + Mv::d(2) + Symbols::h_line * 6 + right_down + Mv::u(2);
box_contents = Draw::createBox(x, y, width, height, Theme::c("hi_fg"), true, title) + Mv::d(1);
for (const auto& line : content) {
box_contents += Mv::save + Mv::r(max((size_t)0, (width / 2) - (Fx::uncolor(line).size() / 2) - 1)) + line + Mv::restore + Mv::d(1);
}
}
string msgBox::operator()() {
string out;
int pos = width / 2 - (boxtype == 0 ? 6 : 14);
const auto first_color = (selected == 0 ? Theme::c("hi_fg") : Theme::c("div_line"));
out = Mv::d(1) + Mv::r(pos) + Fx::b + first_color + button_left + (selected == 0 ? Theme::c("title") : Theme::c("main_fg") + Fx::ub)
+ (boxtype == 0 ? " Ok " : " Yes ") + first_color + button_right;
mouse_mappings["button1"] = Input::Mouse_loc{y + height - 4, x + pos + 1, 3, 12 + (boxtype > 0 ? 1 : 0)};
if (boxtype > 0) {
const auto second_color = (selected == 1 ? Theme::c("hi_fg") : Theme::c("div_line"));
out += Mv::r(2) + second_color + button_left + (selected == 1 ? Theme::c("title") : Theme::c("main_fg") + Fx::ub)
+ " No " + second_color + button_right;
mouse_mappings["button2"] = Input::Mouse_loc{y + height - 4, x + pos + 15 + (boxtype > 0 ? 1 : 0), 3, 12};
}
return box_contents + out + Fx::reset;
}
//? Process input
int msgBox::input(const string& key) {
if (key.empty()) return Invalid;
if (is_in(key, "escape", "backspace", "q") or key == "button2") {
return No_Esc;
}
else if (key == "button1" or (boxtype == 0 and str_to_upper(key) == "O")) {
return Ok_Yes;
}
else if (is_in(key, "enter", "space")) {
return selected + 1;
}
else if (boxtype == 0) {
return Invalid;
}
else if (str_to_upper(key) == "Y") {
return Ok_Yes;
}
else if (str_to_upper(key) == "N") {
return No_Esc;
}
else if (is_in(key, "right", "tab")) {
if (++selected > 1) selected = 0;
return Select;
}
else if (is_in(key, "left", "shift_tab")) {
if (--selected < 0) selected = 1;
return Select;
}
return Invalid;
}
void msgBox::clear() {
box_contents.clear();
box_contents.shrink_to_fit();
button_left.clear();
button_left.shrink_to_fit();
button_right.clear();
button_right.shrink_to_fit();
mouse_mappings.erase("button1");
mouse_mappings.erase("button2");
}
enum menuReturnCodes {
NoChange,
Changed,
Closed,
Switch
};
static int signalChoose(const string& key) {
auto s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid"));
static int x{};
static int y{};
static int selected_signal = -1;