summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-04-18 08:25:44 +0200
committerCanop <cano.petrole@gmail.com>2021-04-18 08:25:44 +0200
commit1ba47dac5f39f71c708c6ed1b2a1add83ed3587c (patch)
treeacdd05e5b0d0c39787ad499e6e1458a192c1a7c3 /src/display
parent2f4027ce1741098147b70e5de4d853d3ae8a86be (diff)
display what files are staged on tree
Diffstat (limited to 'src/display')
-rw-r--r--src/display/col.rs17
-rw-r--r--src/display/displayable_tree.rs53
2 files changed, 61 insertions, 9 deletions
diff --git a/src/display/col.rs b/src/display/col.rs
index 270a2f2..5844763 100644
--- a/src/display/col.rs
+++ b/src/display/col.rs
@@ -1,5 +1,6 @@
use {
crate::{
+ app::AppState,
errors::ConfError,
tree::Tree,
},
@@ -11,7 +12,7 @@ use {
};
// number of columns in enum
-const COLS_COUNT: usize = 8;
+const COLS_COUNT: usize = 9;
/// One of the "columns" of the tree view
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -37,6 +38,9 @@ pub enum Col {
/// number of files in the directory
Count,
+ /// marks whether the path is staged (not used for now, may be removed)
+ Staged,
+
/// name of the file, or subpath if relevant due to filtering mode
Name,
}
@@ -61,6 +65,7 @@ pub static DEFAULT_COLS: Cols = [
Col::Permission,
Col::Count,
Col::Branch,
+ Col::Staged,
Col::Name,
];
@@ -76,6 +81,7 @@ impl FromStr for Col {
"d" | "date" => Ok(Self::Date),
"s" | "size" => Ok(Self::Size),
"c" | "count" => Ok(Self::Count),
+ "staged" => Ok(Self::Staged),
"n" | "name" => Ok(Self::Name),
_ => Err(ConfError::InvalidCols {
details: format!("column not recognized : {}", s),
@@ -104,10 +110,15 @@ impl Col {
Col::Permission => true,
Col::Count => false,
Col::Branch => false,
+ Col::Staged => false,
Col::Name => false,
}
}
- pub fn is_visible(self, tree: &Tree) -> bool {
+ pub fn is_visible(
+ self,
+ tree: &Tree,
+ app_state: Option<&AppState>,
+ ) -> bool {
let tree_options = &tree.options;
match self {
Col::Mark => tree_options.show_selection_mark,
@@ -117,6 +128,8 @@ impl Col {
Col::Permission => tree_options.show_permissions,
Col::Count => tree_options.show_counts,
Col::Branch => true,
+ //Col::Staged => app_state.map_or(false, |a| !a.stage.is_empty()),
+ Col::Staged => false,
Col::Name => true,
}
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs
index ed4eb70..906a878 100644
--- a/src/display/displayable_tree.rs
+++ b/src/display/displayable_tree.rs
@@ -7,6 +7,7 @@ use {
MatchedString,
},
crate::{
+ app::AppState,
content_search::ContentMatch,
errors::ProgramError,
file_sum::FileSum,
@@ -33,7 +34,8 @@ use {
/// - the selection is drawn
/// - a scrollbar may be drawn
/// - the empty lines will be erased
-pub struct DisplayableTree<'s, 't> {
+pub struct DisplayableTree<'a, 's, 't> {
+ pub app_state: Option<&'a AppState>,
pub tree: &'t Tree,
pub skin: &'s StyleMap,
pub area: termimad::Area,
@@ -41,7 +43,7 @@ pub struct DisplayableTree<'s, 't> {
pub ext_colors: &'s ExtColorMap,
}
-impl<'s, 't> DisplayableTree<'s, 't> {
+impl<'a, 's, 't> DisplayableTree<'a, 's, 't> {
pub fn out_of_app(
tree: &'t Tree,
@@ -49,8 +51,9 @@ impl<'s, 't> DisplayableTree<'s, 't> {
ext_colors: &'s ExtColorMap,
width: u16,
height: u16,
- ) -> DisplayableTree<'s, 't> {
+ ) -> DisplayableTree<'a, 's, 't> {
DisplayableTree {
+ app_state: None,
tree,
skin,
ext_colors,
@@ -216,6 +219,7 @@ impl<'s, 't> DisplayableTree<'s, 't> {
line_index: usize,
line: &TreeLine,
selected: bool,
+ staged: bool,
) -> Result<usize, ProgramError> {
cond_bg!(branch_style, self, selected, self.skin.tree);
let mut branch = String::new();
@@ -225,12 +229,20 @@ impl<'s, 't> DisplayableTree<'s, 't> {
if self.tree.has_branch(line_index + 1, depth as usize) {
// TODO: If a theme is on, remove the horizontal lines
if depth == line.depth - 1 {
- "├──"
+ if staged {
+ "├◍─"
+ } else {
+ "├──"
+ }
} else {
"│ "
}
} else {
- "└──"
+ if staged {
+ "└◍─"
+ } else {
+ "└──"
+ }
}
} else {
" "
@@ -243,6 +255,21 @@ impl<'s, 't> DisplayableTree<'s, 't> {
Ok(0)
}
+ /// write the symbol showing whether the path is staged
+ fn write_line_stage_mark<'w, W: Write>(
+ &self,
+ cw: &mut CropWriter<'w, W>,
+ style: &CompoundStyle,
+ staged: bool,
+ ) -> Result<usize, termimad::Error> {
+ Ok(if staged {
+ cw.queue_char(&style, '◍')?; // ▣
+ 0
+ } else {
+ 1
+ })
+ }
+
/// write the name or subpath, depending on the pattern_object
fn write_line_label<'w, W: Write>(
&self,
@@ -397,7 +424,13 @@ impl<'s, 't> DisplayableTree<'s, 't> {
self.write_root_line(&mut cw, self.in_app && tree.selection == 0)?;
self.skin.queue_reset(f)?;
- let visible_cols = tree.visible_cols();
+ let visible_cols: Vec<Col> = tree
+ .options
+ .cols_order
+ .iter()
+ .filter(|col| col.is_visible(&tree, self.app_state))
+ .cloned()
+ .collect();
// if necessary we compute the width of the count column
let count_len = if tree.options.show_counts {
@@ -445,6 +478,8 @@ impl<'s, 't> DisplayableTree<'s, 't> {
if visible_cols[0].needs_left_margin() {
cw.queue_char(space_style, ' ')?;
}
+ let staged = self.app_state
+ .map_or(false, |a| a.stage.paths.contains(&line.path));
for col in &visible_cols {
let void_len = match col {
@@ -458,7 +493,7 @@ impl<'s, 't> DisplayableTree<'s, 't> {
Col::Branch => {
in_branch = true;
- self.write_branch(cw, line_index, line, selected)?
+ self.write_branch(cw, line_index, line, selected, staged)?
}
Col::Permission => {
@@ -490,6 +525,10 @@ impl<'s, 't> DisplayableTree<'s, 't> {
self.write_line_count(cw, line, count_len, selected)?
}
+ Col::Staged => {
+ self.write_line_stage_mark(cw, &label_style, staged)?
+ }
+
Col::Name => {
in_branch = false;
self.write_line_label(cw, line, &label_style, pattern_object, selected)?