Skip to content

Commit e4b4cb7

Browse files
committed
style: apply clang-format
Closes: #573
1 parent e07cc17 commit e4b4cb7

31 files changed

Lines changed: 5721 additions & 4759 deletions

src/btop.cpp

Lines changed: 263 additions & 265 deletions
Large diffs are not rendered by default.

src/btop_cli.cpp

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include "btop_cli.hpp"
44

5+
#include "btop_config.hpp"
6+
#include "btop_shared.hpp"
7+
#include "config.h"
8+
59
#include <algorithm>
610
#include <expected>
711
#include <filesystem>
@@ -18,10 +22,6 @@
1822
#include <fmt/base.h>
1923
#include <fmt/format.h>
2024

21-
#include "btop_config.hpp"
22-
#include "btop_shared.hpp"
23-
#include "config.h"
24-
2525
using namespace std::string_view_literals;
2626

2727
static constexpr auto BOLD = "\033[1m"sv;
@@ -63,16 +63,16 @@ namespace Cli {
6363
if (arg == "-h" || arg == "--help") {
6464
usage();
6565
help();
66-
return std::unexpected { 0 };
66+
return std::unexpected {0};
6767
}
6868
if (arg == "-v" || arg == "-V") {
6969
version();
70-
return std::unexpected { 0 };
70+
return std::unexpected {0};
7171
}
7272
if (arg == "--version") {
7373
version();
7474
build_info();
75-
return std::unexpected { 0 };
75+
return std::unexpected {0};
7676
}
7777

7878
if (arg == "-d" || arg == "--debug") {
@@ -90,15 +90,15 @@ namespace Cli {
9090
if (arg == "-t" || arg == "--tty") {
9191
if (cli.force_tty.has_value()) {
9292
error("tty mode can't be set twice");
93-
return std::unexpected { 1 };
93+
return std::unexpected {1};
9494
}
9595
cli.force_tty = std::make_optional(true);
9696
continue;
9797
}
9898
if (arg == "--no-tty") {
9999
if (cli.force_tty.has_value()) {
100100
error("tty mode can't be set twice");
101-
return std::unexpected { 1 };
101+
return std::unexpected {1};
102102
}
103103
cli.force_tty = std::make_optional(false);
104104
continue;
@@ -108,15 +108,15 @@ namespace Cli {
108108
// This flag requires an argument.
109109
if (++it == args.end()) {
110110
error("Config requires an argument");
111-
return std::unexpected { 1 };
111+
return std::unexpected {1};
112112
}
113113

114114
auto arg = *it;
115-
auto config_file = stdfs::path { arg };
115+
auto config_file = stdfs::path {arg};
116116

117117
if (stdfs::is_directory(config_file)) {
118118
error("Config file can't be a directory");
119-
return std::unexpected { 1 };
119+
return std::unexpected {1};
120120
}
121121

122122
cli.config_file = std::make_optional(config_file);
@@ -126,7 +126,7 @@ namespace Cli {
126126
// This flag requires an argument.
127127
if (++it == args.end()) {
128128
error("Filter requires an argument");
129-
return std::unexpected { 1 };
129+
return std::unexpected {1};
130130
}
131131

132132
auto arg = *it;
@@ -137,7 +137,7 @@ namespace Cli {
137137
// This flag requires an argument.
138138
if (++it == args.end()) {
139139
error("Preset requires an argument");
140-
return std::unexpected { 1 };
140+
return std::unexpected {1};
141141
}
142142

143143
auto arg = *it;
@@ -146,26 +146,26 @@ namespace Cli {
146146
cli.preset = std::make_optional(preset_id);
147147
} catch (std::invalid_argument& e) {
148148
error("Preset must be a positive number");
149-
return std::unexpected { 1 };
149+
return std::unexpected {1};
150150
} catch (std::out_of_range& e) {
151151
error(fmt::format("Preset argument is out of range: {}", arg.data()));
152-
return std::unexpected { 1 };
152+
return std::unexpected {1};
153153
}
154154
continue;
155155
}
156156
if (arg == "--themes-dir") {
157157
// This flag requires an argument.
158158
if (++it == args.end()) {
159159
error("Themes directory requires an argument");
160-
return std::unexpected { 1 };
160+
return std::unexpected {1};
161161
}
162162

163163
auto arg = *it;
164-
auto themes_dir = stdfs::path { arg };
164+
auto themes_dir = stdfs::path {arg};
165165

166166
if (not stdfs::is_directory(themes_dir)) {
167167
error("Themes directory does not exist or is not a directory");
168-
return std::unexpected { 1 };
168+
return std::unexpected {1};
169169
}
170170

171171
cli.themes_dir = std::make_optional(themes_dir);
@@ -175,7 +175,7 @@ namespace Cli {
175175
// This flag requires an argument.
176176
if (++it == args.end()) {
177177
error("Update requires an argument");
178-
return std::unexpected { 1 };
178+
return std::unexpected {1};
179179
}
180180

181181
auto arg = *it;
@@ -184,16 +184,16 @@ namespace Cli {
184184
cli.updates = refresh_rate;
185185
} catch (std::invalid_argument& e) {
186186
error("Update must be a positive number");
187-
return std::unexpected { 1 };
187+
return std::unexpected {1};
188188
} catch (std::out_of_range& e) {
189189
error(fmt::format("Update argument is out of range: {}", arg.data()));
190-
return std::unexpected { 1 };
190+
return std::unexpected {1};
191191
}
192192
continue;
193193
}
194194

195195
error(fmt::format("Unknown argument '{}{}{}'", YELLOW, arg, RESET));
196-
return std::unexpected { 1 };
196+
return std::unexpected {1};
197197
}
198198
return cli;
199199
}
@@ -202,34 +202,26 @@ namespace Cli {
202202
// The idea of using `current_config` is that the CLI parser is run before loading the actual config and thus
203203
// provides default values.
204204
auto config = Config::current_config();
205-
205+
206206
if (isatty(STDOUT_FILENO)) {
207207
std::string buffer {};
208208
// The config buffer ends in `\n`. `std::views::split` will then create an empty element after the last
209209
// newline, which we would write as an additional empty line at the very end.
210210
auto trimmed_config = config.substr(0, config.length() - 1);
211211
for (const auto line : std::views::split(trimmed_config, '\n')) {
212-
auto line_view = std::string_view { line };
212+
auto line_view = std::string_view {line};
213213
if (line_view.starts_with("#")) {
214-
fmt::format_to(
215-
std::back_inserter(buffer), "{1}{0}{2}\n", line_view, BOLD_BRIGHT_BLACK, RESET
216-
);
214+
fmt::format_to(std::back_inserter(buffer), "{1}{0}{2}\n", line_view, BOLD_BRIGHT_BLACK, RESET);
217215
} else if (!line_view.empty()) {
218216
auto pos = line_view.find("=");
219217
if (pos == line_view.npos) {
220218
error("invalid default config: '=' not found");
221-
return std::unexpected { 1 };
219+
return std::unexpected {1};
222220
}
223221
auto name = line_view.substr(0, pos);
224222
auto value = line_view.substr(pos + 1);
225223
fmt::format_to(
226-
std::back_inserter(buffer),
227-
"{2}{0}{4}={3}{1}{4}\n",
228-
name,
229-
value,
230-
BOLD_YELLOW,
231-
BOLD_GREEN,
232-
RESET
224+
std::back_inserter(buffer), "{2}{0}{4}={3}{1}{4}\n", name, value, BOLD_YELLOW, BOLD_GREEN, RESET
233225
);
234226
} else {
235227
fmt::format_to(std::back_inserter(buffer), "\n");
@@ -239,7 +231,7 @@ namespace Cli {
239231
} else {
240232
fmt::print("{}", config);
241233
}
242-
return std::unexpected { 0 };
234+
return std::unexpected {0};
243235
}
244236

245237
void usage() noexcept {
@@ -262,7 +254,9 @@ namespace Cli {
262254
" {2} --default-config{1} Print default config to standard output\n"
263255
" {2}-h, --help{1} Show this help message and exit\n"
264256
" {2}-V, --version{1} Show a version message and exit (more with --version)\n",
265-
BOLD_UNDERLINE, RESET, BOLD
257+
BOLD_UNDERLINE,
258+
RESET,
259+
BOLD
266260
);
267261
}
268262

0 commit comments

Comments
 (0)