mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 19:45:23 +00:00
feat: add custom header for input field
This commit is contained in:
parent
2be2ae7cde
commit
e757b23a25
@ -74,6 +74,14 @@ pub struct Cli {
|
|||||||
#[arg(short, long, value_name = "STRING", verbatim_doc_comment)]
|
#[arg(short, long, value_name = "STRING", verbatim_doc_comment)]
|
||||||
pub input: Option<String>,
|
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.
|
/// The working directory to start the application in.
|
||||||
///
|
///
|
||||||
/// This can be used to specify a different working directory for the
|
/// This can be used to specify a different working directory for the
|
||||||
|
@ -26,6 +26,7 @@ pub struct PostProcessedCli {
|
|||||||
pub tick_rate: Option<f64>,
|
pub tick_rate: Option<f64>,
|
||||||
pub frame_rate: Option<f64>,
|
pub frame_rate: Option<f64>,
|
||||||
pub input: Option<String>,
|
pub input: Option<String>,
|
||||||
|
pub custom_header: Option<String>,
|
||||||
pub command: Option<Command>,
|
pub command: Option<Command>,
|
||||||
pub working_directory: Option<String>,
|
pub working_directory: Option<String>,
|
||||||
pub autocomplete_prompt: Option<String>,
|
pub autocomplete_prompt: Option<String>,
|
||||||
@ -44,6 +45,7 @@ impl Default for PostProcessedCli {
|
|||||||
tick_rate: None,
|
tick_rate: None,
|
||||||
frame_rate: None,
|
frame_rate: None,
|
||||||
input: None,
|
input: None,
|
||||||
|
custom_header: None,
|
||||||
command: None,
|
command: None,
|
||||||
working_directory: None,
|
working_directory: None,
|
||||||
autocomplete_prompt: None,
|
autocomplete_prompt: None,
|
||||||
@ -111,6 +113,7 @@ impl From<Cli> for PostProcessedCli {
|
|||||||
tick_rate: cli.tick_rate,
|
tick_rate: cli.tick_rate,
|
||||||
frame_rate: cli.frame_rate,
|
frame_rate: cli.frame_rate,
|
||||||
input: cli.input,
|
input: cli.input,
|
||||||
|
custom_header: cli.custom_header,
|
||||||
command: cli.command,
|
command: cli.command,
|
||||||
working_directory,
|
working_directory,
|
||||||
autocomplete_prompt: cli.autocomplete_prompt,
|
autocomplete_prompt: cli.autocomplete_prompt,
|
||||||
|
@ -17,6 +17,7 @@ pub struct UiConfig {
|
|||||||
pub input_bar_position: InputPosition,
|
pub input_bar_position: InputPosition,
|
||||||
pub preview_title_position: Option<PreviewTitlePosition>,
|
pub preview_title_position: Option<PreviewTitlePosition>,
|
||||||
pub theme: String,
|
pub theme: String,
|
||||||
|
pub custom_header: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UiConfig {
|
impl Default for UiConfig {
|
||||||
@ -29,6 +30,7 @@ impl Default for UiConfig {
|
|||||||
input_bar_position: InputPosition::Top,
|
input_bar_position: InputPosition::Top,
|
||||||
preview_title_position: None,
|
preview_title_position: None,
|
||||||
theme: String::from(DEFAULT_THEME),
|
theme: String::from(DEFAULT_THEME),
|
||||||
|
custom_header: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.channel_state.current_channel_name,
|
||||||
&ctx.tv_state.spinner,
|
&ctx.tv_state.spinner,
|
||||||
&ctx.colorscheme,
|
&ctx.colorscheme,
|
||||||
|
&ctx.config.ui.custom_header,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if layout.preview_window.is_some() {
|
if layout.preview_window.is_some() {
|
||||||
|
@ -101,6 +101,9 @@ fn apply_cli_overrides(args: &PostProcessedCli, config: &mut Config) {
|
|||||||
config.keybindings =
|
config.keybindings =
|
||||||
merge_keybindings(config.keybindings.clone(), 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<()> {
|
pub fn set_current_dir(path: &String) -> Result<()> {
|
||||||
|
@ -24,13 +24,15 @@ pub fn draw_input_box(
|
|||||||
channel_name: &str,
|
channel_name: &str,
|
||||||
spinner: &Spinner,
|
spinner: &Spinner,
|
||||||
colorscheme: &Colorscheme,
|
colorscheme: &Colorscheme,
|
||||||
|
custom_header: &Option<String>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let header = custom_header.as_deref().unwrap_or(channel_name);
|
||||||
let input_block = Block::default()
|
let input_block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.border_style(Style::default().fg(colorscheme.general.border_fg))
|
.border_style(Style::default().fg(colorscheme.general.border_fg))
|
||||||
.title_top(
|
.title_top(
|
||||||
Line::from(String::from(" ") + channel_name + " ")
|
Line::from(String::from(" ") + header + " ")
|
||||||
.style(Style::default().fg(colorscheme.mode.channel).bold())
|
.style(Style::default().fg(colorscheme.mode.channel).bold())
|
||||||
.centered(),
|
.centered(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user