diff --git a/src/main.rs b/src/main.rs index a13f342..f76a3dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ Language: Rustc 1.71.0 ide: CLion Operating system: POP_OS Purpose: TUI-based ereader and library manager for Linux terminal environments. -Last edited: 11/3/23 +Last edited: 11/14/23 */ mod html_module; @@ -17,7 +17,13 @@ use std::i32; use std::path::Path; -//this function will determine if Bibliofile has been opened before. If it has not, it will create a library folder under /opt/bibliofile. +/* +This function will determine if Bibliofile has been opened before. If it has not, it will create a library folder under /opt/bibliofile. + +Function: library_Exists +param: none +Return Type: void + */ fn library_exists(){ @@ -31,8 +37,13 @@ fn library_exists(){ } -//initial function. Reads the ebook passed by argument. -//TODO: add visual library to pull up ebooks. +/* +initial function. Reads the ebook passed by argument, and checks if library directory exists in Linux. +name: main +params: none +Return type: void + */ + fn main() { //library_exists(); if env::args().len() == 1 { @@ -49,9 +60,14 @@ fn main() { } -//this function manages the screen +/* +Initial screen setup. Sets up the initial TUI screen that will be used by the rest of the application +function: screen_func +Params: string +Return type: none + */ fn screen_func(epub_file: &str){ - + let mut page_num = 1; let mut siv = cursive::default(); let textinfo = get_init_text(epub_file, &page_num, "next"); @@ -63,7 +79,7 @@ fn screen_func(epub_file: &str){ // Creates the cursive root - required for every application. let mut siv = cursive::default(); siv.add_global_callback('q', |s| s.quit()); - siv.add_global_callback('d', move |s| { get_text(s, &page_num, "next"); }); + siv.add_global_callback('d', move |s| { get_text(s); }); // Creates a dialog with a single "Quit" button siv.add_layer(Dialog::around(TextView::new(text)) @@ -78,17 +94,21 @@ fn screen_func(epub_file: &str){ -//TODO: Because page_num will outlive s, Must write page_num to file and call read it to see what page is needed to be open. -//This will also work for placekeeping purposes if another book is opened and you want to return to it - - +/* +This function is called whenever the screen gets refreshed. This is seperate from get_init_text because +it requires the TUI to already be active to be called. +function: get_text +params: Cursive session +Returns type: void + */ fn get_text(s: &mut Cursive) { s.pop_layer(); let args: Vec = env::args().collect(); let filename = &args[1]; let doc = EpubDoc::new(filename); let mut doc = doc.unwrap(); - let mut usize_num = *page_num as usize; + let page_num = 1; + let mut usize_num = page_num as usize; usize_num = usize_num + 1; let title = doc.mdata("title"); @@ -97,6 +117,8 @@ fn get_text(s: &mut Cursive) { let content = doc.get_current_str(); let str_content = content.unwrap(); let text = html_module::main(str_content.0); + + //refreshed screen layout s.add_layer(Dialog::around(TextView::new(text)) .title(title.unwrap() + " page: " + &usize_num.to_string()) .scrollable() @@ -105,7 +127,12 @@ fn get_text(s: &mut Cursive) { } - fn get_init_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){ + + +/* +Function called + */ +fn get_init_text(epub_file: &str, mut page_num: &i32, direction: &str) -> (String, String, i32){ let doc = EpubDoc::new(&epub_file); assert!(doc.is_ok()); let mut doc = doc.unwrap();