2023-03-17 03:22:09 +00:00
|
|
|
/*
|
|
|
|
Program: Bibliofile
|
2023-06-28 19:10:07 +00:00
|
|
|
Language: Rustc 1.70.0
|
2023-05-15 18:33:14 +00:00
|
|
|
ide: CLion
|
2023-05-01 20:31:08 +00:00
|
|
|
Operating system: Fedora 38/WSL
|
2023-03-17 03:22:09 +00:00
|
|
|
Purpose: ncurses based ereader and library manager for Linux terminal environments.
|
2023-06-28 19:10:07 +00:00
|
|
|
Last edited: 6/28/23
|
2023-03-17 03:22:09 +00:00
|
|
|
*/
|
|
|
|
|
2023-05-15 18:33:14 +00:00
|
|
|
|
|
|
|
mod html_module;
|
2023-06-28 17:16:04 +00:00
|
|
|
|
2023-05-21 01:03:54 +00:00
|
|
|
|
2023-05-15 18:33:14 +00:00
|
|
|
use epub::doc::EpubDoc; //library for navigating epubs
|
2023-03-17 02:10:15 +00:00
|
|
|
use std::env;
|
2023-05-20 23:44:13 +00:00
|
|
|
use std::process::exit;
|
2023-03-17 03:22:09 +00:00
|
|
|
|
2023-05-15 18:33:14 +00:00
|
|
|
|
2023-03-17 03:22:09 +00:00
|
|
|
//initial function. Reads the ebook passed by argument.
|
|
|
|
//TODO: add visual library to pull up ebooks.
|
2023-03-18 01:05:02 +00:00
|
|
|
fn main() {
|
2023-05-20 23:44:13 +00:00
|
|
|
if env::args().len() == 1 {
|
|
|
|
println!("you need to enter a book. Closing program.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
let filename = &args[1];
|
2023-06-28 17:16:04 +00:00
|
|
|
|
2023-05-20 23:44:13 +00:00
|
|
|
epub_func(filename);
|
|
|
|
}
|
2023-03-18 01:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//parses epub files
|
2023-05-19 03:01:14 +00:00
|
|
|
fn epub_func(epub_file: &str){
|
2023-05-20 23:44:13 +00:00
|
|
|
|
2023-05-01 16:24:26 +00:00
|
|
|
let doc = EpubDoc::new(&epub_file);
|
|
|
|
assert!(doc.is_ok());
|
2023-05-02 00:26:22 +00:00
|
|
|
let mut doc = doc.unwrap();
|
2023-05-19 03:01:14 +00:00
|
|
|
|
2023-05-20 23:44:13 +00:00
|
|
|
let mut page_num = 1;
|
|
|
|
let is_reading = true;
|
|
|
|
while is_reading == true {
|
|
|
|
let mut next_or_last = String::new();
|
2023-06-28 18:15:01 +00:00
|
|
|
doc.set_current_page(page_num);
|
2023-05-19 03:01:14 +00:00
|
|
|
|
2023-05-20 23:44:13 +00:00
|
|
|
let content = doc.get_current_str();
|
|
|
|
let str_content = content.unwrap();
|
2023-06-28 18:15:01 +00:00
|
|
|
html_module::main(str_content.0);
|
2023-06-28 17:53:13 +00:00
|
|
|
|
2023-05-19 03:01:14 +00:00
|
|
|
|
2023-05-20 23:44:13 +00:00
|
|
|
let input_size = std::io::stdin().read_line(&mut next_or_last);
|
|
|
|
let input_size_len = input_size.unwrap() - 1;
|
|
|
|
if input_size_len == 1{
|
2023-05-21 01:03:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Was not sure how to compare string to input from .read_line
|
|
|
|
Instead, I felt that it would be easier to convert it to bytes and
|
|
|
|
compare the ASCII values.
|
|
|
|
*/
|
2023-05-20 23:44:13 +00:00
|
|
|
let compare = next_or_last.as_bytes();
|
2023-05-21 01:03:54 +00:00
|
|
|
|
|
|
|
//If user presses n(for next) goes forward one page.
|
2023-05-20 23:44:13 +00:00
|
|
|
if compare[0] == 110 {
|
|
|
|
page_num = page_num + 1;
|
|
|
|
}
|
2023-05-21 01:03:54 +00:00
|
|
|
//if user presses b, goes back one page.
|
2023-05-20 23:44:13 +00:00
|
|
|
else if compare[0] == 98 {
|
|
|
|
//if page number equals one then you are at the beginning of the book.
|
|
|
|
if page_num == 1 {
|
|
|
|
println!("at beginning of book.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
page_num = page_num - 1;
|
|
|
|
}
|
|
|
|
}
|
2023-05-21 01:03:54 +00:00
|
|
|
//If user presses q(for quit), exits with status code of 0.
|
2023-05-20 23:44:13 +00:00
|
|
|
else if compare[0] == 113 {
|
|
|
|
println!("quitting...");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("did not understand command.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("Do not understand input. Try again.");
|
|
|
|
}
|
|
|
|
}
|
2023-03-18 01:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|