feat(cli): add custom header for input field (#472)

#362 

Add a custom header and the cli flag for the input field.

Maybe I should replace channel name with header name in the draw method
instead of checking in the draw loop whether the header is there or
not...

Co-authored-by: Alexandre Pasmantier <47638216+alexpasmantier@users.noreply.github.com>
This commit is contained in:
nkxxll 2025-04-20 21:20:14 +02:00 committed by GitHub
parent a938c1c469
commit 0bd4d4274e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 1 deletions

View File

@ -74,6 +74,14 @@ pub struct Cli {
#[arg(short, long, value_name = "STRING", verbatim_doc_comment)]
pub input: Option<String>,
/// Input fields header title
///
/// This can be used to give the input field a custom title e.g. the current
/// working directory.
/// The default value for the input header is the current channel.
#[arg(long, value_name = "STRING", verbatim_doc_comment)]
pub custom_header: Option<String>,
/// The working directory to start the application in.
///
/// This can be used to specify a different working directory for the

View File

@ -26,6 +26,7 @@ pub struct PostProcessedCli {
pub tick_rate: Option<f64>,
pub frame_rate: Option<f64>,
pub input: Option<String>,
pub custom_header: Option<String>,
pub command: Option<Command>,
pub working_directory: Option<String>,
pub autocomplete_prompt: Option<String>,
@ -44,6 +45,7 @@ impl Default for PostProcessedCli {
tick_rate: None,
frame_rate: None,
input: None,
custom_header: None,
command: None,
working_directory: None,
autocomplete_prompt: None,
@ -111,6 +113,7 @@ impl From<Cli> for PostProcessedCli {
tick_rate: cli.tick_rate,
frame_rate: cli.frame_rate,
input: cli.input,
custom_header: cli.custom_header,
command: cli.command,
working_directory,
autocomplete_prompt: cli.autocomplete_prompt,

View File

@ -17,6 +17,7 @@ pub struct UiConfig {
pub input_bar_position: InputPosition,
pub preview_title_position: Option<PreviewTitlePosition>,
pub theme: String,
pub custom_header: Option<String>,
}
impl Default for UiConfig {
@ -29,6 +30,7 @@ impl Default for UiConfig {
input_bar_position: InputPosition::Top,
preview_title_position: None,
theme: String::from(DEFAULT_THEME),
custom_header: None,
}
}
}

View File

@ -239,6 +239,7 @@ pub fn draw(ctx: &Ctx, f: &mut Frame<'_>, area: Rect) -> Result<Layout> {
&ctx.tv_state.channel_state.current_channel_name,
&ctx.tv_state.spinner,
&ctx.colorscheme,
&ctx.config.ui.custom_header,
)?;
if layout.preview_window.is_some() {

View File

@ -101,6 +101,9 @@ fn apply_cli_overrides(args: &PostProcessedCli, config: &mut Config) {
config.keybindings =
merge_keybindings(config.keybindings.clone(), keybindings);
}
if let Some(header) = &args.custom_header {
config.ui.custom_header = Some(header.to_string());
}
}
pub fn set_current_dir(path: &String) -> Result<()> {

View File

@ -24,13 +24,15 @@ pub fn draw_input_box(
channel_name: &str,
spinner: &Spinner,
colorscheme: &Colorscheme,
custom_header: &Option<String>,
) -> Result<()> {
let header = custom_header.as_deref().unwrap_or(channel_name);
let input_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(colorscheme.general.border_fg))
.title_top(
Line::from(String::from(" ") + channel_name + " ")
Line::from(String::from(" ") + header + " ")
.style(Style::default().fg(colorscheme.mode.channel).bold())
.centered(),
)