44 you may not use this file except in compliance with the License.
55 You may obtain a copy of the License at
66
7- http://www.apache.org/licenses/LICENSE-2.0
7+ http://www.apache.org/licenses/LICENSE-2.0
88
99 Unless required by applicable law or agreed to in writing, software
1010 distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,120 +21,140 @@ tab-size = 4
2121#include < filesystem>
2222#include < optional>
2323#include < string>
24- #include < vector>
25-
2624#include < unordered_map>
25+ #include < vector>
2726
2827using std::string;
2928using std::vector;
3029
3130// * Functions and variables for reading and writing the btop config file
3231namespace Config {
3332
34- extern std::filesystem::path conf_dir;
35- extern std::filesystem::path conf_file;
36-
37- extern std::unordered_map<std::string_view, string> strings;
38- extern std::unordered_map<std::string_view, string> stringsTmp;
39- extern std::unordered_map<std::string_view, bool > bools;
40- extern std::unordered_map<std::string_view, bool > boolsTmp;
41- extern std::unordered_map<std::string_view, int > ints;
42- extern std::unordered_map<std::string_view, int > intsTmp;
43-
44- const vector<string> valid_graph_symbols = { " braille" , " block" , " tty" };
45- const vector<string> valid_graph_symbols_def = { " default" , " braille" , " block" , " tty" };
46- const vector<string> valid_boxes = {
47- " cpu" , " mem" , " net" , " proc"
33+ extern std::filesystem::path conf_dir;
34+ extern std::filesystem::path conf_file;
35+
36+ extern std::unordered_map<std::string_view, string> strings;
37+ extern std::unordered_map<std::string_view, string> stringsTmp;
38+ extern std::unordered_map<std::string_view, bool > bools;
39+ extern std::unordered_map<std::string_view, bool > boolsTmp;
40+ extern std::unordered_map<std::string_view, int > ints;
41+ extern std::unordered_map<std::string_view, int > intsTmp;
42+
43+ const vector<string> valid_graph_symbols = {" braille" , " block" , " tty" };
44+ const vector<string> valid_graph_symbols_def = {" default" , " braille" , " block" , " tty" };
45+ const vector<string> valid_boxes = {
46+ " cpu" ,
47+ " mem" ,
48+ " net" ,
49+ " proc"
4850#ifdef GPU_SUPPORT
49- ," gpu0" , " gpu1" , " gpu2" , " gpu3" , " gpu4" , " gpu5"
51+ ,
52+ " gpu0" ,
53+ " gpu1" ,
54+ " gpu2" ,
55+ " gpu3" ,
56+ " gpu4" ,
57+ " gpu5"
5058#endif
51- };
52- const vector<string> temp_scales = { " celsius" , " fahrenheit" , " kelvin" , " rankine" };
59+ };
60+ const vector<string> temp_scales = {" celsius" , " fahrenheit" , " kelvin" , " rankine" };
5361#ifdef __linux__
54- const vector<string> freq_modes = { " first" , " range" , " lowest" , " highest" , " average" };
62+ const vector<string> freq_modes = {" first" , " range" , " lowest" , " highest" , " average" };
5563#endif
5664#ifdef GPU_SUPPORT
57- const vector<string> show_gpu_values = { " Auto" , " On" , " Off" };
65+ const vector<string> show_gpu_values = {" Auto" , " On" , " Off" };
5866#endif
59- const vector<string> base_10_bitrate_values = { " Auto" , " True" , " False" };
60- extern vector<string> current_boxes;
61- extern vector<string> preset_list;
62- extern vector<string> available_batteries;
63- extern int current_preset;
67+ const vector<string> base_10_bitrate_values = {" Auto" , " True" , " False" };
68+ extern vector<string> current_boxes;
69+ extern vector<string> preset_list;
70+ extern vector<string> available_batteries;
71+ extern int current_preset;
6472
65- extern bool write_new;
73+ extern bool write_new;
6674
67- constexpr int ONE_DAY_MILLIS = 1000 * 60 * 60 * 24 ;
75+ constexpr int ONE_DAY_MILLIS = 1000 * 60 * 60 * 24 ;
6876
69- [[nodiscard]] std::optional<std::filesystem::path> get_config_dir () noexcept ;
77+ [[nodiscard]] std::optional<std::filesystem::path> get_config_dir () noexcept ;
7078
71- // * Check if string only contains space separated valid names for boxes and set current_boxes
72- bool set_boxes (const string& boxes);
79+ // * Check if string only contains space separated valid names for boxes and set current_boxes
80+ bool set_boxes (const string& boxes);
7381
74- bool validBoxSizes (const string& boxes);
82+ bool validBoxSizes (const string& boxes);
7583
76- // * Toggle box and update config string shown_boxes
77- bool toggle_box (const string& box);
84+ // * Toggle box and update config string shown_boxes
85+ bool toggle_box (const string& box);
7886
79- // * Parse and setup config value presets
80- bool presetsValid (const string& presets);
87+ // * Parse and setup config value presets
88+ bool presetsValid (const string& presets);
8189
82- // * Apply selected preset
83- bool apply_preset (const string& preset);
90+ // * Apply selected preset
91+ bool apply_preset (const string& preset);
8492
85- bool _locked (const std::string_view name);
93+ bool _locked (const std::string_view name);
8694
87- // * Return bool for config key <name>
88- inline bool getB (const std::string_view name) { return bools.at (name); }
95+ // * Return bool for config key <name>
96+ inline bool getB (const std::string_view name) {
97+ return bools.at (name);
98+ }
8999
90- // * Return integer for config key <name>
91- inline const int & getI (const std::string_view name) { return ints.at (name); }
100+ // * Return integer for config key <name>
101+ inline const int & getI (const std::string_view name) {
102+ return ints.at (name);
103+ }
92104
93- // * Return string for config key <name>
94- inline const string& getS (const std::string_view name) { return strings.at (name); }
105+ // * Return string for config key <name>
106+ inline const string& getS (const std::string_view name) {
107+ return strings.at (name);
108+ }
95109
96- string getAsString (const std::string_view name);
110+ string getAsString (const std::string_view name);
97111
98- extern string validError;
112+ extern string validError;
99113
100- bool intValid (const std::string_view name, const string& value);
101- bool stringValid (const std::string_view name, const string& value);
114+ bool intValid (const std::string_view name, const string& value);
115+ bool stringValid (const std::string_view name, const string& value);
102116
103- // * Set config key <name> to bool <value>
104- inline void set (const std::string_view name, bool value) {
105- if (_locked (name)) boolsTmp.insert_or_assign (name, value);
106- else bools.at (name) = value;
107- }
117+ // * Set config key <name> to bool <value>
118+ inline void set (const std::string_view name, bool value) {
119+ if (_locked (name))
120+ boolsTmp.insert_or_assign (name, value);
121+ else
122+ bools.at (name) = value;
123+ }
108124
109- // * Set config key <name> to int <value>
110- inline void set (const std::string_view name, const int value) {
111- if (_locked (name)) intsTmp.insert_or_assign (name, value);
112- else ints.at (name) = value;
113- }
125+ // * Set config key <name> to int <value>
126+ inline void set (const std::string_view name, const int value) {
127+ if (_locked (name))
128+ intsTmp.insert_or_assign (name, value);
129+ else
130+ ints.at (name) = value;
131+ }
114132
115- // * Set config key <name> to string <value>
116- inline void set (const std::string_view name, const string& value) {
117- if (_locked (name)) stringsTmp.insert_or_assign (name, value);
118- else strings.at (name) = value;
119- }
133+ // * Set config key <name> to string <value>
134+ inline void set (const std::string_view name, const string& value) {
135+ if (_locked (name))
136+ stringsTmp.insert_or_assign (name, value);
137+ else
138+ strings.at (name) = value;
139+ }
120140
121- // * Flip config key bool <name>
122- void flip (const std::string_view name);
141+ // * Flip config key bool <name>
142+ void flip (const std::string_view name);
123143
124- // * Lock config and cache changes until unlocked
125- void lock ();
144+ // * Lock config and cache changes until unlocked
145+ void lock ();
126146
127- // * Unlock config and write any cached values to config
128- void unlock ();
147+ // * Unlock config and write any cached values to config
148+ void unlock ();
129149
130- // * Load the config file from disk
131- void load (const std::filesystem::path& conf_file, vector<string>& load_warnings);
150+ // * Load the config file from disk
151+ void load (const std::filesystem::path& conf_file, vector<string>& load_warnings);
132152
133- // * Write the config file to disk
134- void write ();
153+ // * Write the config file to disk
154+ void write ();
135155
136- auto get_log_file () -> std::optional<std::filesystem::path>;
156+ auto get_log_file () -> std::optional<std::filesystem::path>;
137157
138- // Write default config to an in-memory buffer
139- [[nodiscard]] auto current_config () -> std::string;
140- }
158+ // Write default config to an in-memory buffer
159+ [[nodiscard]] auto current_config () -> std::string;
160+ } // namespace Config
0 commit comments