From c627c95363f34e5252414d4a7d60c5d4267969a4 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Fri, 3 Nov 2023 11:44:56 -0500 Subject: [PATCH] Tried a few things out, learned that page_num will outlive s. This causes the program to crash. Because of this, I will have page_num save to a file and open it when needed. That way it will not outlive S, and automatic bookmarking will already be implemented. Does not run as-is, need to clean up and refactor code to fix the bugs. --- .idea/workspace.xml | 58 ++++++++++++++++++++++++++------------------- src/main.rs | 10 +++++--- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c558439..a9d086a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,7 +15,7 @@ - + @@ -49,28 +49,29 @@ - { - "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": "//wsl$/Ubuntu-22.04/home/jonesd/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": "preferences.pluginManager", - "vue.rearranger.settings.migration": "true" + +}]]> @@ -245,7 +254,8 @@ - diff --git a/src/main.rs b/src/main.rs index a7ec119..a13f342 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,8 +78,11 @@ fn screen_func(epub_file: &str){ +//TODO: Because page_num will outlive s, Must write page_num to file and call read it to see what page is needed to be open. +//This will also work for placekeeping purposes if another book is opened and you want to return to it -fn get_text(s: &mut Cursive, mut page_num: &i32, direction: &str) { + +fn get_text(s: &mut Cursive) { s.pop_layer(); let args: Vec = env::args().collect(); let filename = &args[1]; @@ -87,14 +90,15 @@ fn get_text(s: &mut Cursive, mut page_num: &i32, direction: &str) { let mut doc = doc.unwrap(); let mut usize_num = *page_num as usize; usize_num = usize_num + 1; - let title = doc.mdata("title"); + let title = doc.mdata("title"); + s.add_global_callback('d', move |s| { get_text(s); }); 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); s.add_layer(Dialog::around(TextView::new(text)) - .title(title + " page: " + &page_num.to_string()) + .title(title.unwrap() + " page: " + &usize_num.to_string()) .scrollable() .scroll_x(true), );