epub function

Decided that I am focusing too widely on too many things. Working on bare functionality before menus or extra features. Erased old code and will work exclusively on epub reading until basic functionality is added.
This commit is contained in:
Daniel Jones 2023-05-01 11:24:26 -05:00
parent 395b1d1ce0
commit eb76e8a8ca
3 changed files with 15 additions and 97 deletions

View File

@ -7,4 +7,5 @@ edition = "2021"
[dependencies] [dependencies]
ncurses = "5.101.0" ncurses = "5.101.0"
termsize = "0.1" termsize = "0.1"
epub = "1.2.2"

BIN
pg8800.epub Normal file

Binary file not shown.

View File

@ -2,119 +2,36 @@
Program: Bibliofile Program: Bibliofile
Language: Rustc 1.68.0 Language: Rustc 1.68.0
ide: Visual Studio Code ide: Visual Studio Code
Operating system: Linux Mint 21.1 Operating system:
Purpose: ncurses based ereader and library manager for Linux terminal environments. Purpose: ncurses based ereader and library manager for Linux terminal environments.
Last edited: 10:18 PM 3/16/23 Last edited: 9:55 PM 5/1/23
*/ */
use std::fs::File; use epub::doc::EpubDoc;
use std::fs; use std::fs;
use std::io::prelude::*; use std::io::prelude::*;
use std::env; use std::env;
extern crate ncurses; extern crate ncurses; //display framework
extern crate termsize; extern crate termsize; //makes sure ncurses border maches term size
//initial function. Reads the ebook passed by argument. //initial function. Reads the ebook passed by argument.
//TODO: add visual library to pull up ebooks. //TODO: add visual library to pull up ebooks.
fn main() { fn main() {
//let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
//let filename = &args[1]; let filename = &args[1];
menu(); epub(filename);
}
//Gets files in directory and returns string with contents.
fn get_directory() -> String{
let mut dir: String = "".to_string();
let mut hold: String;
let paths = fs::read_dir("./").unwrap();
for path in paths {
hold = path.unwrap().path().display().to_string();
dir.push_str(&hold);
dir.push_str("\n");
}
println!("{}", &dir);
return dir;
}
//Generates menu screen
fn menu(){
let termsize::Size {mut rows, mut cols} = termsize::get().unwrap();
println!("height: {} \nwidth: {} \n", rows, cols);
rows -= 5;
cols -= 5;
ncurses::initscr();
ncurses::clear();
let win = ncurses::newwin(rows as i32, cols as i32, 0, 0);
ncurses::wprintw(win, &get_directory());
ncurses::refresh();
ncurses::box_(win, 0, 0);
ncurses::wrefresh(win);
ncurses::getch();
ncurses::endwin();
}
//screen init function
fn screen(line: &str){
ncurses::initscr();
ncurses::clear();
ncurses::addstr(line);
ncurses::refresh();
ncurses::getch();
ncurses::endwin();
}
//parses UTF8 files. Does not work if it has BOM or CRLF line terminators. Currently searching for fix.
fn text(filename: &str) -> std::io::Result<()>{
let mut file = File::open(filename).expect("cannot open file.");
let mut contents = String::new();
file.read_to_string(&mut contents).expect("unreadable file.");
screen(&contents);
Ok(())
}
//parses pdf files
fn pdf(){
}
//parses mobi files
fn mobi(){
} }
//parses epub files //parses epub files
fn epub(){ fn epub(epub_file: &str){
println!("{}", epub_file);
let doc = EpubDoc::new(&epub_file);
assert!(doc.is_ok());
let doc = doc.unwrap();
} }