Skip to content

Commit

Permalink
Reduce window width
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum committed May 6, 2022
1 parent 95026a7 commit e0b2d3d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
10 changes: 10 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
FormatStyle: 'file'
Checks: '*,
-llvmlibc-*,
-clang-analyzer-cplusplus.StringChecker,
-concurrency-mt-unsafe,
-cppcoreguidelines-prefer-member-initializer,
-readability-function-cognitive-complexity,
-bugprone-easily-swappable-parameters,
-readability-identifier-length,
-altera-id-dependent-backward-branch,
-altera-unroll-loops,
-altera-struct-pack-align,
-performance-inefficient-string-concatenation,
-readability-isolate-declaration,
-hicpp-special-member-functions,
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.2)

project(
gambal
VERSION 1.3.0
VERSION 1.4.0
LANGUAGES CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down
2 changes: 1 addition & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class config
unsigned int opacity_{ 90 };
int window_x_{ -1 };
int window_y_{ -1 };
bool sigma_{true};
bool sigma_{ true };

public:
explicit config(std::string path)
Expand Down
24 changes: 12 additions & 12 deletions src/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class gui
int char_h{};
int window_width{};
};
std::vector<style> styles_{ { "normal", "6x13", {}, 2, 6, 13, 142 }, { "bold", "7x13B*", {}, 3, 7, 13, 158 } };
std::vector<style> styles_{ { "normal", "6x13", {}, 2, 6, 13, 126 }, { "bold", "7x13B*", {}, 3, 7, 13, 142 } };
decltype(styles_)::iterator style_{ styles_.begin() };
int window_w_{ style_->window_width };
int window_h_{ 1 };
Expand Down Expand Up @@ -410,15 +410,15 @@ class gui
const auto org_top = top;
const auto margin = 5;
const auto& nic = proc_->selected_nic();
const auto w_slots = window_w_ - 10 * style_->char_w - 10;
const auto w_slots = window_w_ - 7 * style_->char_w - 12;
const auto max_rate = nic.max_rate(w_slots);

top += style_->char_h + 1;
draw_string("prime", coord{ margin, top }, humanize_size(max_rate) + "/s");
draw_string("prime", coord{ margin, top }, humanize_size(max_rate) + "s");
top += style_->char_h + 1;
draw_string("rx", coord{ margin, top }, humanize_size(nic.latest_rate().rx) + "/s");
draw_string("rx", coord{ margin, top }, humanize_size(nic.latest_rate().rx) + "s");
top += style_->char_h + 1;
draw_string("tx", coord{ margin, top }, humanize_size(nic.latest_rate().tx) + "/s");
draw_string("tx", coord{ margin, top }, humanize_size(nic.latest_rate().tx) + "s");
top += 4;

auto rate_it = nic.rates().begin();
Expand All @@ -445,8 +445,8 @@ class gui
{
draw_line("light", coord{ margin, top }, dimn{ window_w_ - 2 * margin, 0 });
top += style_->char_h + 1;
draw_string("prime", coord{ margin, top }, "D " + humanize_size(nic.total_bytes().rx, 5));
draw_string("prime", coord{ window_w_ / 2, top }, "U " + humanize_size(nic.total_bytes().tx, 5));
draw_string("prime", coord{ margin, top }, "D " + humanize_size(nic.total_bytes().rx, 4));
draw_string("prime", coord{ window_w_ / 2, top }, "U " + humanize_size(nic.total_bytes().tx, 4));
top += margin;
}

Expand Down Expand Up @@ -572,7 +572,7 @@ class gui
}
}

static std::string humanize_size(uint64_t size, size_t max_width = 4)
static std::string humanize_size(uint64_t size, ssize_t max_width = 3)
{
std::array<const char*, 7> units = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };

Expand All @@ -583,15 +583,15 @@ class gui

const auto order = static_cast<size_t>(std::ceil((str.size() - 3) / 3.0));

auto int_digits = str.size() % 3;
ssize_t int_digits = str.size() % 3;
if (int_digits == 0)
int_digits = 3;

const auto fraction_digits = max_width - int_digits - 1;
if (!fraction_digits)
return str.substr(0, 3) + " " + units[order];
if (fraction_digits <= 0)
return str.substr(0, int_digits) + " " + units[order];

return { str.substr(0, int_digits) + "." + str.substr(int_digits, std::min(fraction_digits, order)) + " " + units[order] };
return { str.substr(0, int_digits) + "." + str.substr(int_digits, std::min(static_cast<size_t>(fraction_digits), order)) + " " + units[order] };
}
};
} // namespace gambal
5 changes: 3 additions & 2 deletions src/proc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class nic
{
n = std::min(rates_.size(), n);
const auto end = std::next(rates_.begin(), n);
const auto max_rate =
*std::max_element(rates_.begin(), end, [](const auto& lhs, const auto& rhs) { return std::max(lhs.rx, lhs.tx) < std::max(rhs.rx, rhs.tx); });
const auto max_rate = *std::max_element(rates_.begin(), end, [](const auto& lhs, const auto& rhs) {
return std::max(lhs.rx, lhs.tx) < std::max(rhs.rx, rhs.tx);
});
return std::max(max_rate.rx, max_rate.tx);
}

Expand Down

0 comments on commit e0b2d3d

Please sign in to comment.