2023-07-20 15:28:40 +00:00
/*
Program : Bibliofile
2023-07-24 23:40:33 +00:00
Language : Rustc 1.7 1.0
2023-07-20 15:28:40 +00:00
ide : CLion
Operating system : Fedora 38 / WSL
Purpose : TUI - based ereader and library manager for Linux terminal environments .
2023-07-27 23:23:41 +00:00
Last edited : 7 / 27 / 23
2023-07-20 15:28:40 +00:00
* /
2023-07-27 23:23:41 +00:00
mod html_module ;
2023-07-20 15:28:40 +00:00
use epub ::doc ::EpubDoc ; //library for navigating epubs
2023-07-27 23:23:41 +00:00
use std ::* ;
use std ::path ::Path ;
2023-07-20 15:28:40 +00:00
use std ::process ::exit ;
2023-10-14 23:23:13 +00:00
use cursive ::views ::{ Dialog , TextView } ;
2023-07-20 15:28:40 +00:00
2023-07-27 23:23:41 +00:00
//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 ( ) ) ;
2023-07-27 23:56:14 +00:00
2023-07-27 23:23:41 +00:00
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. " ) ;
}
}
2023-07-20 15:28:40 +00:00
//initial function. Reads the ebook passed by argument.
//TODO: add visual library to pull up ebooks.
fn main ( ) {
2023-09-02 20:21:36 +00:00
//library_exists();
2023-07-20 15:28:40 +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 ] ;
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 ( ) ;
2023-07-27 23:56:14 +00:00
let mut page_num = 1 ;
2023-07-27 23:23:41 +00:00
2023-10-14 23:23:13 +00:00
let title = doc . mdata ( " title " ) ;
2023-07-24 23:36:08 +00:00
2023-09-02 20:36:26 +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 ( ) ;
2023-07-27 23:56:14 +00:00
2023-09-02 20:21:36 +00:00
}