From 6cbff5d60cb708eb7f1eb0a598a6bb99d4b3a9e7 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Sun, 26 Mar 2023 02:07:01 -0700 Subject: very broken --- src/main.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/main.cpp (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..923f30f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,76 @@ +#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; +} \ No newline at end of file -- cgit 1.4.1-2-gfad0 f3893869f1f4e4a79263a234253b92'>plain) (tree)
1
2
3
4
5
6
7
8
9