mirror of https://github.com/bobwen-dev/hunter
show correct directory on left at start
This commit is contained in:
parent
1e6719fe33
commit
ea77d6f45a
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
16
src/term.rs
16
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 {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue