diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
deleted file mode 100644
index 1e6a7d5..0000000
--- a/.github/workflows/rust.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-name: Rust
-
-on:
- push:
- branches: [ "master" ]
- pull_request:
- branches: [ "master" ]
-
-env:
- CARGO_TERM_COLOR: always
-
-jobs:
- build:
-
- runs-on: ubuntu-latest
-
- steps:
- - uses: actions/checkout@v3
- - name: Build
- run: cargo build --verbose
- - name: Run tests
- run: cargo test --verbose
diff --git a/.idea/bibliofile.iml b/.idea/bibliofile.iml
deleted file mode 100644
index 633cf01..0000000
--- a/.idea/bibliofile.iml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 7b8c306..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index c8397c9..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index a9d086a..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,264 +0,0 @@
-
-
-
-
-
- {
- "useNewFormat": true
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- "associatedIndex": 5
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1684177338227
-
-
- 1684177338227
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1687972565061
-
-
-
- 1687972565061
-
-
- 1687972590786
-
-
-
- 1687972590786
-
-
- 1687974796970
-
-
-
- 1687974796970
-
-
- 1693686100048
-
-
-
- 1693686100048
-
-
- 1693686989198
-
-
-
- 1693686989198
-
-
- 1697325795094
-
-
-
- 1697325795094
-
-
- 1697339218296
-
-
-
- 1697339218296
-
-
-
- 1699028520042
-
-
-
- 1699028520042
-
-
-
- 1699028860277
-
-
-
- 1699028860277
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Dracula_bookmark b/Dracula_bookmark
index 9a03714..bf0d87a 100644
--- a/Dracula_bookmark
+++ b/Dracula_bookmark
@@ -1 +1 @@
-10
\ No newline at end of file
+4
\ No newline at end of file
diff --git a/Dracula_next b/Dracula_next
new file mode 100644
index 0000000..bf0d87a
--- /dev/null
+++ b/Dracula_next
@@ -0,0 +1 @@
+4
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index b37b27a..e173e99 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -87,7 +87,7 @@ fn screen_func(epub_file: &str){
// Creates a dialog with a single "Quit" button
siv.add_layer(Dialog::around(TextView::new(text))
.title("Bibliofile")
- .button("begin", |s| {get_text(s);}),
+ .button("begin", |s| {get_init_text(s);}),
);
// Starts the event loop.
@@ -117,14 +117,136 @@ fn get_text(s: &mut Cursive) {
//gets page number/bookmark
let title = doc.mdata("title");
let bookmark_file_name = title.clone().unwrap() + "_bookmark";
-
+ let next_page = title.clone().unwrap() + "_next";
//if bookmark for file exists, continue to open. If not, create the file and try again.
if Path::exists(bookmark_file_name.as_ref()){
- let bookmark = fs::read_to_string(bookmark_file_name.clone()).expect("no file found! You kidding me?");
+ let next_page_var = fs::read_to_string(next_page.clone()).expect("no file found!");
- let mut page_num: usize = bookmark
+ let mut page_num: usize = next_page_var
+ .trim()
+ .parse()
+ .expect("not a number");// converts from string to usize
+
+
+
+ page_num = page_num + 1;
+ doc.set_current_page(page_num);
+ let content = doc.get_current_str();
+ let str_content = content.unwrap();
+ let text = html_module::main(str_content.0);
+ let number_title = page_num;
+
+
+
+ let page_string = page_num.to_string();
+
+ //writes where the next page is so that Rust knows where to go
+ fs::write(next_page, page_string.as_bytes()).expect("Unable to write file");
+
+ //refreshed screen layout
+ s.add_layer(Dialog::around(TextView::new(text))
+ .title(title.unwrap() + " page: " + &number_title.to_string())
+ .button("last", |s| {get_last_text(s);})
+ .button("quit", |s| s.quit())
+ .button("bookmark", move |s| {bookmark_func(s, page_num, &bookmark_file_name);})
+ .button("next", |s| {get_text(s);})
+ .scrollable()
+ .scroll_x(true),
+ );
+ }
+
+ else{
+ fs::write(next_page, "1").expect("Unable to write file");
+ get_text(s);
+ }
+
+}
+
+
+fn get_last_text(s: &mut Cursive) {
+
+
+ //removes old layer, builds new one
+ s.pop_layer();
+ let args: Vec = env::args().collect();
+ let filename = &args[1];
+ let doc = EpubDoc::new(filename);
+ let mut doc = doc.unwrap();
+
+ //gets page number/bookmark
+ let title = doc.mdata("title");
+ let bookmark_file_name = title.clone().unwrap() + "_bookmark";
+ let next_page = title.clone().unwrap() + "_next";
+
+ //if bookmark for file exists, continue to open. If not, create the file and try again.
+ if Path::exists(bookmark_file_name.as_ref()){
+
+ let next_page_var = fs::read_to_string(next_page.clone()).expect("no file found!");
+
+ let mut page_num: usize = next_page_var
+ .trim()
+ .parse()
+ .expect("not a number");// converts from string to usize
+
+
+
+ page_num = page_num - 1;
+ doc.set_current_page(page_num);
+ let content = doc.get_current_str();
+ let str_content = content.unwrap();
+ let text = html_module::main(str_content.0);
+ let number_title = page_num;
+
+
+
+ let page_string = page_num.to_string();
+
+ //writes where the next page is so that Rust knows where to go
+ fs::write(next_page, page_string.as_bytes()).expect("Unable to write file");
+
+ //refreshed screen layout
+ s.add_layer(Dialog::around(TextView::new(text))
+ .title(title.unwrap() + " page: " + &number_title.to_string())
+ .button("last", |s| {get_last_text(s);})
+ .button("quit", |s| s.quit())
+ .button("bookmark", move |s| {bookmark_func(s, page_num, &bookmark_file_name);})
+ .button("next", |s| {get_text(s);})
+ .scrollable()
+ .scroll_x(true),
+ );
+ }
+
+ else{
+ fs::write(next_page, "1").expect("Unable to write file");
+ get_text(s);
+ }
+
+}
+
+
+fn get_init_text(s: &mut Cursive) {
+
+ //removes old layer, builds new one
+ s.pop_layer();
+ let args: Vec = env::args().collect();
+ let filename = &args[1];
+ let doc = EpubDoc::new(filename);
+ let mut doc = doc.unwrap();
+
+ //gets page number/bookmark
+ let title = doc.mdata("title");
+ let bookmark_file_name = title.clone().unwrap() + "_bookmark";
+ let next_page = title.clone().unwrap() + "_next";
+
+ //if bookmark for file exists, continue to open. If not, create the file and try again.
+ if Path::exists(bookmark_file_name.as_ref()){
+
+ let starting_page = fs::read_to_string(bookmark_file_name.clone()).expect("no file found!");
+
+
+ let mut page_num: usize = starting_page
.trim()
.parse()
.expect("not a number");// converts from string to usize
@@ -132,34 +254,33 @@ fn get_text(s: &mut Cursive) {
let usize_num = page_num as usize; //set_current_page must be usize, not int. This line converts.
-
-
-
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);
- page_num = page_num + 1;
- //let mut bookmark_write = File::open(bookmark_file_name).expect("could not write to file.");
+
+
let page_string = page_num.to_string();
- //bookmark_write.write_all(page_string.as_bytes()).expect("oops, couldn't write.");
- fs::write(bookmark_file_name, page_string.as_bytes()).expect("Unable to write file");
+
+ fs::write(next_page, page_string.as_bytes()).expect("Unable to write file");
//refreshed screen layout
s.add_layer(Dialog::around(TextView::new(text))
.title(title.unwrap() + " page: " + &usize_num.to_string())
.button("last", |s| {get_text(s);})
.button("quit", |s| s.quit())
+ .button("bookmark", move |s| {bookmark_func(s, page_num, &bookmark_file_name);})
.button("next", |s| {get_text(s);})
.scrollable()
.scroll_x(true),
);
}
+
else{
fs::write(bookmark_file_name, "1").expect("Unable to write file");
- get_text(s);
+ get_init_text(s);
}
}
@@ -167,6 +288,20 @@ fn get_text(s: &mut Cursive) {
+fn bookmark_func(s: &mut Cursive, page_num: usize, bookmark: &str){
+ if page_num != 1{
+ let mut new_page_num = page_num;
+ //new_page_num = new_page_num - 1;
+ let page_string = new_page_num.to_string();
+ fs::write(bookmark, page_string.as_bytes()).expect("Unable to write file");
+
+ }
+ else{
+ let page_num = "1";
+ fs::write(bookmark, page_num.as_bytes()).expect("Unable to write file");
+ }
+ }
+