Skip to content

Commit 670df81

Browse files
authored
Merge pull request #14 from janb84/feature/mempool_tab_space_optimization
Mempool tab: Space optimization, element unification.
2 parents acd769c + 7ab77d4 commit 670df81

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ static int run(int argc, char* argv[]) {
11381138
color(Color::Yellow)})
11391139
: (tab_index == 1)
11401140
? hbox({refresh_indicator,
1141-
text(" [↓] select block [Tab/←/→] switch [/] search [q] quit ") |
1141+
text(" [↓] select [Tab/←/→] switch [/] search [q] quit ") |
11421142
color(Color::GrayDark)})
11431143
: (tab_index == 3 && peer_selected >= 0)
11441144
? hbox({refresh_indicator, text(" [\u2191/\u2193] navigate [\u23ce] details [a] "

src/render.cpp

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <iomanip>
55
#include <limits>
66
#include <sstream>
7+
#include <string>
78

89
#include <ftxui/dom/elements.hpp>
910
#include <ftxui/screen/color.hpp>
@@ -36,6 +37,31 @@ Element label_value(const std::string& lbl, const std::string& val, Color val_co
3637
});
3738
}
3839

40+
static Element mempool_stats_box(const AppState& s) {
41+
double usage_frac = s.mempool_max > 0 ? static_cast<double>(s.mempool_usage) /
42+
static_cast<double>(s.mempool_max)
43+
: 0.0;
44+
Color usage_color = usage_frac > 0.8 ? Color::Red
45+
: usage_frac > 0.5 ? Color::Yellow
46+
: Color::Cyan;
47+
return section_box(
48+
"Mempool",
49+
{
50+
label_value(" Transactions : ", fmt_int(s.mempool_tx)),
51+
label_value(" Virtual size : ", fmt_bytes(s.mempool_bytes)),
52+
label_value(" Total fees : ", fmt_btc(s.total_fee)),
53+
label_value(" Min relay fee : ", fmt_satsvb(s.mempool_min_fee)),
54+
hbox({
55+
text(" Memory usage : ") | color(Color::GrayDark),
56+
text(fmt_bytes(s.mempool_usage) + " / " + fmt_bytes(s.mempool_max)) | bold,
57+
text(" "),
58+
gauge(static_cast<float>(usage_frac)) | flex | color(usage_color),
59+
text(" " + std::to_string(static_cast<int>(usage_frac * 100)) + "% ") | bold |
60+
color(usage_color),
61+
}),
62+
});
63+
}
64+
3965
// --- Dashboard --------------------------------------------------------------
4066
Element render_dashboard(const AppState& s) {
4167
// Chain section
@@ -74,24 +100,7 @@ Element render_dashboard(const AppState& s) {
74100
label_value(" Relay fee : ", fmt_satsvb(s.relay_fee)),
75101
});
76102

77-
// Mempool section
78-
double usage_frac = s.mempool_max > 0 ? static_cast<double>(s.mempool_usage) /
79-
static_cast<double>(s.mempool_max)
80-
: 0.0;
81-
auto mempool_section = section_box(
82-
"Mempool",
83-
{
84-
label_value(" Transactions: ", fmt_int(s.mempool_tx)),
85-
label_value(" Size : ", fmt_bytes(s.mempool_bytes)),
86-
label_value(" Total fee : ", fmt_btc(s.total_fee, 4)),
87-
label_value(" Min fee : ", fmt_satsvb(s.mempool_min_fee)),
88-
hbox({
89-
text(" Memory : ") | color(Color::GrayDark),
90-
gauge(static_cast<float>(usage_frac)) | flex |
91-
color(usage_frac > 0.8 ? Color::Red : Color::Cyan),
92-
text(" " + fmt_bytes(s.mempool_usage) + " / " + fmt_bytes(s.mempool_max)) | bold,
93-
}),
94-
});
103+
auto mempool_section = mempool_stats_box(s);
95104

96105
return vbox({
97106
hbox({
@@ -105,33 +114,7 @@ Element render_dashboard(const AppState& s) {
105114

106115
// --- Mempool ----------------------------------------------------------------
107116
Element render_mempool(const AppState& s, int mempool_sel) {
108-
double usage_frac = s.mempool_max > 0 ? static_cast<double>(s.mempool_usage) /
109-
static_cast<double>(s.mempool_max)
110-
: 0.0;
111-
Color usage_color = usage_frac > 0.8 ? Color::Red
112-
: usage_frac > 0.5 ? Color::Yellow
113-
: Color::Cyan;
114-
115-
auto stats_section = section_box(
116-
"Mempool", {
117-
label_value(" Transactions : ", fmt_int(s.mempool_tx)),
118-
label_value(" Virtual size : ", fmt_bytes(s.mempool_bytes)),
119-
label_value(" Total fees : ", fmt_btc(s.total_fee)),
120-
label_value(" Min relay fee : ", fmt_satsvb(s.mempool_min_fee)),
121-
separator(),
122-
text(" Memory usage") | color(Color::GrayDark),
123-
hbox({
124-
text(" "),
125-
gauge(static_cast<float>(usage_frac)) | flex | color(usage_color),
126-
text(" "),
127-
}),
128-
hbox({
129-
text(" Used : ") | color(Color::GrayDark),
130-
text(fmt_bytes(s.mempool_usage)) | bold,
131-
text(" / Max : ") | color(Color::GrayDark),
132-
text(fmt_bytes(s.mempool_max)) | bold,
133-
}),
134-
});
117+
auto stats_section = mempool_stats_box(s);
135118

136119
// Block visualization — vertical fill bars, one column per block.
137120
Element blocks_section;

0 commit comments

Comments
 (0)