feat: A configuration to hide the header #1
7 changed files with 48 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2019-2022 golmman
|
||||
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||
|
||||
use crate::controller::EventQueue;
|
||||
use crate::model::event::Key;
|
||||
|
@ -32,7 +33,10 @@ impl<W: Write> EventQueue<W> {
|
|||
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()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2019-2022 golmman
|
||||
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||
|
||||
use crate::controller::key_event_handler::KeyEventHandler;
|
||||
use crate::controller::resize_event_handler::ResizeEventHandler;
|
||||
|
@ -45,11 +46,16 @@ impl<W: Write> EventQueue<W> {
|
|||
|
||||
let (queue_sender, queue_receiver): (SyncSender<Event>, Receiver<Event>) =
|
||||
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<W: Write> EventQueue<W> {
|
|||
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(())
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2019-2022 golmman
|
||||
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,11 +45,16 @@ impl<W: Write> Pager<W> {
|
|||
.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)
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2019-2022 golmman
|
||||
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||
|
||||
use crate::view::Pager;
|
||||
use std::io::Write;
|
||||
|
@ -22,7 +23,12 @@ impl<W: Write> Pager<W> {
|
|||
}
|
||||
}
|
||||
|
||||
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<String>,
|
||||
) {
|
||||
self.update_terminal_size();
|
||||
|
||||
let spacing_bot = self.config.debug.spacing_bot;
|
||||
|
@ -62,8 +68,10 @@ impl<W: Write> Pager<W> {
|
|||
|
||||
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();
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue