summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-05-01 12:57:19 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-05-01 12:57:19 -0400
commit171bcbc8565f29696b7a62e96430bf46abfe7217 (patch)
treefa073d179e5c6a1ca64a89109960eac24a0bfdb2 /src/ui
parent4409199315c5cc22bfba6cc63052a49dbdddfeb1 (diff)
move theming out of entry and into utils
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/widgets/tui_dirlist.rs35
-rw-r--r--src/ui/widgets/tui_dirlist_detailed.rs35
2 files changed, 34 insertions, 36 deletions
diff --git a/src/ui/widgets/tui_dirlist.rs b/src/ui/widgets/tui_dirlist.rs
index 2618d97..77e9d82 100644
--- a/src/ui/widgets/tui_dirlist.rs
+++ b/src/ui/widgets/tui_dirlist.rs
@@ -5,6 +5,7 @@ use tui::widgets::Widget;
use unicode_width::UnicodeWidthStr;
use crate::fs::{FileType, JoshutoDirEntry, JoshutoDirList};
+use crate::util::style;
const ELLIPSIS: &str = "…";
@@ -46,28 +47,26 @@ impl<'a> Widget for TuiDirList<'a> {
.enumerate()
.take(area.height as usize)
.for_each(|(i, entry)| {
- let style = entry.get_style();
+ let style = style::entry_style(entry);
print_entry(buf, entry, style, (x + 1, y + i as u16), drawing_width - 1);
});
- {
- let screen_index = curr_index % area.height as usize;
+ // draw selected entry in a different style
+ let screen_index = curr_index % area.height as usize;
- let entry = self.dirlist.curr_entry_ref().unwrap();
- let style = {
- let s = entry.get_style().add_modifier(Modifier::REVERSED);
- let space_fill = " ".repeat(drawing_width);
- buf.set_string(x, y + screen_index as u16, space_fill.as_str(), s);
- s
- };
- print_entry(
- buf,
- entry,
- style,
- (x + 1, y + screen_index as u16),
- drawing_width - 1,
- );
- }
+ let entry = self.dirlist.curr_entry_ref().unwrap();
+ let style = style::entry_style(entry).add_modifier(Modifier::REVERSED);
+
+ let space_fill = " ".repeat(drawing_width);
+ buf.set_string(x, y + screen_index as u16, space_fill.as_str(), style);
+
+ print_entry(
+ buf,
+ entry,
+ style,
+ (x + 1, y + screen_index as u16),
+ drawing_width - 1,
+ );
}
}
diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs
index 242b992..bdbf2b7 100644
--- a/src/ui/widgets/tui_dirlist_detailed.rs
+++ b/src/ui/widgets/tui_dirlist_detailed.rs
@@ -6,6 +6,7 @@ use unicode_width::UnicodeWidthStr;
use crate::fs::{FileType, JoshutoDirEntry, JoshutoDirList};
use crate::util::format;
+use crate::util::style;
const FILE_SIZE_WIDTH: usize = 8;
@@ -48,28 +49,26 @@ impl<'a> Widget for TuiDirListDetailed<'a> {
.enumerate()
.take(area.height as usize)
.for_each(|(i, entry)| {
- let style = entry.get_style();
+ let style = style::entry_style(entry);
print_entry(buf, entry, style, (x + 1, y + i as u16), drawing_width - 1);
});
- {
- let screen_index = curr_index % area.height as usize;
+ // draw selected entry in a different style
+ let screen_index = curr_index % area.height as usize;
- let entry = self.dirlist.curr_entry_ref().unwrap();
- let style = {
- let s = entry.get_style().add_modifier(Modifier::REVERSED);
- let space_fill = " ".repeat(drawing_width);
- buf.set_string(x, y + screen_index as u16, space_fill.as_str(), s);
- s
- };
- print_entry(
- buf,
- entry,
- style,
- (x + 1, y + screen_index as u16),
- drawing_width - 1,
- );
- }
+ let entry = self.dirlist.curr_entry_ref().unwrap();
+ let style = style::entry_style(entry).add_modifier(Modifier::REVERSED);
+
+ let space_fill = " ".repeat(drawing_width);
+ buf.set_string(x, y + screen_index as u16, space_fill.as_str(), style);
+
+ print_entry(
+ buf,
+ entry,
+ style,
+ (x + 1, y + screen_index as u16),
+ drawing_width - 1,
+ );
}
}