fix(channels): make stdin and adhoc channels inherit from global config (#633)

## 📺 PR Description

Fixes #627
stdin and adhoc channels now inherit from global config making them
consistent with the rest

## Checklist

<!-- a quick pass through the following items to make sure you haven't
forgotten anything -->

- [x] my commits **and PR title** follow the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format
- [ ] if this is a new feature, I have added tests to consolidate the
feature and prevent regressions
- [ ] if this is a bug fix, I have added a test that reproduces the bug
(if applicable)
- [x] I have added a reasonable amount of documentation to the code
where appropriate
This commit is contained in:
LM 2025-07-12 13:51:48 +02:00 committed by GitHub
parent 4e90a357e8
commit 521c7473b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 32 deletions

View File

@ -157,7 +157,7 @@ impl CommandSpec {
}
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, Default)]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct ChannelKeyBindings {
/// Optional channel specific shortcut that, when pressed, switches directly to this channel.
#[serde(default)]
@ -392,6 +392,22 @@ pub struct UiSpec {
pub const DEFAULT_PROTOTYPE_NAME: &str = "files";
impl From<&crate::config::UiConfig> for UiSpec {
fn from(config: &crate::config::UiConfig) -> Self {
UiSpec {
ui_scale: Some(config.ui_scale),
features: Some(config.features.clone()),
orientation: Some(config.orientation),
input_bar_position: Some(config.input_bar_position),
input_header: config.input_header.clone(),
preview_panel: Some(config.preview_panel.clone()),
status_bar: Some(config.status_bar.clone()),
help_panel: Some(config.help_panel.clone()),
remote_control: Some(config.remote_control.clone()),
}
}
}
#[cfg(test)]
mod tests {
use crate::{action::Action, config::Binding, event::Key};

View File

@ -20,7 +20,7 @@ use television::{
},
config::{Config, ConfigEnv, merge_keybindings},
errors::os_error_exit,
features::{FeatureFlags, Features},
features::FeatureFlags,
gh::update_local_channels,
television::Mode,
utils::clipboard::CLIPBOARD,
@ -249,7 +249,10 @@ pub fn handle_subcommand(command: &Command, config: &Config) -> Result<()> {
}
/// Creates a stdin channel prototype with optional preview configuration
fn create_stdin_channel(args: &PostProcessedCli) -> ChannelPrototype {
fn create_stdin_channel(
args: &PostProcessedCli,
config: &Config,
) -> ChannelPrototype {
debug!("Using stdin channel");
let stdin_preview =
args.preview_command_override.as_ref().map(|preview_cmd| {
@ -262,8 +265,8 @@ fn create_stdin_channel(args: &PostProcessedCli) -> ChannelPrototype {
let mut prototype =
ChannelPrototype::stdin(stdin_preview, args.source_entry_delimiter);
// Configure UI features based on whether preview command is available
let mut features = Features::default();
// Inherit UI features from global config (which has CLI overrides applied)
let mut features = config.ui.features.clone();
if args.preview_command_override.is_some() {
features.enable(FeatureFlags::PreviewPanel);
} else {
@ -271,17 +274,9 @@ fn create_stdin_channel(args: &PostProcessedCli) -> ChannelPrototype {
}
// Set UI specification to properly control feature visibility
prototype.ui = Some(UiSpec {
ui_scale: None,
features: Some(features),
orientation: None,
input_bar_position: None,
input_header: None,
status_bar: None,
preview_panel: None,
help_panel: None,
remote_control: None,
});
let mut ui_spec = UiSpec::from(&config.ui);
ui_spec.features = Some(features);
prototype.ui = Some(ui_spec);
prototype
}
@ -290,7 +285,10 @@ fn create_stdin_channel(args: &PostProcessedCli) -> ChannelPrototype {
const DEFAULT_ADHOC_CHANNEL_HEADER: &str = "Custom Channel";
/// Creates an ad-hoc channel prototype from CLI arguments
fn create_adhoc_channel(args: &PostProcessedCli) -> ChannelPrototype {
fn create_adhoc_channel(
args: &PostProcessedCli,
config: &Config,
) -> ChannelPrototype {
debug!("Creating ad-hoc channel with source command override");
let source_cmd = args.source_command_override.as_ref().unwrap();
@ -306,8 +304,8 @@ fn create_adhoc_channel(args: &PostProcessedCli) -> ChannelPrototype {
Template::parse(DEFAULT_ADHOC_CHANNEL_HEADER).unwrap()
});
// Configure features based on available commands
let mut features = Features::default();
// Inherit UI features from global config (which has CLI overrides applied)
let mut features = config.ui.features.clone();
if args.preview_command_override.is_some() {
features.enable(FeatureFlags::PreviewPanel);
} else {
@ -315,17 +313,10 @@ fn create_adhoc_channel(args: &PostProcessedCli) -> ChannelPrototype {
}
// Set UI specification
prototype.ui = Some(UiSpec {
ui_scale: None,
features: Some(features),
orientation: None,
input_bar_position: None,
input_header: Some(input_header),
status_bar: None,
preview_panel: None,
help_panel: None,
remote_control: None,
});
let mut ui_spec = UiSpec::from(&config.ui);
ui_spec.input_header = Some(input_header);
ui_spec.features = Some(features);
prototype.ui = Some(ui_spec);
prototype
}
@ -445,7 +436,7 @@ pub fn determine_channel(
) -> ChannelPrototype {
// Determine the base channel prototype
let mut channel_prototype = if readable_stdin {
create_stdin_channel(args)
create_stdin_channel(args, config)
} else if let Some(prompt) = &args.autocomplete_prompt {
if cable.is_none() {
cable_empty_exit()
@ -461,7 +452,7 @@ pub fn determine_channel(
prototype
} else if args.channel.is_none() && args.source_command_override.is_some()
{
create_adhoc_channel(args)
create_adhoc_channel(args, config)
} else {
if cable.is_none() {
cable_empty_exit()