summaryrefslogtreecommitdiffstats
path: root/src/btop_config.cpp
blob: 012b0c2d5e5e6a693d22db587c5eda994d6ba184 (plain)
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
/* 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 <array>
#include <robin_hood.h>
#include <ranges>
#include <atomic>
#include <fstream>

#include <btop_config.hpp>
#include <btop_shared.hpp>
#include <btop_tools.hpp>

using robin_hood::unordered_flat_map, std::map, std::array, std::atomic;
namespace fs = std::filesystem;
namespace rng = std::ranges;
using namespace Tools;

//* Functions and variables for reading and writing the btop config file
namespace Config {
	namespace {
		atomic<bool> locked (false);
		atomic<bool> writelock (false);
		bool write_new;

		vector<array<string, 2>> descriptions = {
			{"color_theme", 		"#* Full path to a bashtop/bpytop/btop++ formatted \".theme\" file, \"Default\" and \"TTY\" for builtin themes."},

			{"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."},

			{"force_tty", 			"#* Set to true to force tty mode regardless if a real tty has been detected or not.\n"
									"#* Will force 16-color mode and TTY theme, set all graph symbols to \"tty\" and swap out other non tty friendly symbols."},

			{"graph_symbol", 		"#* Default symbols to use for graph creation, \"braille\", \"block\" or \"tty\".\n"
									"#* \"braille\" offers the highest resolution but might not be included in all fonts.\n"
									"#* \"block\" has half the resolution of braille but uses more common characters.\n"
									"#* \"tty\" uses only 3 different symbols but will work with most fonts and should work in a real TTY.\n"
									"#* Note that \"tty\" only has half the horizontal resolution of the other two, so will show a shorter historical view."},

			{"graph_symbol_cpu", 	"# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},

			{"graph_symbol_mem", 	"# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},

			{"graph_symbol_net", 	"# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},

			{"graph_symbol_proc", 	"# Graph symbol to use for graphs in cpu box, \"default\", \"braille\", \"block\" or \"tty\"."},

			{"shown_boxes", 		"#* Manually set which boxes to show. Available values are \"cpu mem net proc\", separate values with whitespace."},

			{"update_ms", 			"#* Update time in milliseconds, increases automatically if set below internal loops processing time, recommended 2000 ms or above for better sample times for graphs."},

			{"proc_update_mult", 	"#* Processes update multiplier, sets how often the process list is updated as a multiplier of \"update_ms\".\n"
									"#* Set to 2 or higher to greatly decrease bpytop cpu usage. (Only integers)."},

			{"proc_sorting",		"#* Processes sorting, \"pid\" \"program\" \"arguments\" \"threads\" \"user\" \"memory\" \"cpu lazy\" \"cpu responsive\",\n"
									"#* \"cpu lazy\" updates top process over time, \"cpu responsive\" updates top process directly."},

			{"proc_reversed",		"#* Reverse sorting order, True or False."},

			{"proc_tree",			"#* Show processes as a tree."},

			{"proc_colors", 		"#* Use the cpu graph colors in the process list."},

			{"proc_gradient", 		"#* Use a darkening gradient in the process list."},

			{"proc_per_core", 		"#* If process cpu usage should be of the core it's running on or usage of the total available cpu power."},

			{"proc_mem_bytes", 		"#* Show process memory as bytes instead of percent."},

			{"cpu_graph_upper", 	"#* Sets the CPU stat shown in upper half of the CPU graph, \"total\" is always available.\n"
									"#* Select from a list of detected attributes from the options menu."},

			{"cpu_graph_lower", 	"#* Sets the CPU stat shown in lower half of the CPU graph, \"total\" is always available.\n"
									"#* Select from a list of detected attributes from the options menu."},

			{"cpu_invert_lower", 	"#* Toggles if the lower CPU graph should be inverted."},

			{"cpu_single_graph", 	"#* Set to True to completely disable the lower CPU graph."},

			{"show_uptime", 		"#* Shows the system uptime in the CPU box."},

			{"check_temp", 			"#* Show cpu temperature."},

			{"cpu_sensor", 			"#* Which sensor to use for cpu temperature, use options menu to select from list of available sensors."},

			{"show_coretemp", 		"#* Show temperatures for cpu cores also if check_temp is True and sensors has been found."},

			{"temp_scale", 			"#* Which temperature scale to use, available values: \"celsius\", \"fahrenheit\", \"kelvin\" and \"rankine\"."},

			{"show_cpu_freq", 		"#* Show CPU frequency."},

			{"draw_clock", 			"#* Draw a clock at top of screen, formatting according to strftime, empty string to disable."},

			{"background_update", 	"#* Update main ui in background when menus are showing, set this to false if the menus is flickering too much for comfort."},

			{"custom_cpu_name", 	"#* Custom cpu model name, empty string to disable."},

			{"disks_filter", 		"#* Optional filter for shown disks, should be full path of a mountpoint, separate multiple values with a comma \",\".\n"
									"#* Begin line with \"exclude=\" to change to exclude filter, otherwise defaults to \"most include\" filter. Example: disks_filter=\"exclude=/boot, /home/user\"."},

			{"mem_graphs", 			"#* Show graphs instead of meters for memory values."},

			{"show_swap", 			"#* If swap memory should be shown in memory box."},

			{"swap_disk", 			"#* Show swap as a disk, ignores show_swap value above, inserts itself after first disk."},

			{"show_disks", 			"#* If mem box should be split to also show disks info."},

			{"only_physical", 		"#* Filter out non physical disks. Set this to False to include network disks, RAM disks and similar."},

			{"use_fstab", 			"#* Read disks list from /etc/fstab. This also disables only_physical."},

			{"show_io_stat", 		"#* Toggles if io stats should be shown in regular disk usage view."},

			{"io_mode", 			"#* Toggles io mode for disks, showing only big graphs for disk read/write speeds."},

			{"io_graph_combined", 	"#* Set to True to show combined read/write io graphs in io mode."},

			{"io_graph_speeds", 	"#* Set the top speed for the io graphs in MiB/s (10 by default), use format \"device:speed\" separate disks with a comma \",\".\n"
									"#* Example: \"/dev/sda:100, /dev/sdb:20\"."},

			{"net_download", 		"#* Set fixed values for network graphs, default \"10M\" = 10 Mibibytes, possible units \"K\", \"M\", \"G\", append with \"bit\" for bits instead of bytes, i.e \"100mbit\"."},

			{"net_upload", ""},

			{"net_auto", 			"#* Start in network graphs auto rescaling mode, ignores any values set above and rescales down to 10 Kibibytes at the lowest."},

			{"net_sync", 			"#* Sync the scaling for download and upload to whichever currently has the highest scale."},

			{"net_color_fixed", 	"#* If the network graphs color gradient should scale to bandwidth usage or auto scale, bandwidth usage is based on \"net_download\" and \"net_upload\" values."},

			{"net_iface", 			"#* Starts with the Network Interface specified here."},

			{"show_battery", 		"#* Show battery stats in top right if battery is present."},

			{"log_level", 			"#* Set loglevel for \"~/.config/bpytop/error.log\" levels are: \"ERROR\" \"WARNING\" \"INFO\" \"DEBUG\".\n"
									"#* The level set includes all lower levels, i.e. \"DEBUG\" will show all logging info."}
		};

		unordered_flat_map<string, string> strings = {
			{"color_theme", "Default"},
			{"shown_boxes", "cpu mem net proc"},
			{"graph_symbol", "braille"},
			{"graph_symbol_cpu", "default"},
			{"graph_symbol_mem", "default"},
			{"graph_symbol_net", "default"},
			{"graph_symbol_proc", "default"},
			{"proc_sorting", "cpu lazy"},
			{"cpu_graph_upper", "total"},
			{"cpu_graph_lower", "total"},
			{"cpu_sensor", "Auto"},
			{"temp_scale", "celsius"},
			{"draw_clock", "%X"},
			{"custom_cpu_name", ""},
			{"disks_filter", ""},
			{"io_graph_speeds", ""},
			{"net_download", "10M"},
			{"net_upload", "10M"},
			{"net_iface", ""},
			{"log_level", "WARNING"},
			{"proc_filter", ""},
			{"proc_command", ""},
		};
		unordered_flat_map<string, string> stringsTmp;

		unordered_flat_map<string, bool> bools = {
			{"theme_background", true},
			{"truecolor", true},
			{"proc_reversed", false},
			{"proc_tree", false},
			{"proc_colors", true},
			{"proc_gradient", true},
			{"proc_per_core", false},
			{"proc_mem_bytes", true},
			{"cpu_invert_lower", true},
			{"cpu_single_graph", false},
			{"show_uptime", true},
			{"check_temp", true},
			{"show_coretemp", true},
			{"show_cpu_freq", true},
			{"background_update", true},
			{"mem_graphs", true},
			{"show_swap", true},
			{"swap_disk", true},
			{"show_disks", true},
			{"only_physical", true},
			{"use_fstab", false},
			{"show_io_stat", true},
			{"io_mode", false},
			{"io_graph_combined", false},
			{"net_color_fixed", false},
			{"net_auto", true},
			{"net_sync", false},
			{"show_battery", true},
			{"tty_mode", false},
			{"force_tty", false},
			{"lowcolor", false},
			{"show_detailed", false},
			{"proc_filtering", false},
		};
		unordered_flat_map<string, bool> boolsTmp;

		unordered_flat_map<string, int> ints = {
			{"update_ms", 2000},
			{"proc_update_mult", 2},
			{"detailed_pid", 0},
			{"selected_pid", 0},
			{"proc_start", 0},
			{"proc_selected", 0},
		};
		unordered_flat_map<string, int>