added some notifications to alert user to errors.
This commit is contained in:
parent
6275b255d5
commit
c0c02ba073
4
.gitignore
vendored
4
.gitignore
vendored
@ -8,4 +8,8 @@ Cargo.lock
|
|||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# I used Dracula for my test book so I had to remove the files associated with testing.
|
||||||
*.epub
|
*.epub
|
||||||
|
Dracula_*
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
4
|
|
@ -1 +0,0 @@
|
|||||||
1
|
|
BIN
src/.main.rs.kate-swp
Normal file
BIN
src/.main.rs.kate-swp
Normal file
Binary file not shown.
37
src/main.rs
37
src/main.rs
@ -13,10 +13,7 @@ use cursive::Cursive;
|
|||||||
use cursive::view::Scrollable;
|
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::path::Path;
|
use std::path::Path;
|
||||||
use std::fs::File;
|
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -61,10 +58,8 @@ fn main() {
|
|||||||
Closing program.");
|
Closing program.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let args: Vec<String> = env::args().collect();
|
|
||||||
let filename = &args[1];
|
|
||||||
|
|
||||||
screen_func(filename);
|
screen_func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +70,7 @@ function: screen_func
|
|||||||
Params: string
|
Params: string
|
||||||
Return type: none
|
Return type: none
|
||||||
*/
|
*/
|
||||||
fn screen_func(epub_file: &str){
|
fn screen_func(){
|
||||||
|
|
||||||
|
|
||||||
let mut siv = cursive::default();
|
let mut siv = cursive::default();
|
||||||
@ -197,6 +192,20 @@ fn get_last_text(s: &mut Cursive) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
page_num = page_num - 1;
|
||||||
doc.set_current_page(page_num);
|
doc.set_current_page(page_num);
|
||||||
let content = doc.get_current_str();
|
let content = doc.get_current_str();
|
||||||
@ -222,6 +231,7 @@ fn get_last_text(s: &mut Cursive) {
|
|||||||
.scroll_x(true),
|
.scroll_x(true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
fs::write(next_page, "1").expect("Unable to write file");
|
fs::write(next_page, "1").expect("Unable to write file");
|
||||||
@ -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
|
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.
|
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 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()
|
.trim()
|
||||||
.parse()
|
.parse()
|
||||||
.expect("not a number");// converts from string to usize
|
.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){
|
fn bookmark_func(s: &mut Cursive, page_num: usize, bookmark: &str){
|
||||||
|
|
||||||
if page_num != 1{
|
if page_num != 1{
|
||||||
let mut new_page_num = page_num;
|
let new_page_num = page_num;
|
||||||
//new_page_num = new_page_num - 1;
|
//new_page_num = new_page_num - 1;
|
||||||
let page_string = new_page_num.to_string();
|
let page_string = new_page_num.to_string();
|
||||||
fs::write(bookmark, page_string.as_bytes()).expect("Unable to write file");
|
fs::write(bookmark, page_string.as_bytes()).expect("Unable to write file");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
let page_num = "1";
|
let page_num = "1";
|
||||||
fs::write(bookmark, page_num.as_bytes()).expect("Unable to write file");
|
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();})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user