Menu improved
Added menu display, with directory contents in box. Also added different ebook functions to finish later. Will use them once I get to them. Calling it a night, but will add menu selecting and hopefully the ability to read text files tomorrow.
This commit is contained in:
parent
627ed3d7a7
commit
776d71b16c
104
src/main.rs
104
src/main.rs
@ -8,6 +8,7 @@ Last edited: 10:18 PM 3/16/23
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::fs;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::env;
|
use std::env;
|
||||||
extern crate ncurses;
|
extern crate ncurses;
|
||||||
@ -15,31 +16,60 @@ extern crate ncurses;
|
|||||||
|
|
||||||
//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() -> std::io::Result<()> {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
//let args: Vec<String> = env::args().collect();
|
||||||
|
//let filename = &args[1];
|
||||||
|
menu();
|
||||||
|
|
||||||
let filename = &args[1];
|
|
||||||
|
|
||||||
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(())
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_terminal_size()-> (i8, i32, i32){
|
||||||
|
|
||||||
//screen init function
|
|
||||||
fn screen(line: &str){
|
|
||||||
|
|
||||||
let mut stdscr: i8 = 0;
|
let mut stdscr: i8 = 0;
|
||||||
let mut w: i32 = 0; //width
|
let mut w: i32 = 0; //width
|
||||||
let mut h: i32 = 0; //height
|
let mut h: i32 = 0; //height
|
||||||
ncurses::getmaxyx(&mut stdscr, &mut h, &mut w);
|
ncurses::getmaxyx(&mut stdscr, &mut h, &mut w);
|
||||||
|
|
||||||
|
return (stdscr, h, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn menu(){
|
||||||
|
|
||||||
|
let (mut stdscr, height, width): (i8, i32, i32) = get_terminal_size();
|
||||||
|
|
||||||
|
ncurses::initscr();
|
||||||
|
ncurses::clear();
|
||||||
|
let win = ncurses::newwin(100, 100, 5, 5);
|
||||||
|
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::initscr();
|
||||||
ncurses::clear();
|
ncurses::clear();
|
||||||
ncurses::addstr(line);
|
ncurses::addstr(line);
|
||||||
@ -48,3 +78,45 @@ fn screen(line: &str){
|
|||||||
ncurses::endwin();
|
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
|
||||||
|
fn epub(){
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user