From 373fdab0009783a248e551ccd4c2eb9b03dc22f7 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Sun, 22 Dec 2024 21:30:14 +0000 Subject: [PATCH] feat: A configuration to hide the header Signed-off-by: Awiteb --- src/controller/key_event_matcher/mod.rs | 6 +++++- src/controller/mod.rs | 17 +++++++++++++---- src/model/config/mod.rs | 1 + src/model/config/setup.rs | 8 ++++++++ src/view/print.rs | 11 ++++++++--- src/view/update.rs | 14 +++++++++++--- twilight-tree.toml | 2 ++ 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/controller/key_event_matcher/mod.rs b/src/controller/key_event_matcher/mod.rs index 0c887e0..4892ea8 100644 --- a/src/controller/key_event_matcher/mod.rs +++ b/src/controller/key_event_matcher/mod.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2019-2022 golmman +// Copyright (c) 2024 Awiteb use crate::controller::EventQueue; use crate::model::event::Key; @@ -32,7 +33,10 @@ impl EventQueue { self.pager.update( cursor_delta, &self.text_entries, - self.path_node_root.get_absolute_path(), + self.config + .setup + .with_cwd_header + .then_some(self.path_node_root.get_absolute_path()), ); } } diff --git a/src/controller/mod.rs b/src/controller/mod.rs index a551025..29cb165 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2019-2022 golmman +// Copyright (c) 2024 Awiteb use crate::controller::key_event_handler::KeyEventHandler; use crate::controller::resize_event_handler::ResizeEventHandler; @@ -45,11 +46,16 @@ impl EventQueue { let (queue_sender, queue_receiver): (SyncSender, Receiver) = sync_channel(1024); - let path_node_compare = PathNode::get_path_node_compare(&config); - let text_entries = composer.compose_path_node(&path_node_root); - pager.update(0, &text_entries, path_node_root.get_absolute_path()); + pager.update( + 0, + &text_entries, + config + .setup + .with_cwd_header + .then_some(path_node_root.get_absolute_path()), + ); let command_to_run_on_exit = None; Self { @@ -89,7 +95,10 @@ impl EventQueue { self.pager.update( 0, &self.text_entries, - self.path_node_root.get_absolute_path(), + self.config + .setup + .with_cwd_header + .then_some(self.path_node_root.get_absolute_path()), ); Some(()) } diff --git a/src/model/config/mod.rs b/src/model/config/mod.rs index 0ed014e..8ff86dc 100644 --- a/src/model/config/mod.rs +++ b/src/model/config/mod.rs @@ -83,6 +83,7 @@ impl Config { "--keybinding.quit" => config.keybinding.quit = Self::parse_value((key, value)), "--keybinding.reload" => config.keybinding.reload = Self::parse_value((key, value)), "--setup.working_dir" => config.setup.working_dir = Self::parse_value((key, value)), + "--setup.with_cwd_header" => config.setup.with_cwd_header = Self::parse_value((key, value)), "--help" | "--version" => print_help(), "--" => break, diff --git a/src/model/config/setup.rs b/src/model/config/setup.rs index d12a150..1353924 100644 --- a/src/model/config/setup.rs +++ b/src/model/config/setup.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2019-2022 golmman +// Copyright (c) 2024 Awiteb use serde::Deserialize; @@ -7,12 +8,15 @@ use serde::Deserialize; pub struct Setup { #[serde(default = "Setup::default_working_dir")] pub working_dir: String, + #[serde(default = "Setup::default_with_cwd_header")] + pub with_cwd_header: bool, } impl Default for Setup { fn default() -> Self { Setup { working_dir: Self::default_working_dir(), + with_cwd_header: Self::default_with_cwd_header(), } } } @@ -21,4 +25,8 @@ impl Setup { fn default_working_dir() -> String { String::from(".") } + + fn default_with_cwd_header() -> bool { + true + } } diff --git a/src/view/print.rs b/src/view/print.rs index c6ccf71..4feaa1c 100644 --- a/src/view/print.rs +++ b/src/view/print.rs @@ -45,11 +45,16 @@ impl Pager { .unwrap(); } - pub fn print_footer(&mut self, text: &str) { + pub fn print_footer(&mut self, text: &str, there_is_header: bool) { + let goto_end = if there_is_header { + 1 + self.terminal_rows as u16 + } else { + 1 + }; write!( self, "{}{}", - termion::cursor::Goto(1, 1 + self.terminal_rows as u16), + termion::cursor::Goto(1, goto_end), Composer::truncate_string(text, self.terminal_cols as usize), ) .unwrap(); @@ -216,7 +221,7 @@ mod tests { fn print_footer_test() { let result = { let mut pager = prepare_pager(); - pager.print_footer("--- test 123 ---"); + pager.print_footer("--- test 123 ---", true); get_result(pager) }; diff --git a/src/view/update.rs b/src/view/update.rs index c5718f9..1933e53 100644 --- a/src/view/update.rs +++ b/src/view/update.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2019-2022 golmman +// Copyright (c) 2024 Awiteb use crate::view::Pager; use std::io::Write; @@ -22,7 +23,12 @@ impl Pager { } } - pub fn update(&mut self, cursor_row_delta: i32, text_entries: &[String], header_text: String) { + pub fn update( + &mut self, + cursor_row_delta: i32, + text_entries: &[String], + header_text: Option, + ) { self.update_terminal_size(); let spacing_bot = self.config.debug.spacing_bot; @@ -62,8 +68,10 @@ impl Pager { let footer_text = format!("[{}/{}]", self.cursor_row + 1, text_entries_len); - self.print_header(&header_text); - self.print_footer(&footer_text); + if let Some(header_text) = header_text.as_ref() { + self.print_header(header_text); + } + self.print_footer(&footer_text, header_text.is_some()); self.print_debug_info(); diff --git a/twilight-tree.toml b/twilight-tree.toml index db913f6..d896238 100644 --- a/twilight-tree.toml +++ b/twilight-tree.toml @@ -54,3 +54,5 @@ skip_down = "ctrl+down" [setup] # the working directory used when starting working_dir = "." +# when true the working directory is shown in the header +with_cwd_header = true \ No newline at end of file