set termion as backend, curses as frontend.

setup for new page turning system to accomodate cursive
This commit is contained in:
Daniel Jones 2023-10-14 22:06:56 -05:00
parent af933bbc0b
commit 93eadf68c8
3 changed files with 118 additions and 51 deletions

View File

@ -15,7 +15,7 @@
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" /> <cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="Fixed stack underflow bug. Must find more elegant solution later."> <list default="true" id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="Created initial display">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
@ -47,28 +47,28 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.cidr.known.project.marker": "true", &quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
"WebServerToolWindowFactoryState": "false", &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
"cf.first.check.clang-format": "false", &quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
"cidr.known.project.marker": "true", &quot;cidr.known.project.marker&quot;: &quot;true&quot;,
"git-widget-placeholder": "master", &quot;git-widget-placeholder&quot;: &quot;master&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"last_opened_file_path": "/home/dan/CLionProjects/bibliofile", &quot;last_opened_file_path&quot;: &quot;/home/dan/CLionProjects/bibliofile&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true", &quot;org.rust.cargo.project.model.PROJECT_DISCOVERY&quot;: &quot;true&quot;,
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true", &quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs&quot;: &quot;true&quot;,
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true", &quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs&quot;: &quot;true&quot;,
"settings.editor.selected.configurable": "language.rust", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="Cargo.Run"> <component name="RunManager" selected="Cargo.Run">
<configuration name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true"> <configuration name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
<option name="command" value="check" /> <option name="command" value="check" />
@ -88,7 +88,7 @@
</method> </method>
</configuration> </configuration>
<configuration name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true"> <configuration name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
<option name="command" value="run pg2680.epub" /> <option name="command" value="run pg345-images.epub" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="false" /> <option name="emulateTerminal" value="false" />
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
@ -104,6 +104,10 @@
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" /> <option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method> </method>
</configuration> </configuration>
<list>
<item itemvalue="Cargo.Check" />
<item itemvalue="Cargo.Run" />
</list>
</component> </component>
<component name="RustProjectSettings"> <component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" /> <option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
@ -127,7 +131,12 @@
<workItem from="1693679597473" duration="599000" /> <workItem from="1693679597473" duration="599000" />
<workItem from="1693680405017" duration="7265000" /> <workItem from="1693680405017" duration="7265000" />
<workItem from="1693876306734" duration="49000" /> <workItem from="1693876306734" duration="49000" />
<workItem from="1697324576800" duration="1175000" /> <workItem from="1697324576800" duration="3431000" />
<workItem from="1697328049119" duration="41000" />
<workItem from="1697328171250" duration="85000" />
<workItem from="1697328270424" duration="59000" />
<workItem from="1697328349082" duration="212000" />
<workItem from="1697328580563" duration="9760000" />
</task> </task>
<task id="LOCAL-00001" summary="Commit to scraper_framework branch&#10;&#10; - changing framework from Soup to Scraper&#10; - removed ncurses library. Will use different library instead."> <task id="LOCAL-00001" summary="Commit to scraper_framework branch&#10;&#10; - changing framework from Soup to Scraper&#10; - removed ncurses library. Will use different library instead.">
<created>1687972565061</created> <created>1687972565061</created>
@ -164,7 +173,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1693686989198</updated> <updated>1693686989198</updated>
</task> </task>
<option name="localTasksCounter" value="6" /> <task id="LOCAL-00006" summary="Created initial display">
<created>1697325795094</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1697325795094</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -198,7 +214,8 @@
<MESSAGE value="- Can now format HTML&#10;- No longer returns to main.rs. Main function in html_module.rs now reads to console locally." /> <MESSAGE value="- Can now format HTML&#10;- No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
<MESSAGE value=" - Full Terminal Size now used&#10; - Still working on getting newlines working" /> <MESSAGE value=" - Full Terminal Size now used&#10; - Still working on getting newlines working" />
<MESSAGE value="Fixed stack underflow bug. Must find more elegant solution later." /> <MESSAGE value="Fixed stack underflow bug. Must find more elegant solution later." />
<option name="LAST_COMMIT_MESSAGE" value="Fixed stack underflow bug. Must find more elegant solution later." /> <MESSAGE value="Created initial display" />
<option name="LAST_COMMIT_MESSAGE" value="Created initial display" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@ -6,7 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
cursive = "0.20.0"
epub = "2.0.0" epub = "2.0.0"
scraper = "*" scraper = "*"
[dependencies.cursive]
version = "*"
default-features = false
features = ["termion-backend"]

View File

@ -2,19 +2,17 @@
Program: Bibliofile Program: Bibliofile
Language: Rustc 1.71.0 Language: Rustc 1.71.0
ide: CLion ide: CLion
Operating system: Fedora 38/WSL Operating system: POP_OS
Purpose: TUI-based ereader and library manager for Linux terminal environments. Purpose: TUI-based ereader and library manager for Linux terminal environments.
Last edited: 7/27/23 Last edited: 10/14/23
*/ */
mod html_module; mod html_module;
use cursive::views::{Dialog, TextView};
use epub::doc::EpubDoc; //library for navigating epubs use epub::doc::EpubDoc; //library for navigating epubs
use std::*; use std::*;
use std::i32;
use std::path::Path; 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. //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() { fn main() {
//library_exists(); //library_exists();
if env::args().len() == 1 { 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 { else {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let filename = &args[1]; let filename = &args[1];
epub_func(filename); screen_func(filename);
} }
} }
//parses epub files //this function manages the screen
fn epub_func(epub_file: &str){ 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); let doc = EpubDoc::new(&epub_file);
assert!(doc.is_ok()); assert!(doc.is_ok());
let mut doc = doc.unwrap(); 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);
}
let title = doc.mdata("title"); else if direction == "last" {
usize_num = usize_num - 1;
let title = doc.mdata("title");
doc.set_current_page(1); doc.set_current_page(usize_num);
page_num = 1; let content = doc.get_current_str();
let content = doc.get_current_str(); let str_content = content.unwrap();
let str_content = content.unwrap(); let text = html_module::main(str_content.0);
let text = html_module::main(str_content.0);
let mut siv = cursive::default(); return (text, title.unwrap(), usize_num as i32);
siv.add_layer(Dialog::around(TextView::new(text)) }
.title(title.unwrap()) else {
.button("Quit", |s| s.quit())); let title = doc.mdata("title");
siv.run();
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);
}
} }