From 9ae8dff7d97118c5cc05df47cbef83ff0742288d Mon Sep 17 00:00:00 2001 From: trilader Date: Wed, 16 Dec 2020 19:41:58 +0100 Subject: [PATCH] Move almost all of main.cpp to application.cpp and add standalone yttui.cpp --- main.cpp => application.cpp | 27 +++++++++++++++++++++------ application.h | 4 ++++ meson.build | 14 ++++++++++---- yttui.cpp | 7 +++++++ 4 files changed, 42 insertions(+), 10 deletions(-) rename main.cpp => application.cpp (98%) create mode 100644 application.h create mode 100644 yttui.cpp diff --git a/main.cpp b/application.cpp similarity index 98% rename from main.cpp rename to application.cpp index ac7b03c..e356d68 100644 --- a/main.cpp +++ b/application.cpp @@ -491,7 +491,12 @@ void action_scroll_title_right() { } void action_show_video_detail() { - message_box("Details", "Video details go here..."); + const size_t cols = termpaint_surface_width(surface); + + const Channel &ch = channels.at(selected_channel); + const Video &selected = videos[ch.id][selected_video]; + message_box("Description", text_wrap(selected.description, cols / 8 * 7)); + //message_box("Description", selected.description); } using json = nlohmann::json; @@ -549,14 +554,13 @@ void config_get_string_list(std::vector &buffer, const json &obj, c } } -int main() +static void run() { const std::string module_path = get_module_path(); user_home = std::string(std::getenv("HOME")); std::string database_filename = user_home + "/.local/share/yttui.db"; curl_global_init(CURL_GLOBAL_ALL); - tp_init(); const std::vector config_locations{user_home + "/.config", module_path}; std::string config_file; @@ -665,9 +669,20 @@ int main() } } while (!exit); - tp_shutdown(); db_shutdown(); curl_global_cleanup(); - - return 0; +} + +void run_standalone() +{ + tp_init(); + run(); + tp_shutdown(); +} + +void run_embedded(int pty_fd) +{ + tp_init_from_fd(pty_fd); + run(); + tp_shutdown(); } diff --git a/application.h b/application.h new file mode 100644 index 0000000..816a080 --- /dev/null +++ b/application.h @@ -0,0 +1,4 @@ +#pragma once + +void run_standalone(); +void run_embedded(int pty_fd); diff --git a/meson.build b/meson.build index 2b1896e..3c87c1d 100644 --- a/meson.build +++ b/meson.build @@ -9,18 +9,24 @@ curl_dep = dependency('libcurl') json_dep = dependency('nlohmann_json', version: '>=3.5.0') #ide:editable-filelist -src_files = [ +application_files = [ + 'application.cpp', 'db.cpp', - 'main.cpp', 'tui.cpp', 'yt.cpp', ] -deps = [ +#ide:editable-filelist +application_deps = [ termpaint_dep, sqlite3_dep, curl_dep, json_dep ] -executable('yttui', src_files, dependencies: deps, install: true) +application = static_library('yttui-application', application_files, dependencies: application_deps) + +tui_files = [ + 'yttui.cpp', +] +executable('yttui', tui_files, link_with: [application], install: true) diff --git a/yttui.cpp b/yttui.cpp new file mode 100644 index 0000000..03f81e9 --- /dev/null +++ b/yttui.cpp @@ -0,0 +1,7 @@ +#include "application.h" + +int main(int, char *[]) +{ + run_standalone(); + return 0; +}