mirror of
https://github.com/alexpasmantier/television.git
synced 2025-07-29 06:11:37 +00:00
refactor: better default management + a bit of cleaning
This commit is contained in:
parent
c5f4e65942
commit
51ad1855e0
@ -57,7 +57,7 @@ ui_scale = 100
|
|||||||
# Where to place the input bar in the UI (top or bottom)
|
# Where to place the input bar in the UI (top or bottom)
|
||||||
input_bar_position = "top"
|
input_bar_position = "top"
|
||||||
# The input prompt string (defaults to ">" if not specified)
|
# The input prompt string (defaults to ">" if not specified)
|
||||||
# input_prompt = ">"
|
input_prompt = ">"
|
||||||
# What orientation should tv be (landscape or portrait)
|
# What orientation should tv be (landscape or portrait)
|
||||||
orientation = "landscape"
|
orientation = "landscape"
|
||||||
# The theme to use for the UI
|
# The theme to use for the UI
|
||||||
|
@ -402,7 +402,7 @@ impl From<&crate::config::UiConfig> for UiSpec {
|
|||||||
orientation: Some(config.orientation),
|
orientation: Some(config.orientation),
|
||||||
input_bar_position: Some(config.input_bar_position),
|
input_bar_position: Some(config.input_bar_position),
|
||||||
input_header: config.input_header.clone(),
|
input_header: config.input_header.clone(),
|
||||||
input_prompt: config.input_prompt.clone(),
|
input_prompt: Some(config.input_prompt.clone()),
|
||||||
preview_panel: Some(config.preview_panel.clone()),
|
preview_panel: Some(config.preview_panel.clone()),
|
||||||
status_bar: Some(config.status_bar.clone()),
|
status_bar: Some(config.status_bar.clone()),
|
||||||
help_panel: Some(config.help_panel.clone()),
|
help_panel: Some(config.help_panel.clone()),
|
||||||
|
@ -147,7 +147,7 @@ pub struct Cli {
|
|||||||
/// When no channel is specified: Sets the input prompt for the ad-hoc channel.
|
/// When no channel is specified: Sets the input prompt for the ad-hoc channel.
|
||||||
///
|
///
|
||||||
/// The given value is used as the prompt string shown before the input field.
|
/// The given value is used as the prompt string shown before the input field.
|
||||||
/// Defaults to "> " when omitted.
|
/// Defaults to ">" when omitted.
|
||||||
#[arg(long = "input-prompt", value_name = "STRING", verbatim_doc_comment)]
|
#[arg(long = "input-prompt", value_name = "STRING", verbatim_doc_comment)]
|
||||||
pub input_prompt: Option<String>,
|
pub input_prompt: Option<String>,
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ impl Config {
|
|||||||
|
|
||||||
// Apply input_prompt
|
// Apply input_prompt
|
||||||
if let Some(value) = &ui_spec.input_prompt {
|
if let Some(value) = &ui_spec.input_prompt {
|
||||||
self.ui.input_prompt = Some(value.clone());
|
self.ui.input_prompt.clone_from(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle preview_panel with field merging
|
// Handle preview_panel with field merging
|
||||||
@ -488,7 +488,7 @@ mod tests {
|
|||||||
|
|
||||||
const USER_CONFIG_INPUT_PROMPT: &str = r#"
|
const USER_CONFIG_INPUT_PROMPT: &str = r#"
|
||||||
[ui]
|
[ui]
|
||||||
input_prompt = "❯ "
|
input_prompt = "❯"
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -507,7 +507,7 @@ mod tests {
|
|||||||
let config = Config::new(&config_env, None).unwrap();
|
let config = Config::new(&config_env, None).unwrap();
|
||||||
|
|
||||||
// Verify that input_prompt was loaded from user config
|
// Verify that input_prompt was loaded from user config
|
||||||
assert_eq!(config.ui.input_prompt, Some("❯ ".to_string()));
|
assert_eq!(config.ui.input_prompt, "❯");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -108,7 +108,8 @@ pub struct UiConfig {
|
|||||||
pub orientation: Orientation,
|
pub orientation: Orientation,
|
||||||
pub theme: String,
|
pub theme: String,
|
||||||
pub input_header: Option<Template>,
|
pub input_header: Option<Template>,
|
||||||
pub input_prompt: Option<String>,
|
#[serde(default = "default_input_prompt")]
|
||||||
|
pub input_prompt: String,
|
||||||
pub features: Features,
|
pub features: Features,
|
||||||
|
|
||||||
// Feature-specific configurations
|
// Feature-specific configurations
|
||||||
@ -122,6 +123,11 @@ pub struct UiConfig {
|
|||||||
pub theme_overrides: ThemeOverrides,
|
pub theme_overrides: ThemeOverrides,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_INPUT_PROMPT: &str = ">";
|
||||||
|
fn default_input_prompt() -> String {
|
||||||
|
String::from(DEFAULT_INPUT_PROMPT)
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for UiConfig {
|
impl Default for UiConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -131,7 +137,7 @@ impl Default for UiConfig {
|
|||||||
orientation: Orientation::Landscape,
|
orientation: Orientation::Landscape,
|
||||||
theme: String::from(DEFAULT_THEME),
|
theme: String::from(DEFAULT_THEME),
|
||||||
input_header: None,
|
input_header: None,
|
||||||
input_prompt: None,
|
input_prompt: String::from(DEFAULT_INPUT_PROMPT),
|
||||||
features: Features::default(),
|
features: Features::default(),
|
||||||
status_bar: StatusBarConfig::default(),
|
status_bar: StatusBarConfig::default(),
|
||||||
preview_panel: PreviewPanelConfig::default(),
|
preview_panel: PreviewPanelConfig::default(),
|
||||||
|
@ -197,10 +197,7 @@ pub fn draw(ctx: Box<Ctx>, f: &mut Frame<'_>, area: Rect) -> Result<Layout> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// input box
|
// input box
|
||||||
let input_prompt = ctx.config.ui.input_prompt
|
let input_prompt = ctx.config.ui.input_prompt.clone();
|
||||||
.as_ref()
|
|
||||||
.map(|p| format!("{} ", p))
|
|
||||||
.unwrap_or_else(|| "> ".to_string());
|
|
||||||
|
|
||||||
draw_input_box(
|
draw_input_box(
|
||||||
f,
|
f,
|
||||||
|
@ -203,7 +203,7 @@ fn apply_cli_overrides(args: &PostProcessedCli, config: &mut Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(input_prompt) = &args.input_prompt {
|
if let Some(input_prompt) = &args.input_prompt {
|
||||||
config.ui.input_prompt = Some(input_prompt.clone());
|
config.ui.input_prompt.clone_from(input_prompt);
|
||||||
}
|
}
|
||||||
if let Some(preview_header) = &args.preview_header {
|
if let Some(preview_header) = &args.preview_header {
|
||||||
if let Ok(t) = Template::parse(preview_header) {
|
if let Ok(t) = Template::parse(preview_header) {
|
||||||
|
@ -65,8 +65,10 @@ pub fn draw_input_box(
|
|||||||
let inner_input_chunks = RatatuiLayout::default()
|
let inner_input_chunks = RatatuiLayout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([
|
.constraints([
|
||||||
// prompt symbol
|
// prompt symbol + space
|
||||||
Constraint::Length(u16::try_from(input_prompt.len()).unwrap_or(2)),
|
Constraint::Length(
|
||||||
|
u16::try_from(input_prompt.chars().count() + 1).unwrap_or(2),
|
||||||
|
),
|
||||||
// input field
|
// input field
|
||||||
Constraint::Fill(1),
|
Constraint::Fill(1),
|
||||||
// result count
|
// result count
|
||||||
@ -82,7 +84,7 @@ pub fn draw_input_box(
|
|||||||
|
|
||||||
let arrow_block = Block::default();
|
let arrow_block = Block::default();
|
||||||
let arrow = Paragraph::new(Span::styled(
|
let arrow = Paragraph::new(Span::styled(
|
||||||
input_prompt,
|
format!("{} ", input_prompt),
|
||||||
Style::default().fg(colorscheme.input.input_fg).bold(),
|
Style::default().fg(colorscheme.input.input_fg).bold(),
|
||||||
))
|
))
|
||||||
.block(arrow_block);
|
.block(arrow_block);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user