diff --git a/.gitignore b/.gitignore index ce76e10..523d385 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,8 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# I used Dracula for my test book so I had to remove the files associated with testing. *.epub +Dracula_* + diff --git a/Dracula_bookmark b/Dracula_bookmark deleted file mode 100644 index bf0d87a..0000000 --- a/Dracula_bookmark +++ /dev/null @@ -1 +0,0 @@ -4 \ No newline at end of file diff --git a/Dracula_next b/Dracula_next deleted file mode 100644 index 56a6051..0000000 --- a/Dracula_next +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/src/.main.rs.kate-swp b/src/.main.rs.kate-swp new file mode 100644 index 0000000..a2adb91 Binary files /dev/null and b/src/.main.rs.kate-swp differ diff --git a/src/main.rs b/src/main.rs index 87947cb..da480af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,7 @@ use cursive::Cursive; use cursive::view::Scrollable; use epub::doc::EpubDoc; //library for navigating epubs use std::*; -use std::i32; use std::path::Path; -use std::fs::File; -use std::io::prelude::*; use std::str; /* @@ -61,10 +58,8 @@ fn main() { Closing program."); } else { - let args: Vec = env::args().collect(); - let filename = &args[1]; - screen_func(filename); + screen_func(); } } @@ -75,7 +70,7 @@ function: screen_func Params: string Return type: none */ -fn screen_func(epub_file: &str){ +fn screen_func(){ let mut siv = cursive::default(); @@ -197,12 +192,26 @@ fn get_last_text(s: &mut Cursive) { - 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; + + + if page_num == 1{ + s.add_layer(Dialog::around(TextView::new("Already on first page!")) + .button("ok", |s| {s.pop_layer();}) + ); + page_num = 0; + 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"); + get_text(s); + } + else{ + 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; @@ -220,7 +229,8 @@ fn get_last_text(s: &mut Cursive) { .button("next", |s| {get_text(s);}) .scrollable() .scroll_x(true), - ); + ); + } } else{ @@ -230,9 +240,6 @@ fn get_last_text(s: &mut Cursive) { } - - - /* Loads basic config files for ebook. Checks if there is a bookmark, and if not, displays what it sees and passes along to the appropriate function. @@ -257,7 +264,7 @@ fn get_init_text(s: &mut Cursive) { let starting_page = fs::read_to_string(bookmark_file_name.clone()).expect("no file found!"); - let mut page_num: usize = starting_page + let page_num: usize = starting_page .trim() .parse() .expect("not a number");// converts from string to usize @@ -300,17 +307,23 @@ fn get_init_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; + let 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"); } + + s.add_layer(Dialog::around(TextView::new("Bookmark placed!")) + .button("ok", |s| {s.pop_layer();}) + ) }