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.
This commit is contained in:
Daniel Jones 2023-11-03 11:44:56 -05:00
parent 2670e6ffd4
commit c627c95363
2 changed files with 41 additions and 27 deletions

View File

@ -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="Figured out how to call a function upon pressing a button without throwing an error.&#10;&#10;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."> <list default="true" id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="page turning figured out. Must make get_text recursive so that you can call it again once you are done reading.">
<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$/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" />
</list> </list>
@ -49,28 +49,29 @@
<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">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;, "RunOnceActivity.cidr.known.project.marker": "true",
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, "WebServerToolWindowFactoryState": "false",
&quot;cf.first.check.clang-format&quot;: &quot;false&quot;, "cf.first.check.clang-format": "false",
&quot;cidr.known.project.marker&quot;: &quot;true&quot;, "cidr.known.project.marker": "true",
&quot;git-widget-placeholder&quot;: &quot;master&quot;, "git-widget-placeholder": "master",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;last_opened_file_path&quot;: &quot;//wsl$/Ubuntu-22.04/home/jonesd/bibliofile&quot;, "last_opened_file_path": "//wsl$/Ubuntu-22.04/home/jonesd/bibliofile",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;org.rust.cargo.project.model.PROJECT_DISCOVERY&quot;: &quot;true&quot;, "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs&quot;: &quot;true&quot;, "org.rust.disableDetachedFileInspection/home/dan/CLionProjects/bibliofile/src/main.rs": "true",
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs&quot;: &quot;true&quot;, "org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "settings.editor.selected.configurable": "preferences.pluginManager",
"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" />
@ -198,7 +199,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1699028520042</updated> <updated>1699028520042</updated>
</task> </task>
<option name="localTasksCounter" value="9" /> <task id="LOCAL-00009" summary="page turning figured out. Must make get_text recursive so that you can call it again once you are done reading.">
<option name="closed" value="true" />
<created>1699028860277</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1699028860277</updated>
</task>
<option name="localTasksCounter" value="10" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -245,7 +254,8 @@
<MESSAGE value="Created initial display" /> <MESSAGE value="Created initial display" />
<MESSAGE value="set termion as backend, curses as frontend.&#10;setup for new page turning system to accomodate cursive" /> <MESSAGE value="set termion as backend, curses as frontend.&#10;setup for new page turning system to accomodate cursive" />
<MESSAGE value="Figured out how to call a function upon pressing a button without throwing an error.&#10;&#10;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." /> <MESSAGE value="Figured out how to call a function upon pressing a button without throwing an error.&#10;&#10;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." />
<option name="LAST_COMMIT_MESSAGE" value="Figured out how to call a function upon pressing a button without throwing an error.&#10;&#10;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." /> <MESSAGE value="page turning figured out. Must make get_text recursive so that you can call it again once you are done reading." />
<option name="LAST_COMMIT_MESSAGE" value="page turning figured out. Must make get_text recursive so that you can call it again once you are done reading." />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@ -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(); s.pop_layer();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let filename = &args[1]; 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 doc = doc.unwrap();
let mut usize_num = *page_num as usize; let mut usize_num = *page_num as usize;
usize_num = usize_num + 1; 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); doc.set_current_page(usize_num);
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);
s.add_layer(Dialog::around(TextView::new(text)) s.add_layer(Dialog::around(TextView::new(text))
.title(title + " page: " + &page_num.to_string()) .title(title.unwrap() + " page: " + &usize_num.to_string())
.scrollable() .scrollable()
.scroll_x(true), .scroll_x(true),
); );