From 395b1d1ce023b6d6022d60b4d0ecff5e6c7a45f1 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sat, 18 Mar 2023 12:48:14 -0500 Subject: [PATCH] termsize library added Used termsize to find size of the terminal and display a box properly. Changes depending on size of terminal upon start. --- Cargo.toml | 3 ++- src/main.rs | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 867731b..ebd5720 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ncurses = "5.101.0" \ No newline at end of file +ncurses = "5.101.0" +termsize = "0.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 45d47be..fe6e483 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::fs; use std::io::prelude::*; use std::env; extern crate ncurses; +extern crate termsize; //initial function. Reads the ebook passed by argument. @@ -23,21 +24,14 @@ fn main() { } -fn get_terminal_size()-> (i8, i32, i32){ - - let mut stdscr: i8 = 0; - let mut w: i32 = 0; //width - let mut h: i32 = 0; //height - 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(); @@ -50,13 +44,18 @@ fn get_directory() -> String{ return dir; } + +//Generates menu screen fn menu(){ - - let (mut stdscr, height, width): (i8, i32, i32) = get_terminal_size(); + 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(100, 100, 5, 5); + let win = ncurses::newwin(rows as i32, cols as i32, 0, 0); ncurses::wprintw(win, &get_directory()); ncurses::refresh(); ncurses::box_(win, 0, 0);