diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-03-26 02:07:01 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-03-26 02:07:01 -0700 |
commit | 6cbff5d60cb708eb7f1eb0a598a6bb99d4b3a9e7 (patch) | |
tree | 042004653f503b4f5b64b9337d8defbe5763c276 | |
parent | f12eca235e59c0ea64d2c569674ea7ad31753215 (diff) | |
download | ytcpp-6cbff5d60cb708eb7f1eb0a598a6bb99d4b3a9e7.tar.gz |
very broken
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | CMakeLists.txt | 34 | ||||
-rw-r--r-- | main.cpp | 12 | ||||
-rw-r--r-- | src/main.cpp | 76 |
4 files changed, 110 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore index 8125bf6..6dc2dea 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ __pycache__/ # Distribution / packaging .Python build/ +bin/ develop-eggs/ dist/ downloads/ @@ -194,3 +195,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +# VS Code files +.vscode/ + diff --git a/CMakeLists.txt b/CMakeLists.txt index b11fdf7..1702629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,9 @@ cmake_minimum_required(VERSION 3.26.0) -project(ytcpp) - -add_executable(${PROJECT_NAME} main.cpp) +project(ytcpp + LANGUAGES CXX + VERSION 0.0.1 +) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) @@ -16,4 +17,29 @@ FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git GIT_TAG c4713a704ca12237485ecbfec185f76c2a81bd09) FetchContent_MakeAvailable(cpr) -target_link_libraries(${PROJECT_NAME} PRIVATE cpr::cpr) +include(FetchContent) + +FetchContent_Declare(ftxui + GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui.git + GIT_TAG v4.0.0 +) + +FetchContent_GetProperties(ftxui) +if(NOT ftxui_POPULATED) + FetchContent_Populate(ftxui) + add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() + +FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz) +FetchContent_MakeAvailable(json) + +add_executable(${PROJECT_NAME} src/main.cpp) +target_include_directories(${PROJECT_NAME} PRIVATE src) + +target_link_libraries(${PROJECT_NAME} + PRIVATE cpr::cpr + PRIVATE ftxui::screen + PRIVATE ftxui::dom + PRIVATE ftxui::component + PRIVATE nlohmann_json::nlohmann_json +) diff --git a/main.cpp b/main.cpp deleted file mode 100644 index a48631e..0000000 --- a/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include <cpr/cpr.h> -#include <iostream> - -using namespace std; - -int main() { - - cpr::Response r = cpr::Get(cpr::Url{"https://httpbin.org/get"}); - cout << r.status_code << endl - << r.header["content-type"] << endl - << r.text << endl; -} \ No newline at end of file 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 <cpr/cpr.h> +#include <nlohmann/json.hpp> +#include <string> +#include <iostream> +#include <exception> +#include <vector> + +#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<string> getInstances() { + + vector<string> 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<string> instances = getInstances(); + for (auto i: instances) { + cout << i << " "; + } + cout << endl; +} \ No newline at end of file |