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" />
</component>
<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$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
</list>
@ -49,28 +49,29 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
&quot;cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;//wsl$/Ubuntu-22.04/home/jonesd/bibliofile&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;org.rust.cargo.project.model.PROJECT_DISCOVERY&quot;: &quot;true&quot;,
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs&quot;: &quot;true&quot;,
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs&quot;: &quot;true&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"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.disableDetachedFileInspection/home/dan/CLionProjects/bibliofile/src/main.rs": "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"
}
}</component>
}]]></component>
<component name="RunManager" selected="Cargo.Check">
<configuration name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
<option name="command" value="check" />
@ -198,7 +199,15 @@
<option name="project" value="LOCAL" />
<updated>1699028520042</updated>
</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 />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -245,7 +254,8 @@
<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="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 name="XSLT-Support.FileAssociations.UIState">
<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();
let args: Vec<String> = 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),
);