diff --git a/crates/television-screen/src/layout.rs b/crates/television-screen/src/layout.rs index 70093c8..769ffd0 100644 --- a/crates/television-screen/src/layout.rs +++ b/crates/television-screen/src/layout.rs @@ -44,7 +44,7 @@ impl HelpBarLayout { } } -#[derive(Debug, Clone, Copy, Deserialize, Default)] +#[derive(Debug, Clone, Copy, Deserialize, Default, PartialEq)] pub enum InputPosition { #[serde(rename = "top")] Top, diff --git a/crates/television/app.rs b/crates/television/app.rs index 612135f..ef9a9f7 100644 --- a/crates/television/app.rs +++ b/crates/television/app.rs @@ -85,6 +85,7 @@ impl App { channel: TelevisionChannel, config: Config, passthrough_keybindings: &[String], + input: Option, ) -> Result { let (action_tx, action_rx) = mpsc::unbounded_channel(); let (render_tx, _) = mpsc::unbounded_channel(); @@ -104,7 +105,7 @@ impl App { )?; debug!("{:?}", keymap); let television = - Arc::new(Mutex::new(Television::new(channel, config))); + Arc::new(Mutex::new(Television::new(channel, config, input))); Ok(Self { keymap, diff --git a/crates/television/cli.rs b/crates/television/cli.rs index 6d3f34f..1822981 100644 --- a/crates/television/cli.rs +++ b/crates/television/cli.rs @@ -44,6 +44,10 @@ pub struct Cli { #[arg(long, value_name = "STRING")] pub passthrough_keybindings: Option, + /// Input text to pass to the channel to prefill the prompt + #[arg(short, long, value_name = "STRING")] + pub input: Option, + /// The working directory to start in #[arg(value_name = "PATH", index = 2)] pub working_directory: Option, @@ -97,6 +101,7 @@ pub struct PostProcessedCli { pub tick_rate: Option, pub frame_rate: Option, pub passthrough_keybindings: Vec, + pub input: Option, pub command: Option, pub working_directory: Option, pub autocomplete_prompt: Option, @@ -145,6 +150,7 @@ impl From for PostProcessedCli { tick_rate: cli.tick_rate, frame_rate: cli.frame_rate, passthrough_keybindings, + input: cli.input, command: cli.command, working_directory, autocomplete_prompt: cli.autocomplete_prompt, @@ -332,6 +338,7 @@ mod tests { tick_rate: Some(50.0), frame_rate: Some(60.0), passthrough_keybindings: Some("q,ctrl-w,ctrl-t".to_string()), + input: None, command: None, working_directory: Some("/home/user".to_string()), autocomplete_prompt: None, @@ -372,6 +379,7 @@ mod tests { tick_rate: Some(50.0), frame_rate: Some(60.0), passthrough_keybindings: None, + input: None, command: None, working_directory: None, autocomplete_prompt: None, diff --git a/crates/television/main.rs b/crates/television/main.rs index 5febd5f..79de6d6 100644 --- a/crates/television/main.rs +++ b/crates/television/main.rs @@ -112,6 +112,7 @@ async fn main() -> Result<()> { }, config, &args.passthrough_keybindings, + args.input, ) { Ok(mut app) => { stdout().flush()?; diff --git a/crates/television/picker.rs b/crates/television/picker.rs index 7975396..e25ba2f 100644 --- a/crates/television/picker.rs +++ b/crates/television/picker.rs @@ -11,17 +11,17 @@ pub struct Picker { impl Default for Picker { fn default() -> Self { - Self::new() + Self::new(None) } } impl Picker { - fn new() -> Self { + pub fn new(input: Option) -> Self { Self { state: ListState::default(), relative_state: ListState::default(), inverted: false, - input: Input::new(EMPTY_STRING.to_string()), + input: Input::new(input.unwrap_or(EMPTY_STRING.to_string())), } } diff --git a/crates/television/television.rs b/crates/television/television.rs index 3be2b55..b75a0c5 100644 --- a/crates/television/television.rs +++ b/crates/television/television.rs @@ -56,11 +56,15 @@ pub struct Television { impl Television { #[must_use] - pub fn new(mut channel: TelevisionChannel, config: Config) -> Self { - let results_picker = match config.ui.input_bar_position { - InputPosition::Bottom => Picker::default().inverted(), - InputPosition::Top => Picker::default(), - }; + pub fn new( + mut channel: TelevisionChannel, + config: Config, + input: Option, + ) -> Self { + let mut results_picker = Picker::new(input.clone()); + if config.ui.input_bar_position == InputPosition::Bottom { + results_picker = results_picker.inverted(); + } let previewer = Previewer::new(Some(config.previewers.clone().into())); let keymap = Keymap::from(&config.keybindings); let builtin_channels = load_builtin_channels(); @@ -79,7 +83,7 @@ impl Television { ); let colorscheme = (&Theme::from_name(&config.ui.theme)).into(); - channel.find(EMPTY_STRING); + channel.find(&input.unwrap_or(EMPTY_STRING.to_string())); let spinner = Spinner::default(); Self { action_tx: None,