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)
|
||||
input_bar_position = "top"
|
||||
# The input prompt string (defaults to ">" if not specified)
|
||||
# input_prompt = ">"
|
||||
input_prompt = ">"
|
||||
# What orientation should tv be (landscape or portrait)
|
||||
orientation = "landscape"
|
||||
# The theme to use for the UI
|
||||
|
@ -402,7 +402,7 @@ impl From<&crate::config::UiConfig> for UiSpec {
|
||||
orientation: Some(config.orientation),
|
||||
input_bar_position: Some(config.input_bar_position),
|
||||
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()),
|
||||
status_bar: Some(config.status_bar.clone()),
|
||||
help_panel: Some(config.help_panel.clone()),
|
||||
|
@ -268,7 +268,7 @@ impl Config {
|
||||
|
||||
// Apply 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
|
||||
@ -507,7 +507,7 @@ mod tests {
|
||||
let config = Config::new(&config_env, None).unwrap();
|
||||
|
||||
// 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]
|
||||
|
@ -108,7 +108,8 @@ pub struct UiConfig {
|
||||
pub orientation: Orientation,
|
||||
pub theme: String,
|
||||
pub input_header: Option<Template>,
|
||||
pub input_prompt: Option<String>,
|
||||
#[serde(default = "default_input_prompt")]
|
||||
pub input_prompt: String,
|
||||
pub features: Features,
|
||||
|
||||
// Feature-specific configurations
|
||||
@ -122,6 +123,11 @@ pub struct UiConfig {
|
||||
pub theme_overrides: ThemeOverrides,
|
||||
}
|
||||
|
||||
const DEFAULT_INPUT_PROMPT: &str = ">";
|
||||
fn default_input_prompt() -> String {
|
||||
String::from(DEFAULT_INPUT_PROMPT)
|
||||
}
|
||||
|
||||
impl Default for UiConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@ -131,7 +137,7 @@ impl Default for UiConfig {
|
||||
orientation: Orientation::Landscape,
|
||||
theme: String::from(DEFAULT_THEME),
|
||||
input_header: None,
|
||||
input_prompt: None,
|
||||
input_prompt: String::from(DEFAULT_INPUT_PROMPT),
|
||||
features: Features::default(),
|
||||
status_bar: StatusBarConfig::default(),
|
||||
preview_panel: PreviewPanelConfig::default(),
|
||||
|
@ -197,10 +197,7 @@ pub fn draw(ctx: Box<Ctx>, f: &mut Frame<'_>, area: Rect) -> Result<Layout> {
|
||||
)?;
|
||||
|
||||
// input box
|
||||
let input_prompt = ctx.config.ui.input_prompt
|
||||
.as_ref()
|
||||
.map(|p| format!("{} ", p))
|
||||
.unwrap_or_else(|| "> ".to_string());
|
||||
let input_prompt = ctx.config.ui.input_prompt.clone();
|
||||
|
||||
draw_input_box(
|
||||
f,
|
||||
|
@ -203,7 +203,7 @@ fn apply_cli_overrides(args: &PostProcessedCli, config: &mut Config) {
|
||||
}
|
||||
}
|
||||
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 Ok(t) = Template::parse(preview_header) {
|
||||
|
@ -65,8 +65,10 @@ pub fn draw_input_box(
|
||||
let inner_input_chunks = RatatuiLayout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([
|
||||
// prompt symbol
|
||||
Constraint::Length(u16::try_from(input_prompt.len()).unwrap_or(2)),
|
||||
// prompt symbol + space
|
||||
Constraint::Length(
|
||||
u16::try_from(input_prompt.chars().count() + 1).unwrap_or(2),
|
||||
),
|
||||
// input field
|
||||
Constraint::Fill(1),
|
||||
// result count
|
||||
@ -82,7 +84,7 @@ pub fn draw_input_box(
|
||||
|
||||
let arrow_block = Block::default();
|
||||
let arrow = Paragraph::new(Span::styled(
|
||||
input_prompt,
|
||||
format!("{} ", input_prompt),
|
||||
Style::default().fg(colorscheme.input.input_fg).bold(),
|
||||
))
|
||||
.block(arrow_block);
|
||||
|
Loading…
x
Reference in New Issue
Block a user