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="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;/home/dan/CLionProjects/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.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" />
@ -139,6 +139,7 @@
<workItem from="1697344288791" duration="562000" />
<workItem from="1697344966098" duration="165000" />
<workItem from="1697345194146" duration="1214000" />
<workItem from="1698172797400" duration="4440000" />
</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.">
<created>1687972565061</created>
@ -196,6 +197,11 @@
<option name="version" value="3" />
</component>
<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">
<map>
<entry key="MAIN">
@ -215,6 +221,11 @@
</State>
</value>
</entry>
<entry key="bf7340ba-b072-4b3b-9ffa-ee490e55e871">
<value>
<State />
</value>
</entry>
</map>
</option>
</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;
use cursive::views::{Dialog, TextView};
use cursive::backends::termion::termion;
use cursive::event;
use cursive::Cursive;
use cursive::view::Scrollable;
use epub::doc::EpubDoc; //library for navigating epubs
use std::*;
use std::i32;
use std::io::stdin;
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
fn screen_func(epub_file: &str){
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 title = textinfo.1;
page_num = textinfo.2;
// Creates the cursive root - required for every application.
let mut siv = cursive::default();
siv.add_global_callback('q', |s| s.quit());
// Creates a dialog with a single "Quit" button
siv.add_layer(Dialog::around(TextView::new(text))
.title(title)
.button("Quit", |s| s.quit()));
.scrollable()
.scroll_x(true),
);
// Starts the event loop.
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);
assert!(doc.is_ok());
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)
}
}
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)
}
}