firgured out scrolling

This commit is contained in:
Daniel Jones 2023-10-24 14:57:04 -05:00
parent 7bb7b3deb1
commit 4da4809969
5 changed files with 102 additions and 41 deletions

8
.idea/bibliofile.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/bibliofile.iml" filepath="$PROJECT_DIR$/.idea/bibliofile.iml" />
</modules>
</component>
</project>

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">{ <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;/home/dan/CLionProjects/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.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true",
&quot;org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs&quot;: &quot;true&quot;, "org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.pluginManager",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "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" />
@ -139,6 +139,7 @@
<workItem from="1697344288791" duration="562000" /> <workItem from="1697344288791" duration="562000" />
<workItem from="1697344966098" duration="165000" /> <workItem from="1697344966098" duration="165000" />
<workItem from="1697345194146" duration="1214000" /> <workItem from="1697345194146" duration="1214000" />
<workItem from="1698172797400" duration="4440000" />
</task> </task>
<task id="LOCAL-00001" summary="Commit to scraper_framework branch&#10;&#10; - changing framework from Soup to Scraper&#10; - removed ncurses library. Will use different library instead."> <task id="LOCAL-00001" summary="Commit to scraper_framework branch&#10;&#10; - changing framework from Soup to Scraper&#10; - removed ncurses library. Will use different library instead.">
<created>1687972565061</created> <created>1687972565061</created>
@ -196,6 +197,11 @@
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
<option name="OPEN_GENERIC_TABS">
<map>
<entry key="bf7340ba-b072-4b3b-9ffa-ee490e55e871" value="TOOL_WINDOW" />
</map>
</option>
<option name="TAB_STATES"> <option name="TAB_STATES">
<map> <map>
<entry key="MAIN"> <entry key="MAIN">
@ -215,6 +221,11 @@
</State> </State>
</value> </value>
</entry> </entry>
<entry key="bf7340ba-b072-4b3b-9ffa-ee490e55e871">
<value>
<State />
</value>
</entry>
</map> </map>
</option> </option>
</component> </component>

View File

@ -0,0 +1,3 @@
[ZoneTransfer]
ZoneId=3
HostUrl=about:internet

View File

@ -9,16 +9,14 @@ Last edited: 10/14/23
mod html_module; mod html_module;
use cursive::views::{Dialog, TextView}; use cursive::views::{Dialog, TextView};
use cursive::backends::termion::termion; use cursive::Cursive;
use cursive::event; use cursive::view::Scrollable;
use epub::doc::EpubDoc; //library for navigating epubs use epub::doc::EpubDoc; //library for navigating epubs
use std::*; use std::*;
use std::i32; use std::i32;
use std::io::stdin;
use std::path::Path; use std::path::Path;
use termion::event::{Event, Key};
use termion::input::TermRead;
use termion::scroll;
@ -56,38 +54,34 @@ fn main() {
//this function manages the screen //this function manages the screen
fn screen_func(epub_file: &str){ fn screen_func(epub_file: &str){
let mut page_num = 1; let mut page_num = 1;
let textinfo = get_text(epub_file, &page_num, "next"); let mut siv = cursive::default();
let textinfo = get_init_text(epub_file, &page_num, "next");
let text = textinfo.0; let text = textinfo.0;
let title = textinfo.1; let title = textinfo.1;
page_num = textinfo.2; page_num = textinfo.2;
// 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());
// 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)
.button("Quit", |s| s.quit())); .scrollable()
.scroll_x(true),
);
// Starts the event loop. // Starts the event loop.
siv.run(); siv.run();
let c = stdin();
for c in stdin().events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Up) => scroll::Up(1),
_ => {}
}
}
} }
fn get_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){ fn get_text(s: &mut Cursive, epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32) {
let doc = EpubDoc::new(&epub_file); let doc = EpubDoc::new(&epub_file);
assert!(doc.is_ok()); assert!(doc.is_ok());
let mut doc = doc.unwrap(); let mut doc = doc.unwrap();
@ -123,7 +117,44 @@ fn get_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, St
(text, title.unwrap(), usize_num as i32) (text, title.unwrap(), usize_num as i32)
} }
}
fn get_init_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){
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" {
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)
}
} }