summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-02-01 02:45:50 +0100
committerrabite <rabite@posteo.de>2019-02-01 02:45:50 +0100
commitea77d6f45a55bf1992c5b5237c73b8ca92bb2114 (patch)
treeaa48d3f67955525578206a11c96dc098744dd0ff /src
parent1e6719fe3368068217968fe0b637604668cb7764 (diff)
show correct directory on left at start
Diffstat (limited to 'src')
-rw-r--r--src/coordinates.rs2
-rw-r--r--src/file_browser.rs26
-rw-r--r--src/listview.rs2
-rw-r--r--src/term.rs16
-rw-r--r--src/widget.rs2
5 files changed, 31 insertions, 17 deletions
diff --git a/src/coordinates.rs b/src/coordinates.rs
index ee9916e..6b79823 100644
--- a/src/coordinates.rs
+++ b/src/coordinates.rs
@@ -12,7 +12,7 @@ pub struct Coordinates {
impl Coordinates {
pub fn new() -> Coordinates {
Coordinates {
- size: Size((1, 1)),
+ size: Size((crate::term::xsize(), crate::term::ysize())),
position: Position((1, 1)),
}
}
diff --git a/src/file_browser.rs b/src/file_browser.rs
index 71f6a37..0211f01 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -4,7 +4,7 @@ use std::error::Error;
use std::io::Write;
use crate::coordinates::{Coordinates, Position, Size};
-use crate::files::Files;
+use crate::files::{File, Files};
use crate::listview::ListView;
use crate::miller_columns::MillerColumns;
use crate::widget::Widget;
@@ -29,7 +29,12 @@ impl FileBrowser {
miller.push_widget(widget);
}
- Ok(FileBrowser { columns: miller })
+ let mut file_browser = FileBrowser { columns: miller };
+
+ file_browser.update_preview();
+ file_browser.fix_selection();
+
+ Ok(file_browser)
}
pub fn enter_dir(&mut self) {
@@ -72,7 +77,7 @@ impl FileBrowser {
// 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();
+ let file = self.columns.get_main_widget().clone_selected_file();
if let Some(grand_parent) = file.grand_parent() {
let mut left_view = ListView::new(Files::new_from_path(&grand_parent).unwrap());
left_view.select_file(&file);
@@ -87,10 +92,19 @@ impl FileBrowser {
preview.set_file(&file);
}
+ pub fn fix_selection(&mut self) {
+ let cwd = self.cwd();
+ self.columns.get_left_widget_mut()
+ .map(|w|
+ w.select_file(&cwd));
+ }
+
+ pub fn cwd(&self) -> File {
+ self.columns.get_main_widget().content.directory.clone()
+ }
+
pub fn quit_with_dir(&self) {
- let selected_file = self.columns.get_main_widget().selected_file();
- let cwd = selected_file.path();
- let cwd = cwd.parent().unwrap();
+ let cwd = self.cwd().path;
let mut filepath = dirs_2::home_dir().unwrap();
filepath.push(".hunter_cwd");
diff --git a/src/listview.rs b/src/listview.rs
index 0cbdd63..a8d029d 100644
--- a/src/listview.rs
+++ b/src/listview.rs
@@ -102,7 +102,7 @@ where
padding = xsize as usize),
} ,
term::highlight_color(),
- term::cursor_left(size.to_string().width() + unit.width()),
+ term::cursor_left((size.to_string().width() + unit.width()) as u16),
size,
unit
)
diff --git a/src/term.rs b/src/term.rs
index ed8380b..bbd8806 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -16,14 +16,14 @@ pub trait ScreenExt: Write {
impl ScreenExt for AlternateScreen<Box<Stdout>> {}
-pub fn xsize() -> usize {
+pub fn xsize() -> u16 {
let (xsize, _) = termion::terminal_size().unwrap();
- xsize as usize
+ xsize
}
-pub fn ysize() -> usize {
+pub fn ysize() -> u16 {
let (_, ysize) = termion::terminal_size().unwrap();
- ysize as usize
+ ysize
}
pub fn sized_string(string: &str, xsize: u16) -> String {
@@ -69,12 +69,12 @@ pub fn from_lscolor(color: &lscolors::Color) -> String {
}
}
-pub fn cursor_left(n: usize) -> String {
- format!("{}", termion::cursor::Left(n as u16))
+pub fn cursor_left(n: u16) -> String {
+ format!("{}", termion::cursor::Left(n))
}
-pub fn gotoy(y: usize) -> String {
- format!("{}", termion::cursor::Goto(1, y as u16))
+pub fn gotoy(y: u16) -> String {
+ format!("{}", termion::cursor::Goto(1, y))
}
pub fn goto_xy(x: u16, y: u16) -> String {
diff --git a/src/widget.rs b/src/widget.rs
index 361c6cc..528b487 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -58,7 +58,7 @@ pub trait Widget {
crate::term::header_color(),
self.render_header(),
" ",
- xsize = crate::term::xsize()
+ xsize = self.get_size().xsize() as usize
)
}