bibliofile/src/main.rs

73 lines
1.9 KiB
Rust
Raw Normal View History

/*
Program: Bibliofile
2023-07-24 23:40:33 +00:00
Language: Rustc 1.71.0
ide: CLion
Operating system: Fedora 38/WSL
Purpose: TUI-based ereader and library manager for Linux terminal environments.
Last edited: 7/27/23
*/
mod html_module;
use epub::doc::EpubDoc; //library for navigating epubs
use std::*;
use std::path::Path;
use std::process::exit;
2023-10-14 23:23:13 +00:00
use cursive::views::{Dialog, TextView};
//this function will determine if Bibliofile has been opened before. If it has not, it will create a library folder under /opt/bibliofile.
fn library_exists(){
//if /var/lib/bibliofile/library does not exist, create it.
let mut library_exist_var = Path::exists("/var/lib/bibliofile/library".as_ref());
if library_exist_var == false{
fs::create_dir_all("/var/lib/bibliofile/library").expect("Error...could not create library. If this is your first time running Bibliofile, try running with sudo.");
}
}
//initial function. Reads the ebook passed by argument.
//TODO: add visual library to pull up ebooks.
fn main() {
//library_exists();
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];
epub_func(filename);
}
}
//parses epub files
fn epub_func(epub_file: &str){
let doc = EpubDoc::new(&epub_file);
assert!(doc.is_ok());
let mut doc = doc.unwrap();
let mut page_num = 1;
2023-10-14 23:23:13 +00:00
let title = doc.mdata("title");
2023-07-24 23:36:08 +00:00
doc.set_current_page(1);
page_num = 1;
let content = doc.get_current_str();
let str_content = content.unwrap();
let text = html_module::main(str_content.0);
2023-10-14 23:23:13 +00:00
let mut siv = cursive::default();
siv.add_layer(Dialog::around(TextView::new(text))
.title(title.unwrap())
.button("Quit", |s| s.quit()));
siv.run();
}