summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/coordinates.rs35
-rw-r--r--src/file_browser.rs60
-rw-r--r--src/files.rs158
-rw-r--r--src/listview.rs179
-rw-r--r--src/main.rs92
-rw-r--r--src/miller_columns.rs92
-rw-r--r--src/preview.rs71
-rw-r--r--src/term.rs42
-rw-r--r--src/textview.rs56
-rw-r--r--src/widget.rs66
-rw-r--r--src/win_main.rs3
-rw-r--r--src/window.rs81
12 files changed, 470 insertions, 465 deletions
diff --git a/src/coordinates.rs b/src/coordinates.rs
index 6283cdf..ee9916e 100644
--- a/src/coordinates.rs
+++ b/src/coordinates.rs
@@ -1,10 +1,9 @@
-#[derive(Debug,Clone,PartialEq)]
-pub struct Size(pub (u16,u16));
-#[derive(Debug,Clone,PartialEq)]
-pub struct Position(pub (u16,u16));
+#[derive(Debug, Clone, PartialEq)]
+pub struct Size(pub (u16, u16));
+#[derive(Debug, Clone, PartialEq)]
+pub struct Position(pub (u16, u16));
-
-#[derive(Debug,Clone,PartialEq)]
+#[derive(Debug, Clone, PartialEq)]
pub struct Coordinates {
pub size: Size,
pub position: Position,
@@ -12,12 +11,16 @@ pub struct Coordinates {
impl Coordinates {
pub fn new() -> Coordinates {
- Coordinates { size: Size ((1,1)), position: Position ((1,1)) }
- }
- pub fn size(&self) -> &Size {
- &self.size
+ Coordinates {
+ size: Size((1, 1)),
+ position: Position((1, 1)),
+ }
}
+ // pub fn size(&self) -> &Size {
+ // &self.size
+ // }
+
pub fn xsize(&self) -> u16 {
self.size.xsize()
}
@@ -34,11 +37,11 @@ impl Coordinates {
self.position().clone()
}
-// pub fn left(&self) -> /
+ // pub fn left(&self) -> /
}
impl Size {
- pub fn size(&self) -> (u16,u16) {
+ pub fn size(&self) -> (u16, u16) {
self.0
}
pub fn xsize(&self) -> u16 {
@@ -50,13 +53,13 @@ impl Size {
}
impl Position {
- pub fn position(&self) -> (u16,u16) {
+ pub fn position(&self) -> (u16, u16) {
self.0
}
pub fn x(&self) -> u16 {
(self.0).1
}
- pub fn y(&self) -> u16 {
- (self.0).1
- }
+ // pub fn y(&self) -> u16 {
+ // (self.0).1
+ // }
}
diff --git a/src/file_browser.rs b/src/file_browser.rs
index c770fa3..2bae8c3 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -1,34 +1,35 @@
-use termion::event::{Key};
+use termion::event::Key;
+use std::error::Error;
use std::io::Write;
-use crate::widget::Widget;
+use crate::coordinates::{Coordinates, Position, Size};
use crate::files::Files;
-//use crate::hbox::HBox;
use crate::listview::ListView;
-use crate::coordinates::{Size,Position,Coordinates};
-use crate::preview::Previewer;
use crate::miller_columns::MillerColumns;
+use crate::widget::Widget;
pub struct FileBrowser {
pub columns: MillerColumns<ListView<Files>>,
}
impl FileBrowser {
- pub fn new() -> FileBrowser {
+ pub fn new() -> Result<FileBrowser, Box<Error>> {
let cwd = std::env::current_dir().unwrap();
let mut miller = MillerColumns::new();
- let mut lists: Vec<_> = cwd.ancestors().map(|path| {
- ListView::new(Files::new_from_path(path).unwrap())
- }).collect();
+ let lists: Result<Vec<ListView<Files>>, Box<Error>> = cwd
+ .ancestors()
+ .map(|path| Ok(ListView::new(Files::new_from_path(path)?)))
+ .collect();
+ let mut lists = lists?;
lists.reverse();
for widget in lists {
miller.push_widget(widget);
}
- FileBrowser { columns: miller }
+ Ok(FileBrowser { columns: miller })
}
pub fn enter_dir(&mut self) {
@@ -37,30 +38,47 @@ impl FileBrowser {
let path = fileview.selected_file().path();
match Files::new_from_path(&path) {
Ok(files) => {
+ std::env::set_current_dir(path).unwrap();
let view = ListView::new(files);
self.columns.push_widget(view);
self.update_preview();
- },
- Err(err) => {
- self.show_status(&format!("Can't open this path: {}", err));
+ }
+ Err(_) => {
+ //self.show_status(&format!("Can't open this path: {}", err));
+
+ let status = std::process::Command::new("xdg-open")
+ .args(dbg!(path.file_name()))
+ .status();
+ match status {
+ Ok(status) => {
+ self.show_status(&format!("\"{}\" exited with {}", "xdg-open", status))
+ }
+ Err(err) => {
+ self.show_status(&format!("Can't run this \"{}\": {}", "xdg-open", err))
+ }
+ }
}
};
}
pub fn go_back(&mut self) {
- if self.columns.get_left_widget().is_none() { return }
+ if self.columns.get_left_widget().is_none() {
+ return;
+ }
+ let fileview = self.columns.get_main_widget();
+ let path = fileview.selected_file().grand_parent().unwrap();
+ std::env::set_current_dir(path).unwrap();
self.columns.pop_widget();
// Make sure there's a directory on the left unless it's /
if self.columns.get_left_widget().is_none() {
let file = self.columns.get_main_widget().selected_file().clone();
if let Some(grand_parent) = file.grand_parent() {
- let left_view
- = ListView::new(Files::new_from_path(grand_parent).unwrap());
+ let mut left_view = ListView::new(Files::new_from_path(&grand_parent).unwrap());
+ left_view.select_file(&file);
self.columns.prepend_widget(left_view);
}
}
-
}
pub fn update_preview(&mut self) {
@@ -74,16 +92,15 @@ impl FileBrowser {
let cwd = selected_file.path();
let cwd = cwd.parent().unwrap();
- let mut filepath = std::env::home_dir().unwrap();
+ let mut filepath = dirs_2::home_dir().unwrap();
filepath.push(".hunter_cwd");
let mut file = std::fs::File::create(filepath).unwrap();
- file.write(cwd.to_str().unwrap().as_bytes());
+ file.write(cwd.to_str().unwrap().as_bytes()).unwrap();
panic!("Quitting!");
}
}
-
impl Widget for FileBrowser {
fn render(&self) -> Vec<String> {
vec![]
@@ -121,13 +138,12 @@ impl Widget for FileBrowser {
}
}
-
fn on_key(&mut self, key: Key) {
match key {
Key::Char('Q') => self.quit_with_dir(),
Key::Right => self.enter_dir(),
Key::Left => self.go_back(),
- _ => self.columns.get_main_widget_mut().on_key(key)
+ _ => self.columns.get_main_widget_mut().on_key(key),
}
self.update_preview();
}
diff --git a/src/files.rs b/src/files.rs
index 17dc3a2..e03c3a0 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -1,12 +1,12 @@
-use std::ops::Index;
-use std::error::Error;
-use std::path::PathBuf;
-use std::ffi::OsStr;
use std::cmp::{Ord, Ordering};
+use std::error::Error;
+use std::ops::Index;
+use std::path::{Path, PathBuf};
use std::time::SystemTime;
-use lscolors::{LsColors, Style};
+use lscolors::LsColors;
use mime_detective;
+use rayon::prelude::*;
lazy_static! {
static ref COLORS: LsColors = LsColors::from_env().unwrap();
@@ -14,6 +14,7 @@ lazy_static! {
#[derive(PartialEq)]
pub struct Files {
+ pub directory: File,
pub files: Vec<File>,
pub sort: SortBy,
pub dirs_first: bool,
@@ -28,40 +29,52 @@ impl Index<usize> for Files {
fn get_kind(file: &std::fs::DirEntry) -> Kind {
let file = file.file_type().unwrap();
- if file.is_file() { return Kind::File; }
- if file.is_dir() { return Kind::Directory; }
- if file.is_symlink() { return Kind::Link; }
+ if file.is_file() {
+ return Kind::File;
+ }
+ if file.is_dir() {
+ return Kind::Directory;
+ }
+ if file.is_symlink() {
+ return Kind::Link;
+ }
Kind::Pipe
}
-impl Files {
- pub fn new_from_path<S: AsRef<OsStr> + Sized>(path: S)
- -> Result<Files, Box<dyn Error>>
- where S: std::convert::AsRef<std::path::Path> {
- let mut files = Vec::new();
-
- for file in std::fs::read_dir(path)? {
- let file = file?;
- let name = file.file_name();
- let name = name.to_string_lossy();
- let kind = get_kind(&file);
- let path = file.path();
- let meta = file.metadata()?;
- let size = meta.len() / 1024;
- let mtime = meta.modified()?;
-
- let color
- = match COLORS.style_for_path_with_metadata(file.path(), Some(&meta)) {
- Some(style) => { style.clone().foreground },
- None => None
- };
- let file = File::new(&name, path, kind, size as usize, mtime, color);
- files.push(file)
- }
+fn get_color(path: &Path, meta: &std::fs::Metadata) -> Option<lscolors::Color> {
+ match COLORS.style_for_path_with_metadata(path, Some(&meta)) {
+ Some(style) => style.clone().foreground,
+ None => None,
+ }
+}
- let mut files = Files { files: files,
- sort: SortBy::Name,
- dirs_first: true };
+impl Files {
+ pub fn new_from_path(path: &Path) -> Result<Files, Box<dyn Error>> {
+ let direntries: Result<Vec<_>, _> = std::fs::read_dir(&path)?.collect();
+
+ let files: Vec<_> = direntries?
+ .par_iter()
+ .map(|file| {
+ //let file = file?;
+ let name = file.file_name();
+ let name = name.to_string_lossy();
+ let kind = get_kind(&file);
+ let path = file.path();
+ let meta = file.metadata().unwrap();
+ let size = meta.len() / 1024;
+ let mtime = meta.modified().unwrap();
+
+ let color = get_color(&path, &meta);
+ File::new(&name, path, kind, size as usize, mtime, color)
+ })
+ .collect();
+
+ let mut files = Files {
+ directory: File::new_from_path(&path)?,
+ files: files,
+ sort: SortBy::Name,
+ dirs_first: true,
+ };
files.sort();
Ok(files)
@@ -69,23 +82,21 @@ impl Files {
pub fn sort(&mut self) {
match self.sort {
- SortBy::Name => {
- self.files.sort_by(|a,b| {
- alphanumeric_sort::compare_str(&a.name, &b.name)
- })
- },
+ SortBy::Name => self
+ .files
+ .sort_by(|a, b| alphanumeric_sort::compare_str(&a.name, &b.name)),
SortBy::Size => {
- self.files.sort_by(|a,b| {
+ self.files.sort_by(|a, b| {
if a.size == b.size {
- return alphanumeric_sort::compare_str(&b.name, &a.name)
+ return alphanumeric_sort::compare_str(&b.name, &a.name);
}
a.size.cmp(&b.size).reverse()
});
- },
+ }
SortBy::MTime => {
- self.files.sort_by(|a,b| {
+ self.files.sort_by(|a, b| {
if a.mtime == b.mtime {
- return alphanumeric_sort::compare_str(&a.name, &b.name)
+ return alphanumeric_sort::compare_str(&a.name, &b.name);
}
a.mtime.cmp(&b.mtime)
});
@@ -93,10 +104,12 @@ impl Files {
};
if self.dirs_first {
- self.files.sort_by(|a,b| {
+ self.files.sort_by(|a, b| {
if a.is_dir() && !b.is_dir() {
Ordering::Less
- } else { Ordering::Equal }
+ } else {
+ Ordering::Equal
+ }
});
}
}
@@ -105,14 +118,10 @@ impl Files {
self.sort = match self.sort {
SortBy::Name => SortBy::Size,
SortBy::Size => SortBy::MTime,
- SortBy::MTime => SortBy::Name
+ SortBy::MTime => SortBy::Name,
};
}
- pub fn iter(&self) -> std::slice::Iter<File> {
- self.files.iter()
- }
-
pub fn len(&self) -> usize {
self.files.len()
}
@@ -123,22 +132,21 @@ pub enum Kind {
Directory,
File,
Link,
- Pipe
+ Pipe,
}
impl std::fmt::Display for SortBy {
- fn fmt(&self, formatter: &mut std::fmt::Formatter<'_> )
- -> Result<(), std::fmt::Error> {
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
let text = match self {
SortBy::Name => "name",
SortBy::Size => "size",
- SortBy::MTime => "mtime"
+ SortBy::MTime => "mtime",
};
write!(formatter, "{}", text)
}
}
-#[derive(Debug,Copy,Clone,PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq)]
pub enum SortBy {
Name,
Size,
@@ -158,14 +166,15 @@ pub struct File {
// flags: Option<String>,
}
-
impl File {
- pub fn new(name: &str,
- path: PathBuf,
- kind: Kind,
- size: usize,
- mtime: SystemTime,
- color: Option<lscolors::Color>) -> File {
+ pub fn new(
+ name: &str,
+ path: PathBuf,
+ kind: Kind,
+ size: usize,
+ mtime: SystemTime,
+ color: Option<lscolors::Color>,
+ ) -> File {
File {
name: name.to_string(),
path: path,
@@ -178,6 +187,22 @@ impl File {
// flags: None,
}
}
+
+ pub fn new_from_path(path: &Path) -> Result<File, Box<Error>> {
+ let pathbuf = path.to_path_buf();
+ let name = path
+ .file_name()
+ .map(|name| name.to_string_lossy().to_string())
+ .unwrap_or("/".to_string());
+
+ let kind = Kind::Directory; //get_kind(&path);
+ let meta = &path.metadata().unwrap();
+ let size = meta.len() / 1024;
+ let mtime = meta.modified().unwrap();
+ let color = get_color(&path, meta);
+ Ok(File::new(&name, pathbuf, kind, size as usize, mtime, color))
+ }
+
pub fn calculate_size(&self) -> (usize, String) {
let mut unit = 0;
let mut size = self.size.unwrap();
@@ -191,8 +216,9 @@ impl File {
2 => " GB",
3 => " TB",
4 => "wtf are you doing",
- _ => ""
- }.to_string();
+ _ => "",
+ }
+ .to_string();
(size, unit)
}
diff --git a/src/listview.rs b/src/listview.rs
index c742877..9ec3a6c 100644
--- a/src/listview.rs
+++ b/src/listview.rs
@@ -1,16 +1,20 @@
-use unicode_width::{UnicodeWidthStr};
-use termion::event::{Key,Event};
+use rayon::prelude::*;
+use termion::event::{Event, Key};
+use unicode_width::UnicodeWidthStr;
use std::path::{Path, PathBuf};
-use crate::term;
+use crate::coordinates::{Coordinates, Position, Size};
use crate::files::{File, Files};
+use crate::term;
use crate::widget::Widget;
-use crate::coordinates::{Coordinates,Size,Position};
// Maybe also buffer drawlist for efficiency when it doesn't change every draw
-pub struct ListView<T> {
+pub struct ListView<T>
+where
+ T: Send,
+{
pub content: T,
selection: usize,
offset: usize,
@@ -20,25 +24,26 @@ pub struct ListView<T> {
coordinates: Coordinates,
}
-impl<T: 'static> ListView<T> where ListView<T>: Widget {
+impl<T> ListView<T>
+where
+ ListView<T>: Widget,
+ T: Send,
+{
pub fn new(content: T) -> Self {
let view = ListView::<T> {
content: content,
selection: 0,
offset: 0,
buffer: Vec::new(),
- coordinates: Coordinates { size: Size ((1,1)),
- position: Position((1,1)) }
- // dimensions: (1,1),
- // position: (1,1)
+ coordinates: Coordinates {
+ size: Size((1, 1)),
+ position: Position((1, 1)),
+ }, // dimensions: (1,1),
+ // position: (1,1)
};
view
}
- pub fn to_trait(self) -> Box<Widget> {
- Box::new(self)
- }
-
fn move_up(&mut self) {
if self.selection == 0 {
return;
@@ -58,8 +63,7 @@ impl<T: 'static> ListView<T> where ListView<T>: Widget {
return;
}
- if self.selection + 1 >= y_size && self.selection + 1 - self.offset >= y_size
- {
+ if self.selection + 1 >= y_size && self.selection + 1 - self.offset >= y_size {
self.offset += 1;
}
@@ -70,7 +74,9 @@ impl<T: 'static> ListView<T> where ListView<T>: Widget {
let ysize = self.coordinates.ysize() as usize;
let mut offset = 0;
- while position + 1 > ysize + offset { offset += 1 }
+ while position + 1 > ysize + offset {
+ offset += 1
+ }
self.offset = offset;
self.selection = position;
@@ -82,35 +88,29 @@ impl<T: 'static> ListView<T> where ListView<T>: Widget {
let xsize = self.get_size().xsize();
let sized_string = term::sized_string(&name, xsize);
- let padding = xsize as usize - sized_string.width();
- let padded_string = format!("{:padding$}",
- sized_string,
- padding = xsize as usize);
+
+ let padded_string = format!("{:padding$}", sized_string, padding = xsize as usize);
let styled_string = match &file.color {
- Some(color) => format!("{}{}",
- term::from_lscolor(color),
- &padded_string),
- _ => format!("{}{}",
- term::normal_color(),
- padded_string)
+ Some(color) => format!("{}{}", term::from_lscolor(color), &padded_string),
+ _ => format!("{}{}", term::normal_color(), padded_string),
};
-
format!(
"{}{}{}{}{}",
styled_string,
term::highlight_color(),
term::cursor_left(size.to_string().width() + unit.width()),
size,
- unit)
+ unit
+ )
}
-
}
-impl ListView<Files> where
+impl ListView<Files>
+where
ListView<Files>: Widget,
- Files: std::ops::Index<usize, Output=File>,
- Files: std::marker::Sized
+ Files: std::ops::Index<usize, Output = File>,
+ Files: std::marker::Sized,
{
pub fn selected_file(&self) -> &File {
let selection = self.selection;
@@ -131,7 +131,7 @@ impl ListView<Files> where
pub fn goto_grand_parent(&mut self) {
match self.grand_parent() {
Some(grand_parent) => self.goto_path(&grand_parent),
- None => self.show_status("Can't go further!")
+ None => self.show_status("Can't go further!"),
}
}
@@ -142,13 +142,13 @@ impl ListView<Files> where
}
pub fn goto_path(&mut self, path: &Path) {
- match crate::files::Files::new_from_path(path){
+ match crate::files::Files::new_from_path(path) {
Ok(files) => {
self.content = files;
self.selection = 0;
self.offset = 0;
self.refresh();
- },
+ }
Err(err) => {
self.show_status(&format!("Can't open this path: {}", err));
return;
@@ -156,8 +156,13 @@ impl ListView<Files> where
}
}
- fn select_file(&mut self, file: &File) {
- let pos = self.content.files.iter().position(|item| item == file).unwrap();
+ pub fn select_file(&mut self, file: &File) {
+ let pos = self
+ .content
+ .files
+ .par_iter()
+ .position_any(|item| item == file)
+ .unwrap();
self.set_selection(pos);
}
@@ -182,28 +187,25 @@ impl ListView<Files> where
fn exec_cmd(&mut self) {
match self.minibuffer("exec ($s for selected files)") {
Some(cmd) => {
- let filename = self.selected_file().name.clone();
- let cmd = cmd.replace("$s", &filename);
self.show_status(&format!("Running: \"{}\"", &cmd));
- let mut parts = cmd.split_whitespace();
- let exe = parts.next().unwrap();
- let status = std::process::Command::new(exe).args(parts)
- .status();
+
+ let filename = self.selected_file().name.clone();
+ let cmd = cmd.replace("$s", &format!("{}", &filename));
+
+ let status = std::process::Command::new("sh")
+ .arg("-c")
+ .arg(&cmd)
+ .status();
match status {
- Ok(status) => self.show_status(&format!("\"{}\" exited with {}",
- cmd,
- status)),
- Err(err) => self.show_status(&format!("Can't run this \"{}\": {}",
- cmd,
- err))
+ Ok(status) => self.show_status(&format!("\"{}\" exited with {}", cmd, status)),
+ Err(err) => self.show_status(&format!("Can't run this \"{}\": {}", cmd, err)),
}
- },
- None => self.show_status("")
+ }
+ None => self.show_status(""),
}
}
}
-
impl Widget for ListView<Files> {
fn get_size(&self) -> &Size {
&self.coordinates.size
@@ -221,7 +223,9 @@ impl Widget for ListView<Files> {
&self.coordinates
}
fn set_coordinates(&mut self, coordinates: &Coordinates) {
- if self.coordinates == *coordinates { return }
+ if self.coordinates == *coordinates {
+ return;
+ }
self.coordinates = coordinates.clone();
self.refresh();
}
@@ -229,32 +233,39 @@ impl Widget for ListView<Files> {
self.buffer = self.render();
}
fn render(&self) -> Vec<String> {
- self.content.iter().map(|file| {
- self.render_line(&file)
- }).collect()
+ self.content
+ .files
+ .par_iter()
+ .map(|file| self.render_line(&file))
+ .collect()
}
fn get_drawlist(&self) -> String {
let mut output = term::reset();
- let (xsize, ysize) = self.get_size().size();
+ let (_, ysize) = self.get_size().size();
let (xpos, ypos) = self.coordinates.position().position();
- for (i, item) in self.buffer
- .iter()
+ output += &self
+ .buffer
+ .par_iter()
.skip(self.offset)
.take(ysize as usize)
.enumerate()
- {
- output += &term::normal_color();
+ .map(|(i, item)| {
+ let mut output = term::normal_color();
- if i == (self.selection - self.offset) {
- output += &term::invert();
- }
- output += &format!("{}{}{}",
- term::goto_xy(xpos, i as u16 + ypos),
- item,
- term::reset());
- }
+ if i == (self.selection - self.offset) {
+ output += &term::invert();
+ }
+ output += &format!(
+ "{}{}{}",
+ term::goto_xy(xpos, i as u16 + ypos),
+ item,
+ term::reset()
+ );
+ String::from(output)
+ })
+ .collect::<String>();
output += &self.get_redraw_empty_list(self.buffer.len());
@@ -266,18 +277,22 @@ impl Widget for ListView<Files> {
fn on_key(&mut self, key: Key) {
match key {
- Key::Up => { self.move_up(); self.refresh(); },
- Key::Down => { self.move_down(); self.refresh(); },
- Key::Left => {
- self.goto_grand_parent()
- },
- Key::Right => {
- self.goto_selected()
- },
- Key::Char('s') => { self.cycle_sort() } ,
- Key::Char('d') => self.toggle_dirs_first() ,
- Key::Char('!') => self.exec_cmd() ,
- _ => { self.bad(Event::Key(key)); }
+ Key::Up => {
+ self.move_up();
+ self.refresh();
+ }
+ Key::Down => {
+ self.move_down();
+ self.refresh();
+ }
+ Key::Left => self.goto_grand_parent(),
+ Key::Right => self.goto_selected(),
+ Key::Char('s') => self.cycle_sort(),
+ Key::Char('d') => self.toggle_dirs_first(),
+ Key::Char('!') => self.exec_cmd(),
+ _ => {
+ self.bad(Event::Key(key));
+ }
}
}
}
diff --git a/src/main.rs b/src/main.rs
index b6a2321..2cf76e0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,98 +3,40 @@ extern crate unicode_width;
#[macro_use]
extern crate lazy_static;
extern crate alphanumeric_sort;
+extern crate dirs_2;
extern crate lscolors;
-
-use std::io::{stdout, Write};
-
-
-use termion::screen::AlternateScreen;
+extern crate mime_detective;
+extern crate rayon;
use termion::input::MouseTerminal;
use termion::raw::IntoRawMode;
+use termion::screen::AlternateScreen;
-mod term;
-mod window;
-mod listview;
+use std::io::{stdout, Write};
+
+mod coordinates;
+mod file_browser;
mod files;
-mod win_main;
-mod widget;
-//mod hbox;
+mod listview;
mod miller_columns;
-mod coordinates;
+mod preview;
+mod term;
+mod textview;
+mod widget;
+mod win_main;
+mod window;
-use listview::ListView;
use window::Window;
-//use hbox::HBox;
-use miller_columns::MillerColumns;
-use widget::Widget;
-use coordinates::{Coordinates,Size,Position};
-mod file_browser;
-use file_browser::FileBrowser;
fn main() {
// Need to do this here to actually turn terminal into raw mode...
let mut _screen = AlternateScreen::from(Box::new(stdout()));
let mut _stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
- let (xsize, ysize) = term::size();
- let ysize = ysize - 1;
-
- let coordinates = Coordinates { size: Size ((xsize, ysize - 1)) ,
- position: Position( (1, 2 )) };
-
-
- let files = files::Files::new_from_path("/home/project/").unwrap();
- let mut listview = ListView::new(files);
-
- let files = files::Files::new_from_path("/home/project/Downloads/").unwrap();
- let mut listview2 = ListView::new(files);
-
- let files = files::Files::new_from_path("/home/").unwrap();
- let mut listview3 = ListView::new(files);
-
- // let files = files::Files::new_from_path("/").unwrap();
- // let mut listview4 = ListView::new(files);
-
- // listview.set_size( Size ((20,30)));
- // listview.set_position(Position((160,1)));
-
- // listview2.set_size( Size ((20,30)));
- // listview2.set_position(Position((160,1)));
-
- // listview3.set_size( Size ((20,30)));
- // listview3.set_position(Position((160,1)));
-
- // listview4.set_size( Size ((20,30)));
- // listview4.set_position(Position((160,1)));
-
-
- // listview2.set_dimensions((95,53));
- // listview2.set_position((95,1));
-
- // let boxed = vec![listview.to_trait(), listview2.to_trait()];
-
- // let hbox = HBox::new(boxed, (xsize, ysize-1), (1,2) , 0);
-
-
-
- let mut miller
- = MillerColumns::new(vec![listview3,listview,listview2],
- coordinates,
- (33, 33, 33));
-
- // miller.main = Some(listview2);
- // miller.left = Some(listview3);
- // miller.preview = Some(listview4);
-
- let coords = dbg!(miller.calculate_coordinates());
-
+ let filebrowser = crate::file_browser::FileBrowser::new().unwrap();
- miller.refresh();
- let filebrowser = crate::file_browser::FileBrowser { columns: miller };
-
let mut win = Window::new(filebrowser);
win.handle_input();
write!(_stdout, "{}", termion::cursor::Show).unwrap();
- }
+}
diff --git a/src/miller_columns.rs b/src/miller_columns.rs
index 8e6459d..1d69442 100644
--- a/src/miller_columns.rs
+++ b/src/miller_columns.rs
@@ -1,33 +1,30 @@
-use termion::event::{Key,Event};
+use termion::event::Key;
-
-use crate::widget::Widget;
-use crate::files::Files;
-//use crate::hbox::HBox;
-use crate::listview::ListView;
-use crate::coordinates::{Coordinates, Size,Position};
-use crate::files::File;
+use crate::coordinates::{Coordinates, Position, Size};
use crate::preview::Previewer;
+use crate::widget::Widget;
pub struct MillerColumns<T> {
pub widgets: Vec<T>,
// pub left: Option<T>,
// pub main: Option<T>,
pub preview: Previewer,
- pub ratio: (u16,u16,u16),
+ pub ratio: (u16, u16, u16),
pub coordinates: Coordinates,
}
-
-
-
-
-impl<T> MillerColumns<T> where T: Widget {
- pub fn new() -> Self { Self { widgets: vec![],
- coordinates: Coordinates::new(),
- ratio: (33, 33, 33),
- preview: Previewer::new() } }
-
+impl<T> MillerColumns<T>
+where
+ T: Widget,
+{
+ pub fn new() -> Self {
+ Self {
+ widgets: vec![],
+ coordinates: Coordinates::new(),
+ ratio: (33, 33, 33),
+ preview: Previewer::new(),
+ }
+ }
pub fn push_widget(&mut self, mut widget: T) {
let mcoords = self.calculate_coordinates().1;
@@ -55,43 +52,49 @@ impl<T> MillerColumns<T> where T: Widget {
let ratio = self.ratio;
let left_xsize = xsize * ratio.0 / 100;
- let left_size = Size ((left_xsize, ysize));
+ let left_size = Size((left_xsize, ysize));
let left_pos = self.coordinates.top();
-
let main_xsize = xsize * ratio.1 / 100;
- let main_size = Size ( (main_xsize, ysize) );
- let main_pos = Position ( (left_xsize + 2, top ));
+ let main_size = Size((main_xsize, ysize));
+ let main_pos = Position((left_xsize + 2, top));
let preview_xsize = xsize * ratio.2 / 100;
- let preview_size = Size ( (preview_xsize, ysize) );
- let preview_pos = Position ( (left_xsize + main_xsize + 3, top) );