Figured out how to call a function upon pressing a button without throwing an error.

Solution: Open the file every time the button is pressed and go to specified page. File outlasts s function, so error called every time function is called.
This commit is contained in:
Daniel Jones 2023-11-03 11:21:56 -05:00
parent e5b8490128
commit 87cdb7239e
2 changed files with 29 additions and 59 deletions

View File

@ -49,28 +49,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": "//wsl$/Ubuntu-22.04/home/jonesd/bibliofile", &quot;last_opened_file_path&quot;: &quot;//wsl$/Ubuntu-22.04/home/jonesd/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": "preferences.pluginManager", &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.Check"> <component name="RunManager" selected="Cargo.Check">
<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" />

View File

@ -4,7 +4,7 @@ Language: Rustc 1.71.0
ide: CLion ide: CLion
Operating system: POP_OS 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: 10/14/23 Last edited: 11/3/23
*/ */
mod html_module; mod html_module;
@ -17,9 +17,6 @@ use std::i32;
use std::path::Path; use std::path::Path;
//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.
fn library_exists(){ fn library_exists(){
@ -66,10 +63,11 @@ fn screen_func(epub_file: &str){
// Creates the cursive root - required for every application. // Creates the cursive root - required for every application.
let mut siv = cursive::default(); let mut siv = cursive::default();
siv.add_global_callback('q', |s| s.quit()); siv.add_global_callback('q', |s| s.quit());
siv.add_global_callback('d', move |s| { get_text(s, &page_num, "next"); });
// Creates a dialog with a single "Quit" button // Creates a dialog with a single "Quit" button
siv.add_layer(Dialog::around(TextView::new(text)) siv.add_layer(Dialog::around(TextView::new(text))
.title(title) .title(title + " page: " + &page_num.to_string())
.scrollable() .scrollable()
.scroll_x(true), .scroll_x(true),
); );
@ -81,42 +79,14 @@ fn screen_func(epub_file: &str){
fn get_text(s: &mut Cursive, epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32) { fn get_text(s: &mut Cursive, mut page_num: &i32, direction: &str) {
s.pop_layer();
let args: Vec<String> = env::args().collect();
let filename = &args[1];
let doc = EpubDoc::new(&epub_file); let doc = EpubDoc::new(&epub_file);
assert!(doc.is_ok());
let mut doc = doc.unwrap();
let mut usize_num = *page_num as usize;
return if direction == "next" { s.add_layer(Dialog::text("D has been pressed! Congratulations! You figured this shit out!"));
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);
(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);
(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);
(text, title.unwrap(), usize_num as i32)
}
} }
fn get_init_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){ fn get_init_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){