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" />
</component>
<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$/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" />
@ -47,28 +47,28 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"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": "language.rust",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
&quot;cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/dan/CLionProjects/bibliofile&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;org.rust.cargo.project.model.PROJECT_DISCOVERY&quot;: &quot;true&quot;,
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs&quot;: &quot;true&quot;,
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs&quot;: &quot;true&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager" selected="Cargo.Run">
<configuration name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
<option name="command" value="check" />
@ -88,7 +88,7 @@
</method>
</configuration>
<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="emulateTerminal" value="false" />
<option name="channel" value="DEFAULT" />
@ -104,6 +104,10 @@
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Cargo.Check" />
<item itemvalue="Cargo.Run" />
</list>
</component>
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
@ -127,7 +131,12 @@
<workItem from="1693679597473" duration="599000" />
<workItem from="1693680405017" duration="7265000" />
<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 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>
@ -164,7 +173,14 @@
<option name="project" value="LOCAL" />
<updated>1693686989198</updated>
</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 />
</component>
<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=" - Full Terminal Size now used&#10; - Still working on getting newlines working" />
<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 name="XSLT-Support.FileAssociations.UIState">
<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
[dependencies]
cursive = "0.20.0"
epub = "2.0.0"
scraper = "*"
[dependencies.cursive]
version = "*"
default-features = false
features = ["termion-backend"]

View File

@ -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<String> = 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);
}
let title = doc.mdata("title");
else if direction == "last" {
usize_num = usize_num - 1;
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);
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);
let mut siv = cursive::default();
siv.add_layer(Dialog::around(TextView::new(text))
.title(title.unwrap())
.button("Quit", |s| s.quit()));
siv.run();
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);
}
}