feat: A configuration to hide the header
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
a3f7dade8a
commit
373fdab000
7 changed files with 48 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright (c) 2019-2022 golmman
|
// Copyright (c) 2019-2022 golmman
|
||||||
|
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||||
|
|
||||||
use crate::controller::EventQueue;
|
use crate::controller::EventQueue;
|
||||||
use crate::model::event::Key;
|
use crate::model::event::Key;
|
||||||
|
@ -32,7 +33,10 @@ impl<W: Write> EventQueue<W> {
|
||||||
self.pager.update(
|
self.pager.update(
|
||||||
cursor_delta,
|
cursor_delta,
|
||||||
&self.text_entries,
|
&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
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright (c) 2019-2022 golmman
|
// Copyright (c) 2019-2022 golmman
|
||||||
|
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||||
|
|
||||||
use crate::controller::key_event_handler::KeyEventHandler;
|
use crate::controller::key_event_handler::KeyEventHandler;
|
||||||
use crate::controller::resize_event_handler::ResizeEventHandler;
|
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>) =
|
let (queue_sender, queue_receiver): (SyncSender<Event>, Receiver<Event>) =
|
||||||
sync_channel(1024);
|
sync_channel(1024);
|
||||||
|
|
||||||
let path_node_compare = PathNode::get_path_node_compare(&config);
|
let path_node_compare = PathNode::get_path_node_compare(&config);
|
||||||
|
|
||||||
let text_entries = composer.compose_path_node(&path_node_root);
|
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;
|
let command_to_run_on_exit = None;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -89,7 +95,10 @@ impl<W: Write> EventQueue<W> {
|
||||||
self.pager.update(
|
self.pager.update(
|
||||||
0,
|
0,
|
||||||
&self.text_entries,
|
&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(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ impl Config {
|
||||||
"--keybinding.quit" => config.keybinding.quit = Self::parse_value((key, value)),
|
"--keybinding.quit" => config.keybinding.quit = Self::parse_value((key, value)),
|
||||||
"--keybinding.reload" => config.keybinding.reload = 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.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(),
|
"--help" | "--version" => print_help(),
|
||||||
"--" => break,
|
"--" => break,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright (c) 2019-2022 golmman
|
// Copyright (c) 2019-2022 golmman
|
||||||
|
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -7,12 +8,15 @@ use serde::Deserialize;
|
||||||
pub struct Setup {
|
pub struct Setup {
|
||||||
#[serde(default = "Setup::default_working_dir")]
|
#[serde(default = "Setup::default_working_dir")]
|
||||||
pub working_dir: String,
|
pub working_dir: String,
|
||||||
|
#[serde(default = "Setup::default_with_cwd_header")]
|
||||||
|
pub with_cwd_header: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Setup {
|
impl Default for Setup {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Setup {
|
Setup {
|
||||||
working_dir: Self::default_working_dir(),
|
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 {
|
fn default_working_dir() -> String {
|
||||||
String::from(".")
|
String::from(".")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_with_cwd_header() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,16 @@ impl<W: Write> Pager<W> {
|
||||||
.unwrap();
|
.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!(
|
write!(
|
||||||
self,
|
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),
|
Composer::truncate_string(text, self.terminal_cols as usize),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -216,7 +221,7 @@ mod tests {
|
||||||
fn print_footer_test() {
|
fn print_footer_test() {
|
||||||
let result = {
|
let result = {
|
||||||
let mut pager = prepare_pager();
|
let mut pager = prepare_pager();
|
||||||
pager.print_footer("--- test 123 ---");
|
pager.print_footer("--- test 123 ---", true);
|
||||||
get_result(pager)
|
get_result(pager)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
// Copyright (c) 2019-2022 golmman
|
// Copyright (c) 2019-2022 golmman
|
||||||
|
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||||
|
|
||||||
use crate::view::Pager;
|
use crate::view::Pager;
|
||||||
use std::io::Write;
|
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();
|
self.update_terminal_size();
|
||||||
|
|
||||||
let spacing_bot = self.config.debug.spacing_bot;
|
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);
|
let footer_text = format!("[{}/{}]", self.cursor_row + 1, text_entries_len);
|
||||||
|
|
||||||
self.print_header(&header_text);
|
if let Some(header_text) = header_text.as_ref() {
|
||||||
self.print_footer(&footer_text);
|
self.print_header(header_text);
|
||||||
|
}
|
||||||
|
self.print_footer(&footer_text, header_text.is_some());
|
||||||
|
|
||||||
self.print_debug_info();
|
self.print_debug_info();
|
||||||
|
|
||||||
|
|
|
@ -54,3 +54,5 @@ skip_down = "ctrl+down"
|
||||||
[setup]
|
[setup]
|
||||||
# the working directory used when starting
|
# the working directory used when starting
|
||||||
working_dir = "."
|
working_dir = "."
|
||||||
|
# when true the working directory is shown in the header
|
||||||
|
with_cwd_header = true
|
Loading…
Reference in a new issue