file status indication and color for rename

This commit is contained in:
Stephan Dilly 2020-05-02 11:58:48 +02:00
parent 8f6a7bd330
commit aa830963d4

View file

@ -165,6 +165,8 @@ impl ChangesComponent {
match &item.kind { match &item.kind {
FileTreeItemKind::File(status_item) => { FileTreeItemKind::File(status_item) => {
let status_char =
Self::item_status_char(&status_item.status);
let file = Path::new(&status_item.path) let file = Path::new(&status_item.path)
.file_name() .file_name()
.unwrap() .unwrap()
@ -173,28 +175,22 @@ impl ChangesComponent {
let txt = if selected { let txt = if selected {
format!( format!(
"{}{:w$}", "{} {}{:w$}",
status_char,
indent_str, indent_str,
file, file,
w = width as usize w = width as usize
) )
} else { } else {
format!("{}{}", indent_str, file) format!("{} {}{}", status_char, indent_str, file) //M + - R
}; };
let mut style = Style::default().fg( let mut style =
match status_item Style::default().fg(Self::item_color(
.status status_item
.unwrap_or(StatusItemType::Modified) .status
{ .unwrap_or(StatusItemType::Modified),
StatusItemType::Modified => { ));
Color::LightYellow
}
StatusItemType::New => Color::LightGreen,
StatusItemType::Deleted => Color::LightRed,
_ => Color::White,
},
);
if selected { if selected {
style = style.bg(select_color); style = style.bg(select_color);
@ -209,7 +205,7 @@ impl ChangesComponent {
let txt = if selected { let txt = if selected {
format!( format!(
"{}{}{:w$}", " {}{}{:w$}",
indent_str, indent_str,
collapse_char, collapse_char,
item.info.path, item.info.path,
@ -217,7 +213,7 @@ impl ChangesComponent {
) )
} else { } else {
format!( format!(
"{}{}{}", " {}{}{}",
indent_str, collapse_char, item.info.path, indent_str, collapse_char, item.info.path,
) )
}; };
@ -232,6 +228,30 @@ impl ChangesComponent {
} }
} }
} }
fn item_color(item_type: StatusItemType) -> Color {
match item_type {
StatusItemType::Modified => Color::LightYellow,
StatusItemType::New => Color::LightGreen,
StatusItemType::Deleted => Color::LightRed,
StatusItemType::Renamed => Color::LightMagenta,
_ => Color::White,
}
}
fn item_status_char(item_type: &Option<StatusItemType>) -> char {
if let Some(item_type) = item_type {
match item_type {
StatusItemType::Modified => 'M',
StatusItemType::New => '+',
StatusItemType::Deleted => '-',
StatusItemType::Renamed => 'R',
_ => ' ',
}
} else {
' '
}
}
} }
impl DrawableComponent for ChangesComponent { impl DrawableComponent for ChangesComponent {