set termion as backend, curses as frontend.
setup for new page turning system to accomodate cursive
This commit is contained in:
parent
af933bbc0b
commit
93eadf68c8
@ -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": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.cidr.known.project.marker": "true",
|
"RunOnceActivity.cidr.known.project.marker": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
"cf.first.check.clang-format": "false",
|
"cf.first.check.clang-format": "false",
|
||||||
"cidr.known.project.marker": "true",
|
"cidr.known.project.marker": "true",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"last_opened_file_path": "/home/dan/CLionProjects/bibliofile",
|
"last_opened_file_path": "/home/dan/CLionProjects/bibliofile",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
||||||
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true",
|
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true",
|
||||||
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true",
|
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true",
|
||||||
"settings.editor.selected.configurable": "language.rust",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></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 - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead.">
|
<task id="LOCAL-00001" summary="Commit to scraper_framework branch - changing framework from Soup to Scraper - 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 - No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
|
<MESSAGE value="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
|
||||||
<MESSAGE value=" - Full Terminal Size now used - Still working on getting newlines working" />
|
<MESSAGE value=" - Full Terminal Size now used - 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 />
|
||||||
|
@ -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"]
|
||||||
|
88
src/main.rs
88
src/main.rs
@ -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;
|
||||||
let mut page_num = 1;
|
if direction == "next" {
|
||||||
|
usize_num = usize_num + 1;
|
||||||
|
|
||||||
let title = doc.mdata("title");
|
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())
|
|
||||||
.button("Quit", |s| s.quit()));
|
else if direction == "last" {
|
||||||
siv.run();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user