summaryrefslogtreecommitdiffstats
path: root/src/stage
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-04-20 16:04:28 +0200
committerCanop <cano.petrole@gmail.com>2021-04-20 16:04:28 +0200
commit3b6f4fecbe1abcc095f458a18deb63d30c60e9d9 (patch)
treecb81d680e94d3ffd72a43a6674354cce69047835 /src/stage
parent87db0b89a7975216f6810392945a0e57548406e0 (diff)
staging area: display filtered count / count
Diffstat (limited to 'src/stage')
-rw-r--r--src/stage/stage_state.rs45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/stage/stage_state.rs b/src/stage/stage_state.rs
index 87abbc9..dc7fe43 100644
--- a/src/stage/stage_state.rs
+++ b/src/stage/stage_state.rs
@@ -6,6 +6,7 @@ use {
display::{CropWriter, Screen, SPACE_FILLING, W},
errors::ProgramError,
pattern::*,
+ skin::*,
tree::*,
verb::*,
},
@@ -17,6 +18,8 @@ use {
termimad::Area,
};
+const TITLE: &str = "Staging Area"; // no wide char allowed here
+
pub struct StageState {
filtered_stage: FilteredStage,
@@ -46,6 +49,45 @@ impl StageState {
mode: initial_mode(con),
}
}
+
+ fn write_title_line(
+ &self,
+ stage: &Stage,
+ cw: &mut CropWriter<'_, W>,
+ styles: &StyleMap,
+ ) -> Result<(), ProgramError> {
+ let total_count = format!("{}", stage.len());
+ let mut count_len = total_count.len();
+ if self.filtered_stage.pattern().is_some() {
+ count_len += total_count.len() + 1; // 1 for '/'
+ }
+ if cw.allowed < count_len {
+ return Ok(());
+ }
+ if TITLE.len() + 1 + count_len <= cw.allowed {
+ cw.queue_str(
+ &styles.staging_area_title,
+ TITLE,
+ )?;
+ }
+ cw.repeat(&styles.staging_area_title, &SPACE_FILLING, cw.allowed - count_len)?;
+ if self.filtered_stage.pattern().is_some() {
+ cw.queue_g_string(
+ &styles.char_match,
+ format!("{}", self.filtered_stage.len()),
+ )?;
+ cw.queue_char(
+ &styles.staging_area_title,
+ '/',
+ )?;
+ }
+ cw.queue_g_string(
+ &styles.staging_area_title,
+ total_count,
+ )?;
+ cw.fill(&styles.staging_area_title, &SPACE_FILLING)?;
+ Ok(())
+ }
}
impl PanelState for StageState {
@@ -132,8 +174,7 @@ impl PanelState for StageState {
let width = area.width as usize;
w.queue(cursor::MoveTo(area.left, 0))?;
let mut cw = CropWriter::new(w, width);
- cw.queue_str(&styles.staging_area_title, "Staging Area")?;
- cw.fill(&styles.staging_area_title, &SPACE_FILLING)?;
+ self.write_title_line(stage, &mut cw, styles)?;
let list_area = Area::new(area.left, area.top + 1, area.width, area.height - 1);
let list_height = list_area.height as usize;
for idx in 0..list_height {