Move almost all of main.cpp to application.cpp and add standalone yttui.cpp

This commit is contained in:
Daniel Schulte 2020-12-16 19:41:58 +01:00
parent 507c66bf04
commit 9ae8dff7d9
4 changed files with 42 additions and 10 deletions

View File

@ -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<std::string> &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<std::string> 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();
}

4
application.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
void run_standalone();
void run_embedded(int pty_fd);

View File

@ -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)

7
yttui.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "application.h"
int main(int, char *[])
{
run_standalone();
return 0;
}