diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cfe194..51fa403 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(lwcli) enable_language(CXX) diff --git a/external/lwsf b/external/lwsf index fc2da08..d64a65f 160000 --- a/external/lwsf +++ b/external/lwsf @@ -1 +1 @@ -Subproject commit fc2da0875345f170c45f72806aff556e242118a7 +Subproject commit d64a65f2a2b733b938ab67cdcc62c8cfa0f2b2b7 diff --git a/src/views/manager.cpp b/src/views/manager.cpp index 5b18fb5..f6ae570 100644 --- a/src/views/manager.cpp +++ b/src/views/manager.cpp @@ -577,11 +577,10 @@ namespace lwcli { namespace view for (const auto& elem : stack_) elements.push_back({elem.first, ftxui::xflex_grow(elem.second->Render())}); - //ftxui::hbox({ftxui::text("┃ TWOUI.CIFRO.CODES ┃"), ftxui::filler(), ftxui::text("┃ 2 ┃"), ftxui::filler(), ftxui::text(" ┃ _M_onero ┃")}), - ftxui::Elements out{ //TWOUI.CIFRO.CODES - ftxui::hbox({ftxui::text(" ○━━━━━━━━┓"), ftxui::filler(), ftxui::text(" ○━━━━━┓"), ftxui::filler(), ftxui::text(" ○━━━━━━┓")}), - ftxui::hbox({ftxui::text("┃ cifro.codes ┃"), ftxui::filler(), ftxui::text("┃ z85.pub ┃"), ftxui::filler(), ftxui::text("┃ _M_onero ┃")}), - ftxui::hbox({ftxui::text("┗━━━━━━━━▶ "), ftxui::filler(), ftxui::text("┗━━━━━▶ "), ftxui::filler(), ftxui::text("┗━━━━━━▶ ")}), + ftxui::Elements out{ + ftxui::text(" ○━━━━━━━━━━━━━━━━━┓") | ftxui::hcenter, + ftxui::text("┃ lwcli.cifro.codes ┃") | ftxui::hcenter, + ftxui::text("┗━━━━━━━━━━━━━━━━━▶ ") | ftxui::hcenter, ftxui::separator(), help_, disclaimer_, @@ -592,7 +591,7 @@ namespace lwcli { namespace view decorate::banner(completion_->Render()) }; if (!state_.error.empty()) - out[3] = ftxui::inverted(decorate::banner(ftxui::text(state_.error))); + out[7] = ftxui::inverted(decorate::banner(ftxui::text(state_.error))); const auto base = ftxui::hcenter(ftxui::xflex_grow(ftxui::vbox(std::move(out)))); if (state_.overlay) diff --git a/src/views/settings.cpp b/src/views/settings.cpp index e3f2e2a..576ee8e 100644 --- a/src/views/settings.cpp +++ b/src/views/settings.cpp @@ -173,6 +173,53 @@ namespace lwcli { namespace view } }; + class show_keys_ final : public ftxui::ComponentBase + { + const ftxui::Element title_; + const ftxui::Component buttons_; + const ftxui::Element display_; + + bool Focusable() const override final { return true; } + ftxui::Component ActiveChild() override final { return buttons_; } + + static ftxui::Element get_keys(const std::shared_ptr& wal) + { + return ftxui::vbox({ + ftxui::paragraph(wal->seed()), + ftxui::separator(), + ftxui::gridbox({ + {ftxui::text("View Public: "), ftxui::text(wal->publicViewKey())}, + {ftxui::text("Spend Public: "), ftxui::text(wal->publicSpendKey())}, + {ftxui::text("View Key: "), ftxui::text(wal->secretViewKey())}, + {ftxui::text("Spend Key: "), ftxui::text(wal->secretSpendKey())} + }) + }); + } + + public: + explicit show_keys_(const std::shared_ptr& wal) + : ftxui::ComponentBase(), + title_(ftxui::text(_("Wallet (Secret) Keys"))), + buttons_(ftxui::Button(_("Close"), [] () { throw event::close{}; }, ascii())), + display_(get_keys(wal)) + {} + + bool OnEvent(ftxui::Event event) override final + { + buttons_->OnEvent(std::move(event)); + return true; + } + + ftxui::Element OnRender() override final + { + return ftxui::window(title_, ftxui::vbox({ + ftxui::hcenter(buttons_->Render()), + ftxui::separator(), + display_ + })); + } + }; + class settings_ final : public ftxui::ComponentBase { const std::shared_ptr wal_; @@ -181,9 +228,16 @@ namespace lwcli { namespace view std::string error_; ftxui::Component buttons_; ftxui::Component ui_; + ftxui::Component overlay_; + ftxui::Element cached_; bool Focusable() const override final { return true; } - ftxui::Component ActiveChild() override final { return ui_; } + ftxui::Component ActiveChild() override final + { + if (overlay_) + return overlay_; + return ui_; + } public: explicit settings_(std::shared_ptr&& wal) @@ -193,7 +247,9 @@ namespace lwcli { namespace view config_(std::make_unique(*wal_)), error_(), buttons_(), - ui_() + ui_(), + overlay_(), + cached_() { buttons_ = ftxui::Container::Horizontal({ ftxui::Button(_("Cancel"), [] () { throw event::close{}; }, ascii()), @@ -202,7 +258,8 @@ namespace lwcli { namespace view config_->store(*wal_, error_); if (error_.empty()) throw event::close{}; - }, ascii()) + }, ascii()), + ftxui::Button(_("Secret Keys"), [this] () { show_keys(); }, ascii()) }); ftxui::Components ui; @@ -215,16 +272,39 @@ namespace lwcli { namespace view Add(ui_); } + void show_keys() + { + overlay_ = std::make_shared(wal_); + Add(overlay_); + } + bool OnEvent(ftxui::Event event) override final { - if (event == ftxui::Event::CtrlQ) - throw event::close{}; - ui_->OnEvent(std::move(event)); + try + { + if (overlay_) + return overlay_->OnEvent(std::move(event)); + else if (event == ftxui::Event::CtrlQ) + throw event::close{}; + ui_->OnEvent(std::move(event)); + } + catch (const event::close&) + { + if (!overlay_) + throw; + overlay_->Detach(); + overlay_.reset(); + } return true; } ftxui::Element OnRender() override final { + if (overlay_) + { + return ftxui::dbox({cached_, decorate::overlay(overlay_->Render())}); + } + const auto min_size = ftxui::size(ftxui::WIDTH, ftxui::GREATER_THAN, 5); std::vector grid; grid.reserve(config_->states.size()); @@ -237,11 +317,12 @@ namespace lwcli { namespace view else highlighted = ftxui::inverted(ftxui::text(error_)); - return ftxui::window(title_, ftxui::vbox({ + cached_ = ftxui::window(title_, ftxui::vbox({ ftxui::hcenter(buttons_->Render()), highlighted, ftxui::gridbox(std::move(grid)) })); + return cached_; } }; }