Skip to content

proof of concept: allow passing --inline from channel config #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions television/channels/prototypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ pub struct UiSpec {
pub help_panel: Option<ui::HelpPanelConfig>,
#[serde(default)]
pub remote_control: Option<ui::RemoteControlConfig>,
#[serde(default)]
pub inline: Option<bool>,
}

pub const DEFAULT_PROTOTYPE_NAME: &str = "files";
Expand All @@ -411,6 +413,7 @@ impl From<&crate::config::UiConfig> for UiSpec {
status_bar: Some(config.status_bar.clone()),
help_panel: Some(config.help_panel.clone()),
remote_control: Some(config.remote_control.clone()),
inline: config.inline,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions television/config/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct UiConfig {
#[serde(default = "default_input_prompt")]
pub input_prompt: String,
pub features: Features,
pub inline: Option<bool>,

// Feature-specific configurations
pub status_bar: StatusBarConfig,
Expand Down Expand Up @@ -144,6 +145,7 @@ impl Default for UiConfig {
help_panel: HelpPanelConfig::default(),
remote_control: RemoteControlConfig::default(),
theme_overrides: ThemeOverrides::default(),
inline: None,
}
}
}
24 changes: 23 additions & 1 deletion television/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() -> Result<()> {

let readable_stdin = is_readable_stdin();

let args = post_process(cli, readable_stdin);
let mut args = post_process(cli, readable_stdin);
debug!("PostProcessedCli: {:?}", args);

// load the configuration file
Expand Down Expand Up @@ -78,6 +78,9 @@ async fn main() -> Result<()> {
let channel_prototype =
determine_channel(&args, &config, readable_stdin, Some(&cable));

// allow channel to override CLI arguments
apply_channel_overrides(&mut args, &channel_prototype);

CLIPBOARD.with(<_>::default);

debug!("Creating application...");
Expand Down Expand Up @@ -135,6 +138,23 @@ async fn main() -> Result<()> {
exit(0);
}

fn apply_channel_overrides(
args: &mut PostProcessedCli,
channel_prototype: &ChannelPrototype,
) -> () {
// The default value for CLI args inline is `false`. If the CLI arguments have
// specified --inline, we should always take that value and ignore what the chanel wants
if args.inline {
return;
}
if let Some(ui) = channel_prototype.ui.as_ref() {
// Otherwise, if the channel has specified an inline value, take it
if let Some(inline) = ui.inline {
args.inline = inline
}
}
}

/// Apply overrides from the CLI arguments to the configuration.
///
/// This function mutates the configuration in place.
Expand Down Expand Up @@ -383,6 +403,7 @@ fn apply_ui_overrides(
status_bar: None,
help_panel: None,
remote_control: None,
inline: None,
});

// Apply input header override
Expand Down Expand Up @@ -764,6 +785,7 @@ mod tests {
status_bar: None,
help_panel: None,
remote_control: None,
inline: None,
});

let cable = Cable::from_prototypes(vec![channel_prototype]);
Expand Down