feat(ui): make help bar display optional (#35)

This commit is contained in:
Alexandre Pasmantier 2024-11-16 20:32:40 +01:00 committed by GitHub
parent 7277a3f3ab
commit 512afa2fda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 70 additions and 34 deletions

View File

@ -23,6 +23,8 @@ use_nerd_font_icons = false
# │ │ # │ │
# └───────────────────────────────────────┘ # └───────────────────────────────────────┘
ui_scale = 80 ui_scale = 80
# Whether to show the top help bar in the UI
show_help_bar = true
# Previewers settings # Previewers settings
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------

2
Cargo.lock generated
View File

@ -2963,7 +2963,7 @@ dependencies = [
[[package]] [[package]]
name = "television" name = "television"
version = "0.4.22" version = "0.4.23"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"better-panic", "better-panic",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "television" name = "television"
version = "0.4.22" version = "0.4.23"
edition = "2021" edition = "2021"
description = "The revolution will be televised." description = "The revolution will be televised."
license = "MIT" license = "MIT"

View File

@ -8,6 +8,7 @@ const DEFAULT_UI_SCALE: u16 = 90;
pub struct UiConfig { pub struct UiConfig {
pub use_nerd_font_icons: bool, pub use_nerd_font_icons: bool,
pub ui_scale: u16, pub ui_scale: u16,
pub show_help_bar: bool,
} }
impl Default for UiConfig { impl Default for UiConfig {
@ -15,6 +16,7 @@ impl Default for UiConfig {
Self { Self {
use_nerd_font_icons: false, use_nerd_font_icons: false,
ui_scale: DEFAULT_UI_SCALE, ui_scale: DEFAULT_UI_SCALE,
show_help_bar: true,
} }
} }
} }
@ -30,6 +32,10 @@ impl From<UiConfig> for ValueKind {
String::from("ui_scale"), String::from("ui_scale"),
ValueKind::U64(val.ui_scale.into()).into(), ValueKind::U64(val.ui_scale.into()).into(),
); );
m.insert(
String::from("show_help_bar"),
ValueKind::Boolean(val.show_help_bar).into(),
);
ValueKind::Table(m) ValueKind::Table(m)
} }
} }

View File

@ -378,6 +378,7 @@ impl Television {
&Dimensions::from(self.config.ui.ui_scale), &Dimensions::from(self.config.ui.ui_scale),
area, area,
!matches!(self.mode, Mode::Channel), !matches!(self.mode, Mode::Channel),
self.config.ui.show_help_bar,
); );
// help bar (metadata, keymaps, logo) // help bar (metadata, keymaps, logo)

View File

@ -26,9 +26,11 @@ impl Television {
f: &mut Frame, f: &mut Frame,
layout: &Layout, layout: &Layout,
) -> color_eyre::Result<()> { ) -> color_eyre::Result<()> {
self.draw_metadata_block(f, layout.help_bar_left); if let Some(help_bar) = layout.help_bar {
self.draw_keymaps_block(f, layout.help_bar_middle)?; self.draw_metadata_block(f, help_bar.left);
draw_logo_block(f, layout.help_bar_right, mode_color(self.mode)); self.draw_keymaps_block(f, help_bar.middle)?;
draw_logo_block(f, help_bar.right, mode_color(self.mode));
}
Ok(()) Ok(())
} }

View File

@ -24,10 +24,25 @@ impl Default for Dimensions {
} }
} }
#[derive(Debug, Clone, Copy)]
pub struct HelpBarLayout {
pub left: Rect,
pub middle: Rect,
pub right: Rect,
}
impl HelpBarLayout {
pub fn new(left: Rect, middle: Rect, right: Rect) -> Self {
Self {
left,
middle,
right,
}
}
}
pub struct Layout { pub struct Layout {
pub help_bar_left: Rect, pub help_bar: Option<HelpBarLayout>,
pub help_bar_middle: Rect,
pub help_bar_right: Rect,
pub results: Rect, pub results: Rect,
pub input: Rect, pub input: Rect,
pub preview_title: Rect, pub preview_title: Rect,
@ -38,9 +53,7 @@ pub struct Layout {
impl Layout { impl Layout {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
help_bar_left: Rect, help_bar: Option<HelpBarLayout>,
help_bar_middle: Rect,
help_bar_right: Rect,
results: Rect, results: Rect,
input: Rect, input: Rect,
preview_title: Rect, preview_title: Rect,
@ -48,9 +61,7 @@ impl Layout {
remote_control: Option<Rect>, remote_control: Option<Rect>,
) -> Self { ) -> Self {
Self { Self {
help_bar_left, help_bar,
help_bar_middle,
help_bar_right,
results, results,
input, input,
preview_title, preview_title,
@ -63,26 +74,42 @@ impl Layout {
dimensions: &Dimensions, dimensions: &Dimensions,
area: Rect, area: Rect,
with_remote: bool, with_remote: bool,
with_help_bar: bool,
) -> Self { ) -> Self {
let main_block = centered_rect(dimensions.x, dimensions.y, area); let main_block = centered_rect(dimensions.x, dimensions.y, area);
// split the main block into two vertical chunks (help bar + rest) // split the main block into two vertical chunks (help bar + rest)
let hz_chunks = layout::Layout::default() let main_rect: Rect;
.direction(Direction::Vertical) let help_bar_layout: Option<HelpBarLayout>;
.constraints([Constraint::Max(9), Constraint::Fill(1)])
.split(main_block);
// split the help bar into three horizontal chunks (left + center + right) if with_help_bar {
let help_bar_chunks = layout::Layout::default() let hz_chunks = layout::Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Vertical)
.constraints([ .constraints([Constraint::Max(9), Constraint::Fill(1)])
// metadata .split(main_block);
Constraint::Fill(1), main_rect = hz_chunks[1];
// keymaps
Constraint::Fill(1), // split the help bar into three horizontal chunks (left + center + right)
// logo let help_bar_chunks = layout::Layout::default()
Constraint::Length(24), .direction(Direction::Horizontal)
]) .constraints([
.split(hz_chunks[0]); // metadata
Constraint::Fill(1),
// keymaps
Constraint::Fill(1),
// logo
Constraint::Length(24),
])
.split(hz_chunks[0]);
help_bar_layout = Some(HelpBarLayout {
left: help_bar_chunks[0],
middle: help_bar_chunks[1],
right: help_bar_chunks[2],
});
} else {
main_rect = main_block;
help_bar_layout = None;
}
// split the main block into two vertical chunks // split the main block into two vertical chunks
let constraints = if with_remote { let constraints = if with_remote {
@ -97,7 +124,7 @@ impl Layout {
let vt_chunks = layout::Layout::default() let vt_chunks = layout::Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints(constraints) .constraints(constraints)
.split(hz_chunks[1]); .split(main_rect);
// left block: results + input field // left block: results + input field
let left_chunks = layout::Layout::default() let left_chunks = layout::Layout::default()
@ -112,9 +139,7 @@ impl Layout {
.split(vt_chunks[1]); .split(vt_chunks[1]);
Self::new( Self::new(
help_bar_chunks[0], help_bar_layout,
help_bar_chunks[1],
help_bar_chunks[2],
left_chunks[0], left_chunks[0],
left_chunks[1], left_chunks[1],
right_chunks[0], right_chunks[0],