diff options
author | Dennis van der Schagt <dennisschagt@gmail.com> | 2024-10-10 17:05:34 +0200 |
---|---|---|
committer | Dennis van der Schagt <dennisschagt@gmail.com> | 2024-10-10 17:05:34 +0200 |
commit | b1ec4cc9d290ecf6c5f09240ab72189dc537b710 (patch) | |
tree | 939ecf590349f7684552c8ea0b36bd1759721266 | |
parent | 46dd39d42670f8c0965de026d1e81d1b346015eb (diff) |
Prepare for ratatui: Return an std::string from Stfl::Form::run()
-rw-r--r-- | include/stflpp.h | 2 | ||||
-rw-r--r-- | src/formaction.cpp | 6 | ||||
-rw-r--r-- | src/pbview.cpp | 12 | ||||
-rw-r--r-- | src/stflpp.cpp | 9 |
4 files changed, 15 insertions, 14 deletions
diff --git a/include/stflpp.h b/include/stflpp.h index a71be20b..dba7aa96 100644 --- a/include/stflpp.h +++ b/include/stflpp.h @@ -25,7 +25,7 @@ public: Form(Form&&) = delete; Form& operator=(Form&&) = delete; - const char* run(int timeout); + std::string run(int timeout); std::string get(const std::string& name); void set(const std::string& name, const std::string& value); diff --git a/src/formaction.cpp b/src/formaction.cpp index 38ebd890..1dcc00c3 100644 --- a/src/formaction.cpp +++ b/src/formaction.cpp @@ -79,11 +79,7 @@ void FormAction::draw_form() std::string FormAction::draw_form_wait_for_event(unsigned int timeout) { - const char* event = f.run(timeout); - if (event == nullptr) { - return ""; - } - return std::string(event); + return f.run(timeout); } void FormAction::recalculate_widget_dimensions() diff --git a/src/pbview.cpp b/src/pbview.cpp index 83251514..6a84cc81 100644 --- a/src/pbview.cpp +++ b/src/pbview.cpp @@ -103,7 +103,7 @@ void PbView::run(bool auto_download, bool wrap_scroll) msg_line_dllist_form.set_text(ctrl.downloads()[idx].status_msg()); } - const char* event = dllist_form.run(500); + const auto event = dllist_form.run(500); if (auto_download) { if (ctrl.get_maxdownloads() > @@ -112,11 +112,11 @@ void PbView::run(bool auto_download, bool wrap_scroll) } } - if (!event || strcmp(event, "TIMEOUT") == 0) { + if (event.empty() || event == "TIMEOUT") { continue; } - if (strcmp(event, "RESIZE") == 0) { + if (event == "RESIZE") { handle_resize(); continue; } @@ -319,12 +319,12 @@ void PbView::run_help() bool quit = false; do { - const char* event = help_form.run(0); - if (!event) { + const auto event = help_form.run(0); + if (event.empty()) { continue; } - if (strcmp(event, "RESIZE") == 0) { + if (event == "RESIZE") { handle_resize(); continue; } diff --git a/src/stflpp.cpp b/src/stflpp.cpp index d864ba5e..ad68089f 100644 --- a/src/stflpp.cpp +++ b/src/stflpp.cpp @@ -42,9 +42,14 @@ Stfl::Form::~Form() } } -const char* Stfl::Form::run(int timeout) +std::string Stfl::Form::run(int timeout) { - return stfl_ipool_fromwc(ipool, stfl_run(f, timeout)); + const auto event = stfl_ipool_fromwc(ipool, stfl_run(f, timeout)); + if (event != nullptr) { + return std::string(event); + } else { + return ""; + } } std::string Stfl::Form::get(const std::string& name) |