Added documentation and made compilable for testing reasons

This commit is contained in:
Daniel Jones 2023-11-14 16:53:08 -06:00
parent c627c95363
commit bdb41ccbd2

View File

@ -4,7 +4,7 @@ Language: Rustc 1.71.0
ide: CLion ide: CLion
Operating system: POP_OS Operating system: POP_OS
Purpose: TUI-based ereader and library manager for Linux terminal environments. Purpose: TUI-based ereader and library manager for Linux terminal environments.
Last edited: 11/3/23 Last edited: 11/14/23
*/ */
mod html_module; mod html_module;
@ -17,7 +17,13 @@ use std::i32;
use std::path::Path; 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(){ 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() { fn main() {
//library_exists(); //library_exists();
if env::args().len() == 1 { 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){ fn screen_func(epub_file: &str){
let mut page_num = 1; let mut page_num = 1;
let mut siv = cursive::default(); let mut siv = cursive::default();
let textinfo = get_init_text(epub_file, &page_num, "next"); 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. // Creates the cursive root - required for every application.
let mut siv = cursive::default(); let mut siv = cursive::default();
siv.add_global_callback('q', |s| s.quit()); 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 // Creates a dialog with a single "Quit" button
siv.add_layer(Dialog::around(TextView::new(text)) 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) { fn get_text(s: &mut Cursive) {
s.pop_layer(); s.pop_layer();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let filename = &args[1]; let filename = &args[1];
let doc = EpubDoc::new(filename); let doc = EpubDoc::new(filename);
let mut doc = doc.unwrap(); 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; usize_num = usize_num + 1;
let title = doc.mdata("title"); let title = doc.mdata("title");
@ -97,6 +117,8 @@ fn get_text(s: &mut Cursive) {
let content = doc.get_current_str(); let content = doc.get_current_str();
let str_content = content.unwrap(); let str_content = content.unwrap();
let text = html_module::main(str_content.0); let text = html_module::main(str_content.0);
//refreshed screen layout
s.add_layer(Dialog::around(TextView::new(text)) s.add_layer(Dialog::around(TextView::new(text))
.title(title.unwrap() + " page: " + &usize_num.to_string()) .title(title.unwrap() + " page: " + &usize_num.to_string())
.scrollable() .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); let doc = EpubDoc::new(&epub_file);
assert!(doc.is_ok()); assert!(doc.is_ok());
let mut doc = doc.unwrap(); let mut doc = doc.unwrap();