From 93eadf68c85fb2ae8fdd6d8e0a213db3b5df2ec5 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sat, 14 Oct 2023 22:06:56 -0500 Subject: [PATCH] set termion as backend, curses as frontend. setup for new page turning system to accomodate cursive --- .idea/workspace.xml | 69 ++++++++++++++++++++------------- Cargo.toml | 6 ++- src/main.rs | 94 +++++++++++++++++++++++++++++++++------------ 3 files changed, 118 insertions(+), 51 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index be60bd5..612aab9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,7 +15,7 @@ - + @@ -47,28 +47,28 @@ - { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.cidr.known.project.marker": "true", + "WebServerToolWindowFactoryState": "false", + "cf.first.check.clang-format": "false", + "cidr.known.project.marker": "true", + "git-widget-placeholder": "master", + "ignore.virus.scanning.warn.message": "true", + "last_opened_file_path": "/home/dan/CLionProjects/bibliofile", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true", + "org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true", + "org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true", + "settings.editor.selected.configurable": "preferences.pluginManager", + "vue.rearranger.settings.migration": "true" } -}]]> +} - + + + + @@ -198,7 +214,8 @@ - diff --git a/Cargo.toml b/Cargo.toml index 01dc0c3..ecb74eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cursive = "0.20.0" epub = "2.0.0" scraper = "*" + +[dependencies.cursive] +version = "*" +default-features = false +features = ["termion-backend"] diff --git a/src/main.rs b/src/main.rs index 1406f88..c72c86b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,17 @@ Program: Bibliofile Language: Rustc 1.71.0 ide: CLion -Operating system: Fedora 38/WSL +Operating system: POP_OS Purpose: TUI-based ereader and library manager for Linux terminal environments. -Last edited: 7/27/23 +Last edited: 10/14/23 */ - mod html_module; - +use cursive::views::{Dialog, TextView}; use epub::doc::EpubDoc; //library for navigating epubs use std::*; +use std::i32; use std::path::Path; -use std::process::exit; -use cursive::views::{Dialog, TextView}; //this function will determine if Bibliofile has been opened before. If it has not, it will create a library folder under /opt/bibliofile. @@ -35,39 +33,87 @@ fn library_exists(){ fn main() { //library_exists(); if env::args().len() == 1 { - println!("you need to enter a book. Closing program."); + println!("You need to enter a book! \n\ + context: bibliofile book.epub\n\ + Closing program."); } else { let args: Vec = env::args().collect(); let filename = &args[1]; - epub_func(filename); + screen_func(filename); } } -//parses epub files -fn epub_func(epub_file: &str){ +//this function manages the screen +fn screen_func(epub_file: &str){ + let mut page_num = 1; + let textinfo = get_text(epub_file, &page_num, "next"); + let text = textinfo.0; + let title = textinfo.1; + page_num = textinfo.2; + // Creates the cursive root - required for every application. + let mut siv = cursive::default(); + // Creates a dialog with a single "Quit" button + siv.add_layer(Dialog::around(TextView::new(text)) + .title(title) + .button("Quit", |s| s.quit())); + + // Starts the event loop. + siv.run(); + + + + +} + + + + + +fn get_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){ let doc = EpubDoc::new(&epub_file); assert!(doc.is_ok()); let mut doc = doc.unwrap(); + let mut usize_num = *page_num as usize; + if direction == "next" { + usize_num = usize_num + 1; + let title = doc.mdata("title"); - let mut page_num = 1; + doc.set_current_page(usize_num); + let content = doc.get_current_str(); + let str_content = content.unwrap(); + let text = html_module::main(str_content.0); + + return (text, title.unwrap(), usize_num as i32); + } + + else if direction == "last" { + usize_num = usize_num - 1; + let title = doc.mdata("title"); + + doc.set_current_page(usize_num); + let content = doc.get_current_str(); + let str_content = content.unwrap(); + let text = html_module::main(str_content.0); + + return (text, title.unwrap(), usize_num as i32); + } + else { + let title = doc.mdata("title"); + + doc.set_current_page(usize_num); + let content = doc.get_current_str(); + let str_content = content.unwrap(); + let text = html_module::main(str_content.0); + + return (text, title.unwrap(), usize_num as i32); + } + +} - let title = doc.mdata("title"); - doc.set_current_page(1); - page_num = 1; - let content = doc.get_current_str(); - let str_content = content.unwrap(); - let text = html_module::main(str_content.0); - let mut siv = cursive::default(); - siv.add_layer(Dialog::around(TextView::new(text)) - .title(title.unwrap()) - .button("Quit", |s| s.quit())); - siv.run(); - -} \ No newline at end of file