mirror of https://github.com/bobwen-dev/hunter
some lipstick
This commit is contained in:
parent
9cd395d8f7
commit
d3746dacb2
|
@ -117,12 +117,17 @@ impl FileBrowser {
|
|||
|
||||
pub fn quit_with_dir(&self) {
|
||||
let cwd = self.cwd().path;
|
||||
let selected_file = self.selected_file().path.to_string_lossy();
|
||||
|
||||
let mut filepath = dirs_2::home_dir().unwrap();
|
||||
filepath.push(".hunter_cwd");
|
||||
|
||||
let output = format!("HUNTER_CWD=\"{}\"\nF=\"{}\"",
|
||||
cwd.to_str().unwrap(),
|
||||
selected_file);
|
||||
|
||||
let mut file = std::fs::File::create(filepath).unwrap();
|
||||
file.write(cwd.to_str().unwrap().as_bytes()).unwrap();
|
||||
file.write(output.as_bytes()).unwrap();
|
||||
panic!("Quitting!");
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +152,14 @@ impl Widget for FileBrowser {
|
|||
self.columns.coordinates = coordinates.clone();
|
||||
}
|
||||
fn render_header(&self) -> String {
|
||||
"".to_string()
|
||||
let file = self.selected_file();
|
||||
let name = &file.name;
|
||||
let color = if file.is_dir() || file.color.is_none() {
|
||||
crate::term::highlight_color() } else {
|
||||
crate::term::from_lscolor(file.color.as_ref().unwrap()) };
|
||||
|
||||
let path = file.path.parent().unwrap().to_string_lossy().to_string();
|
||||
format!("{}/{}{}", path, &color, name )
|
||||
}
|
||||
fn refresh(&mut self) {
|
||||
self.columns.refresh();
|
||||
|
@ -164,8 +176,8 @@ 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(),
|
||||
Key::Right | Key::Char('f') => self.enter_dir(),
|
||||
Key::Left | Key::Char('b') => self.go_back(),
|
||||
_ => self.columns.get_main_widget_mut().on_key(key),
|
||||
}
|
||||
self.update_preview();
|
||||
|
|
|
@ -283,11 +283,11 @@ impl Widget for ListView<Files> {
|
|||
|
||||
fn on_key(&mut self, key: Key) {
|
||||
match key {
|
||||
Key::Up => {
|
||||
Key::Up | Key::Char('p') => {
|
||||
self.move_up();
|
||||
self.refresh();
|
||||
}
|
||||
Key::Down => {
|
||||
Key::Down | Key::Char('n') => {
|
||||
self.move_down();
|
||||
self.refresh();
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ impl Previewer {
|
|||
.output().unwrap();
|
||||
|
||||
|
||||
if output.status.code().unwrap() == 5 {
|
||||
if output.status.code().unwrap() != 0 {
|
||||
write!(std::io::stdout(), "{}", redraw).unwrap();
|
||||
} else {
|
||||
let output = std::str::from_utf8(&output.stdout)
|
||||
|
|
|
@ -53,11 +53,12 @@ pub trait Widget: PartialEq {
|
|||
|
||||
fn get_header_drawlist(&mut self) -> String {
|
||||
format!(
|
||||
"{}{}{}{:xsize$}",
|
||||
"{}{}{:xsize$}{}{}",
|
||||
crate::term::goto_xy(1, 1),
|
||||
crate::term::header_color(),
|
||||
self.render_header(),
|
||||
" ",
|
||||
crate::term::goto_xy(1, 1),
|
||||
self.render_header(),
|
||||
xsize = self.get_size().xsize() as usize
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue