#include #include #include #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 using namespace std; using json = nlohmann::json; string renderSearchBar() { auto screen = ftxui::ScreenInteractive::Fullscreen(); ftxui::InputOption option; option.on_enter = screen.ExitLoopClosure(); string searchTerm; ftxui::Component inputSearchTerm = ftxui::Input(&searchTerm, "SMTH", &option); auto component = ftxui::Container::Vertical({ inputSearchTerm }); auto renderer = ftxui::Renderer(component, [&] { return ftxui::vbox({ ftxui::text(" YTCCP "), ftxui::separator(), ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()), }) | ftxui::border; }); screen.Loop(renderer); return searchTerm; } vector getInstances() { vector result; cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, cpr::Parameters{{"sort_by", "api"}}); if (r.status_code > 299) { cerr << "invidious.io returned error code " << r.status_code << "!!" << endl; throw runtime_error("bad response"); } json j = json::parse(r.text); for (json i: j) { if (i[1]["api"]) { result.push_back(i.front()); } } return result; } int main() { cout << renderSearchBar() << endl; vector instances = getInstances(); for (auto i: instances) { cout << i << " "; } cout << endl; }