From ed28bad02a038236b63bee4272b648244d5182e0 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Sat, 4 Sep 2021 19:58:02 +0200 Subject: [PATCH] Fix Gauge of size zero. (#200) --- src/ftxui/component/component_fuzzer.cpp | 13 +++++++------ src/ftxui/dom/gauge.cpp | 10 +++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ftxui/component/component_fuzzer.cpp b/src/ftxui/component/component_fuzzer.cpp index f6e1b70..e04220c 100644 --- a/src/ftxui/component/component_fuzzer.cpp +++ b/src/ftxui/component/component_fuzzer.cpp @@ -23,16 +23,17 @@ std::string GeneratorString(const char*& data, size_t& size) { while (index < size && data[index]) ++index; + auto out = std::string(data, data + index); + data += index; + size -= index; + + // The input component do not support invalid UTF8 yet. try { - auto out = std::string(data, data + index); - auto w_out = to_wstring(out); - data += index; - size -= index; - return std::move(out); + to_wstring(out); } catch (...) { - // The input component do not support invalid UTF8 yet. return "0"; } + return std::move(out); } int GeneratorInt(const char* data, size_t size) { diff --git a/src/ftxui/dom/gauge.cpp b/src/ftxui/dom/gauge.cpp index 699f64f..252b6c3 100644 --- a/src/ftxui/dom/gauge.cpp +++ b/src/ftxui/dom/gauge.cpp @@ -1,3 +1,4 @@ +#include #include // for allocator, make_shared #include // for string @@ -9,7 +10,7 @@ namespace ftxui { -static std::string charset[] = { +static std::string charset[11] = { #if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK) // Microsoft's terminals often use fonts not handling the 8 unicode // characters for representing the whole gauge. Fallback with less. @@ -23,7 +24,7 @@ static std::string charset[] = { class Gauge : public Node { public: - Gauge(float progress) : progress_(progress) {} + Gauge(float progress) : progress_(std::min(std::max(progress, 0.f), 1.f)) {} void ComputeRequirement() override { requirement_.flex_grow_x = 1; @@ -35,7 +36,10 @@ class Gauge : public Node { } void Render(Screen& screen) override { - float y = box_.y_min; + int y = box_.y_min; + if (y > box_.y_max) + return; + float limit = box_.x_min + progress_ * (box_.x_max - box_.x_min + 1); int limit_int = limit; int x = box_.x_min;