Skip to content

Commit aa83096

Browse files
author
Stephan Dilly
committed
file status indication and color for rename
1 parent 8f6a7bd commit aa83096

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

src/components/changes.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ impl ChangesComponent {
165165

166166
match &item.kind {
167167
FileTreeItemKind::File(status_item) => {
168+
let status_char =
169+
Self::item_status_char(&status_item.status);
168170
let file = Path::new(&status_item.path)
169171
.file_name()
170172
.unwrap()
@@ -173,28 +175,22 @@ impl ChangesComponent {
173175

174176
let txt = if selected {
175177
format!(
176-
"{}{:w$}",
178+
"{} {}{:w$}",
179+
status_char,
177180
indent_str,
178181
file,
179182
w = width as usize
180183
)
181184
} else {
182-
format!("{}{}", indent_str, file)
185+
format!("{} {}{}", status_char, indent_str, file) //M + - R
183186
};
184187

185-
let mut style = Style::default().fg(
186-
match status_item
187-
.status
188-
.unwrap_or(StatusItemType::Modified)
189-
{
190-
StatusItemType::Modified => {
191-
Color::LightYellow
192-
}
193-
StatusItemType::New => Color::LightGreen,
194-
StatusItemType::Deleted => Color::LightRed,
195-
_ => Color::White,
196-
},
197-
);
188+
let mut style =
189+
Style::default().fg(Self::item_color(
190+
status_item
191+
.status
192+
.unwrap_or(StatusItemType::Modified),
193+
));
198194

199195
if selected {
200196
style = style.bg(select_color);
@@ -209,15 +205,15 @@ impl ChangesComponent {
209205

210206
let txt = if selected {
211207
format!(
212-
"{}{}{:w$}",
208+
" {}{}{:w$}",
213209
indent_str,
214210
collapse_char,
215211
item.info.path,
216212
w = width as usize
217213
)
218214
} else {
219215
format!(
220-
"{}{}{}",
216+
" {}{}{}",
221217
indent_str, collapse_char, item.info.path,
222218
)
223219
};
@@ -232,6 +228,30 @@ impl ChangesComponent {
232228
}
233229
}
234230
}
231+
232+
fn item_color(item_type: StatusItemType) -> Color {
233+
match item_type {
234+
StatusItemType::Modified => Color::LightYellow,
235+
StatusItemType::New => Color::LightGreen,
236+
StatusItemType::Deleted => Color::LightRed,
237+
StatusItemType::Renamed => Color::LightMagenta,
238+
_ => Color::White,
239+
}
240+
}
241+
242+
fn item_status_char(item_type: &Option<StatusItemType>) -> char {
243+
if let Some(item_type) = item_type {
244+
match item_type {
245+
StatusItemType::Modified => 'M',
246+
StatusItemType::New => '+',
247+
StatusItemType::Deleted => '-',
248+
StatusItemType::Renamed => 'R',
249+
_ => ' ',
250+
}
251+
} else {
252+
' '
253+
}
254+
}
235255
}
236256

237257
impl DrawableComponent for ChangesComponent {

0 commit comments

Comments
 (0)