1
0
mirror of https://github.com/bobwen-dev/hunter synced 2025-04-12 00:55:41 +02:00

listview fixes

This commit is contained in:
rabite 2019-01-29 15:47:45 +01:00
parent 3a2b02cba6
commit ca521059e4
3 changed files with 55 additions and 29 deletions

View File

@ -49,12 +49,12 @@ impl Files {
let size = meta.len() / 1024; let size = meta.len() / 1024;
let mtime = meta.modified()?; let mtime = meta.modified()?;
let style let color
= match COLORS.style_for_path_with_metadata(file.path(), Some(&meta)) { = match COLORS.style_for_path_with_metadata(file.path(), Some(&meta)) {
Some(style) => Some(style.clone()), Some(style) => { style.clone().foreground },
None => None None => None
}; };
let file = File::new(&name, path, kind, size as usize, mtime, style); let file = File::new(&name, path, kind, size as usize, mtime, color);
files.push(file) files.push(file)
} }
@ -151,7 +151,7 @@ pub struct File {
pub size: Option<usize>, pub size: Option<usize>,
pub kind: Kind, pub kind: Kind,
pub mtime: SystemTime, pub mtime: SystemTime,
pub style: Option<Style>, pub color: Option<lscolors::Color>,
// owner: Option<String>, // owner: Option<String>,
// group: Option<String>, // group: Option<String>,
// flags: Option<String>, // flags: Option<String>,
@ -164,14 +164,14 @@ impl File {
kind: Kind, kind: Kind,
size: usize, size: usize,
mtime: SystemTime, mtime: SystemTime,
style: Option<Style>) -> File { color: Option<lscolors::Color>) -> File {
File { File {
name: name.to_string(), name: name.to_string(),
path: path, path: path,
size: Some(size), size: Some(size),
kind: kind, kind: kind,
mtime: mtime, mtime: mtime,
style: style color: color
// owner: None, // owner: None,
// group: None, // group: None,
// flags: None, // flags: None,

View File

@ -82,26 +82,29 @@ impl<T: 'static> ListView<T> where ListView<T>: Widget {
let xsize = self.get_size().xsize(); let xsize = self.get_size().xsize();
let sized_string = term::sized_string(&name, xsize); let sized_string = term::sized_string(&name, xsize);
let padding = xsize - sized_string.width() as u16; let padding = xsize as usize - sized_string.width();
let styled_string = match &file.style { let padded_string = format!("{:padding$}",
Some(style) => style.to_ansi_term_style().paint(sized_string).to_string(), sized_string,
_ => format!("{}{}", term::normal_color(), 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)
}; };
format!( format!(
"{}{:padding$}{}{}{}{}", "{}{}{}{}{}",
styled_string, styled_string,
" ",
term::highlight_color(), term::highlight_color(),
term::cursor_left(size.to_string().width() + unit.width()), term::cursor_left(size.to_string().width() + unit.width()),
size, size,
unit, unit)
padding = padding as usize)
} }
} }
impl ListView<Files> where impl ListView<Files> where
@ -228,10 +231,8 @@ impl Widget for ListView<Files> {
fn get_drawlist(&self) -> String { fn get_drawlist(&self) -> String {
let mut output = term::reset(); let mut output = term::reset();
let (xsize, ysize) = self.coordinates.size().size(); let (xsize, ysize) = self.get_size().size();
let (xpos, ypos) = self.coordinates.position().position(); let (xpos, ypos) = self.coordinates.position().position();
output += &term::reset();
for (i, item) in self.buffer for (i, item) in self.buffer
.iter() .iter()
@ -253,8 +254,11 @@ impl Widget for ListView<Files> {
if ysize as usize > self.buffer.len() { if ysize as usize > self.buffer.len() {
let start_y = self.buffer.len() + 1 + ypos as usize; let start_y = self.buffer.len() + 1 + ypos as usize;
for i in start_y..ysize as usize { for i in start_y..(ysize+2) as usize {
output += &format!("{}{:xsize$}{}", term::gotoy(i), " ", xsize = xsize as usize); output += &format!("{}{:xsize$}",
term::goto_xy(xpos,i as u16),
" ",
xsize = xsize as usize);
} }
} }

View File

@ -45,20 +45,42 @@ pub fn sized_string(string: &str, xsize: u16) -> String {
pub fn highlight_color() -> String { pub fn highlight_color() -> String {
format!( format!(
"{}{}", "{}",
termion::color::Fg(termion::color::LightGreen), termion::color::Fg(termion::color::LightGreen),
termion::color::Bg(termion::color::Black) //termion::color::Bg(termion::color::Black)
) )
} }
pub fn normal_color() -> String { pub fn normal_color() -> String {
format!( format!(
"{}{}", "{}",
termion::color::Fg(termion::color::LightBlue), termion::color::Fg(termion::color::LightBlue),
termion::color::Bg(termion::color::Black) //termion::color::Bg(termion::color::Black)
) )
} }
pub fn from_lscolor(color: &lscolors::Color) -> String {
match color {
lscolors::Color::Black => {
format!("{}", termion::color::Fg(termion::color::Black)) },
lscolors::Color::Red => {
format!("{}", termion::color::Fg(termion::color::Red)) }
lscolors::Color::Green => {
format!("{}",termion::color::Fg(termion::color::Green)) }
lscolors::Color::Yellow => {
format!("{}",termion::color::Fg(termion::color::Yellow)) }
lscolors::Color::Blue => {
format!("{}",termion::color::Fg(termion::color::Blue)) }
lscolors::Color::Magenta => {
format!("{}", termion::color::Fg(termion::color::Magenta)) }
lscolors::Color::Cyan => {
format!("{}",termion::color::Fg(termion::color::Cyan)) }
lscolors::Color::White => {
format!("{}",termion::color::Fg(termion::color::White)) } ,
_ => { format!("{}", normal_color()) }
}
}
pub fn cursor_left(n: usize) -> String { pub fn cursor_left(n: usize) -> String {
format!("{}", termion::cursor::Left(n as u16)) format!("{}", termion::cursor::Left(n as u16))