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:
parent
e5b8490128
commit
87cdb7239e
@ -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": {
|
"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": "//wsl$/Ubuntu-22.04/home/jonesd/bibliofile",
|
"last_opened_file_path": "//wsl$/Ubuntu-22.04/home/jonesd/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": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></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" />
|
||||||
|
46
src/main.rs
46
src/main.rs
@ -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){
|
||||||
|
Loading…
Reference in New Issue
Block a user