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
|
||||
**/*.rs.bk
|
||||
|
||||
# I used Dracula for my test book so I had to remove the files associated with testing.
|
||||
*.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.
51
src/main.rs
51
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<String> = 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();})
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user