2023-03-17 03:22:09 +00:00
|
|
|
/*
|
|
|
|
Program: Bibliofile
|
|
|
|
Language: Rustc 1.68.0
|
|
|
|
ide: Visual Studio Code
|
|
|
|
Operating system: Linux Mint 21.1
|
|
|
|
Purpose: ncurses based ereader and library manager for Linux terminal environments.
|
|
|
|
Last edited: 10:18 PM 3/16/23
|
|
|
|
*/
|
|
|
|
|
2023-03-17 02:10:15 +00:00
|
|
|
use std::fs::File;
|
2023-03-18 01:05:02 +00:00
|
|
|
use std::fs;
|
2023-03-17 02:10:15 +00:00
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::env;
|
2023-03-17 02:58:32 +00:00
|
|
|
extern crate ncurses;
|
2023-03-18 17:48:14 +00:00
|
|
|
extern crate termsize;
|
2023-03-17 02:10:15 +00:00
|
|
|
|
2023-03-17 03:22:09 +00:00
|
|
|
|
|
|
|
//initial function. Reads the ebook passed by argument.
|
|
|
|
//TODO: add visual library to pull up ebooks.
|
2023-03-18 01:05:02 +00:00
|
|
|
fn main() {
|
|
|
|
//let args: Vec<String> = env::args().collect();
|
|
|
|
//let filename = &args[1];
|
|
|
|
menu();
|
2023-03-17 03:22:09 +00:00
|
|
|
|
2023-03-17 02:58:32 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 01:05:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Gets files in directory and returns string with contents.
|
|
|
|
fn get_directory() -> String{
|
|
|
|
|
2023-03-18 17:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-18 01:05:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-18 17:48:14 +00:00
|
|
|
|
|
|
|
//Generates menu screen
|
2023-03-18 01:05:02 +00:00
|
|
|
fn menu(){
|
2023-03-18 17:48:14 +00:00
|
|
|
let termsize::Size {mut rows, mut cols} = termsize::get().unwrap();
|
|
|
|
|
2023-03-18 01:05:02 +00:00
|
|
|
|
2023-03-18 17:48:14 +00:00
|
|
|
println!("height: {} \nwidth: {} \n", rows, cols);
|
|
|
|
rows -= 5;
|
|
|
|
cols -= 5;
|
2023-03-18 01:05:02 +00:00
|
|
|
ncurses::initscr();
|
|
|
|
ncurses::clear();
|
2023-03-18 17:48:14 +00:00
|
|
|
let win = ncurses::newwin(rows as i32, cols as i32, 0, 0);
|
2023-03-18 01:05:02 +00:00
|
|
|
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){
|
|
|
|
|
2023-03-17 02:58:32 +00:00
|
|
|
ncurses::initscr();
|
2023-03-17 21:27:16 +00:00
|
|
|
ncurses::clear();
|
2023-03-17 18:59:57 +00:00
|
|
|
ncurses::addstr(line);
|
2023-03-17 02:58:32 +00:00
|
|
|
ncurses::refresh();
|
|
|
|
ncurses::getch();
|
|
|
|
ncurses::endwin();
|
|
|
|
|
2023-03-17 01:11:57 +00:00
|
|
|
}
|
2023-03-18 01:05:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
fn epub(){
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|