#include #include #include #include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component.hpp" // for Input, Renderer, Vertical #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/component_options.hpp" // for InputOption #include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive #include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border #include "ftxui/util/ref.hpp" // for Ref #include "tui.hpp" using namespace std; bool Tui::renderSearchBar(string& searchTerm, int& searchingFor) { cancel = false; auto screen = ftxui::ScreenInteractive::Fullscreen(); ftxui::InputOption option; option.on_enter = screen.ExitLoopClosure(); ftxui::Component inputSearchTerm = ftxui::Input(&searchTerm, "SMTH", &option); vector searchingForOptions = { "Videos", "Channels", "Playlists" }; ftxui::Component selectSearchFor = ftxui::Toggle(&searchingForOptions, &searchingFor); string cancelLabel = "Cancel"; ftxui::Component cancelButton = ftxui::Button(&cancelLabel, cancelAndExit(screen)); string searchLabel = "Search"; ftxui::Component searchButton = ftxui::Button(&searchLabel, screen.ExitLoopClosure()); ftxui::Component component = ftxui::Container::Vertical({ inputSearchTerm, selectSearchFor, cancelButton, searchButton }); auto renderer = ftxui::Renderer(component, [&] { return ftxui::vbox({ ftxui::text(" YTCCP "), ftxui::separator(), ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()), ftxui::separator(), ftxui::hbox(ftxui::text(" Search For: "), selectSearchFor->Render()), ftxui::separator(), ftxui::hbox({ cancelButton->Render() | ftxui::size(ftxui::WIDTH, ftxui::LESS_THAN, 20), ftxui::filler(), searchButton->Render() | ftxui::size(ftxui::WIDTH, ftxui::LESS_THAN, 20), }), }) | ftxui::border; }); screen.Loop(renderer); return true; } bool Tui::isCancelled() { return cancel; } ftxui::Closure Tui::cancelAndExit(ftxui::ScreenInteractive& screen) { cancel = true; return screen.ExitLoopClosure(); }