Skip to content

Commit 8245537

Browse files
feat(cli): add input-position cli argument (#840)
1 parent c95d48b commit 8245537

7 files changed

Lines changed: 93 additions & 32 deletions

File tree

docs/01-Users/09-cli.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,16 @@ Input:
198198
The given value is used as the prompt string shown before the input field.
199199
Defaults to ">" when omitted.
200200
201+
--input-position <INPUT_POSITION>
202+
Input bar position.
203+
204+
Sets whether the input panel is shown at the top or bottom of the UI.
205+
206+
[possible values: top, bottom]
207+
201208
--input-border <INPUT_BORDER>
202209
Sets the input panel border type.
203210
204-
Available options are: `none`, `plain`, `rounded`, `thick`.
205-
206211
[possible values: none, plain, rounded, thick]
207212
208213
--input-padding <STRING>
@@ -235,8 +240,6 @@ UI:
235240
--results-border <RESULTS_BORDER>
236241
Sets the results panel border type.
237242
238-
Available options are: `none`, `plain`, `rounded`, `thick`.
239-
240243
[possible values: none, plain, rounded, thick]
241244
242245
--results-padding <STRING>
@@ -252,8 +255,6 @@ UI:
252255
When a channel is specified: Overrides the layout/orientation defined in the channel prototype.
253256
When no channel is specified: Sets the layout orientation for the ad-hoc channel.
254257
255-
Options are "landscape" or "portrait".
256-
257258
[possible values: landscape, portrait]
258259
259260
--no-remote

man/tv.1

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.SH NAME
55
television \- A very fast, portable and hackable fuzzy finder for the terminal
66
.SH SYNOPSIS
7-
\fBtelevision\fR [\fB\-s\fR|\fB\-\-source\-command\fR] [\fB\-\-ansi\fR] [\fB\-\-source\-display\fR] [\fB\-\-source\-output\fR] [\fB\-\-source\-entry\-delimiter\fR] [\fB\-p\fR|\fB\-\-preview\-command\fR] [\fB\-\-preview\-header\fR] [\fB\-\-preview\-footer\fR] [\fB\-\-cache\-preview\fR] [\fB\-\-preview\-offset\fR] [\fB\-\-no\-preview\fR] [\fB\-\-hide\-preview\fR] [\fB\-\-show\-preview\fR] [\fB\-\-preview\-border\fR] [\fB\-\-preview\-padding\fR] [\fB\-\-hide\-preview\-scrollbar\fR] [\fB\-\-preview\-size\fR] [\fB\-i\fR|\fB\-\-input\fR] [\fB\-\-input\-header\fR] [\fB\-\-input\-prompt\fR] [\fB\-\-input\-border\fR] [\fB\-\-input\-padding\fR] [\fB\-\-no\-status\-bar\fR] [\fB\-\-hide\-status\-bar\fR] [\fB\-\-show\-status\-bar\fR] [\fB\-\-results\-border\fR] [\fB\-\-results\-padding\fR] [\fB\-\-layout\fR] [\fB\-\-no\-remote\fR] [\fB\-\-hide\-remote\fR] [\fB\-\-show\-remote\fR] [\fB\-\-no\-help\-panel\fR] [\fB\-\-hide\-help\-panel\fR] [\fB\-\-show\-help\-panel\fR] [\fB\-\-ui\-scale\fR] [\fB\-\-height\fR] [\fB\-\-width\fR] [\fB\-\-inline\fR] [\fB\-t\fR|\fB\-\-tick\-rate\fR] [\fB\-\-watch\fR] [\fB\-\-autocomplete\-prompt\fR] [\fB\-\-exact\fR] [\fB\-\-select\-1\fR] [\fB\-\-take\-1\fR] [\fB\-\-take\-1\-fast\fR] [\fB\-k\fR|\fB\-\-keybindings\fR] [\fB\-\-expect\fR] [\fB\-\-config\-file\fR] [\fB\-\-cable\-dir\fR] [\fB\-\-global\-history\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fICHANNEL\fR] [\fIPATH\fR] [\fIsubcommands\fR]
7+
\fBtelevision\fR [\fB\-s\fR|\fB\-\-source\-command\fR] [\fB\-\-ansi\fR] [\fB\-\-source\-display\fR] [\fB\-\-source\-output\fR] [\fB\-\-source\-entry\-delimiter\fR] [\fB\-p\fR|\fB\-\-preview\-command\fR] [\fB\-\-preview\-header\fR] [\fB\-\-preview\-footer\fR] [\fB\-\-cache\-preview\fR] [\fB\-\-preview\-offset\fR] [\fB\-\-no\-preview\fR] [\fB\-\-hide\-preview\fR] [\fB\-\-show\-preview\fR] [\fB\-\-preview\-border\fR] [\fB\-\-preview\-padding\fR] [\fB\-\-hide\-preview\-scrollbar\fR] [\fB\-\-preview\-size\fR] [\fB\-i\fR|\fB\-\-input\fR] [\fB\-\-input\-header\fR] [\fB\-\-input\-prompt\fR] [\fB\-\-input\-position\fR] [\fB\-\-input\-border\fR] [\fB\-\-input\-padding\fR] [\fB\-\-no\-status\-bar\fR] [\fB\-\-hide\-status\-bar\fR] [\fB\-\-show\-status\-bar\fR] [\fB\-\-results\-border\fR] [\fB\-\-results\-padding\fR] [\fB\-\-layout\fR] [\fB\-\-no\-remote\fR] [\fB\-\-hide\-remote\fR] [\fB\-\-show\-remote\fR] [\fB\-\-no\-help\-panel\fR] [\fB\-\-hide\-help\-panel\fR] [\fB\-\-show\-help\-panel\fR] [\fB\-\-ui\-scale\fR] [\fB\-\-height\fR] [\fB\-\-width\fR] [\fB\-\-inline\fR] [\fB\-t\fR|\fB\-\-tick\-rate\fR] [\fB\-\-watch\fR] [\fB\-\-autocomplete\-prompt\fR] [\fB\-\-exact\fR] [\fB\-\-select\-1\fR] [\fB\-\-take\-1\fR] [\fB\-\-take\-1\-fast\fR] [\fB\-k\fR|\fB\-\-keybindings\fR] [\fB\-\-expect\fR] [\fB\-\-config\-file\fR] [\fB\-\-cable\-dir\fR] [\fB\-\-global\-history\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fICHANNEL\fR] [\fIPATH\fR] [\fIsubcommands\fR]
88
.SH DESCRIPTION
99
A very fast, portable and hackable fuzzy finder for the terminal
1010
.SH OPTIONS
@@ -29,12 +29,7 @@ To pull the latest collection of channels from github, use the
2929
[\fIPATH\fR]
3030
The working directory to start the application in.
3131

32-
This flag works identically in both channel mode and ad\-hoc mode.
33-
34-
This can be used to specify a different working directory for the
35-
application to start in. This is useful when the application is
36-
started from a different directory than the one the user wants to
37-
interact with.
32+
Defaults to the current directory.
3833
.SH SOURCE
3934
.TP
4035
\fB\-s\fR, \fB\-\-source\-command\fR \fI<STRING>\fR
@@ -203,10 +198,17 @@ When no channel is specified: Sets the input prompt for the ad\-hoc channel.
203198
The given value is used as the prompt string shown before the input field.
204199
Defaults to ">" when omitted.
205200
.TP
201+
\fB\-\-input\-position\fR \fI<INPUT_POSITION>\fR
202+
Input bar position.
203+
204+
Sets whether the input panel is shown at the top or bottom of the UI.
205+
.br
206+
207+
.br
208+
[\fIpossible values: \fRtop, bottom]
209+
.TP
206210
\fB\-\-input\-border\fR \fI<INPUT_BORDER>\fR
207211
Sets the input panel border type.
208-
209-
Available options are: `none`, `plain`, `rounded`, `thick`.
210212
.br
211213

212214
.br
@@ -241,8 +243,6 @@ This overrides any channel configuration that might have it disabled.
241243
.TP
242244
\fB\-\-results\-border\fR \fI<RESULTS_BORDER>\fR
243245
Sets the results panel border type.
244-
245-
Available options are: `none`, `plain`, `rounded`, `thick`.
246246
.br
247247

248248
.br
@@ -260,8 +260,6 @@ Layout orientation for the UI.
260260

261261
When a channel is specified: Overrides the layout/orientation defined in the channel prototype.
262262
When no channel is specified: Sets the layout orientation for the ad\-hoc channel.
263-
264-
Options are "landscape" or "portrait".
265263
.br
266264

267265
.br

television/cli/args.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,19 @@ pub struct Cli {
291291
)]
292292
pub input_prompt: Option<String>,
293293

294-
/// Sets the input panel border type.
294+
/// Input bar position.
295295
///
296-
/// Available options are: `none`, `plain`, `rounded`, `thick`.
296+
/// Sets whether the input panel is shown at the top or bottom of the UI.
297+
#[arg(
298+
long,
299+
value_enum,
300+
value_name = "INPUT_POSITION",
301+
verbatim_doc_comment,
302+
help_heading = "Input"
303+
)]
304+
pub input_position: Option<InputPosition>,
305+
306+
/// Sets the input panel border type.
297307
#[arg(long, value_enum, verbatim_doc_comment, help_heading = "Input")]
298308
pub input_border: Option<BorderType>,
299309

@@ -333,8 +343,6 @@ pub struct Cli {
333343
pub show_status_bar: bool,
334344

335345
/// Sets the results panel border type.
336-
///
337-
/// Available options are: `none`, `plain`, `rounded`, `thick`.
338346
#[arg(long, value_enum, verbatim_doc_comment, help_heading = "UI")]
339347
pub results_border: Option<BorderType>,
340348

@@ -355,8 +363,6 @@ pub struct Cli {
355363
///
356364
/// When a channel is specified: Overrides the layout/orientation defined in the channel prototype.
357365
/// When no channel is specified: Sets the layout orientation for the ad-hoc channel.
358-
///
359-
/// Options are "landscape" or "portrait".
360366
#[arg(long, value_enum, verbatim_doc_comment, help_heading = "UI")]
361367
pub layout: Option<LayoutOrientation>,
362368

@@ -668,6 +674,12 @@ pub enum LayoutOrientation {
668674
Portrait,
669675
}
670676

677+
#[derive(Debug, Clone, Copy, PartialEq, ValueEnum)]
678+
pub enum InputPosition {
679+
Top,
680+
Bottom,
681+
}
682+
671683
#[derive(Debug, Clone, Copy, PartialEq, ValueEnum)]
672684
pub enum BorderType {
673685
None,

television/cli/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
},
1010
errors::cli_parsing_error_exit,
1111
event::Key,
12-
screen::layout::Orientation,
12+
screen::layout::{InputPosition, Orientation},
1313
utils::paths::expand_tilde,
1414
};
1515
use anyhow::{Result, anyhow};
@@ -105,6 +105,7 @@ pub struct ChannelCli {
105105
pub input: Option<String>,
106106
pub input_header: Option<String>,
107107
pub input_prompt: Option<String>,
108+
pub input_position: Option<InputPosition>,
108109
pub input_border: Option<BorderType>,
109110
pub input_padding: Option<Padding>,
110111

@@ -280,6 +281,7 @@ pub fn post_process(cli: Cli, readable_stdin: bool) -> PostProcessedCli {
280281

281282
// Determine layout
282283
let layout: Option<Orientation> = cli.layout.map(Orientation::from);
284+
let input_position = cli.input_position.map(InputPosition::from);
283285

284286
// borders
285287
let input_border = cli.input_border.map(BorderType::from);
@@ -347,6 +349,7 @@ pub fn post_process(cli: Cli, readable_stdin: bool) -> PostProcessedCli {
347349
input: cli.input,
348350
input_header: cli.input_header,
349351
input_prompt: cli.input_prompt,
352+
input_position,
350353
input_border,
351354
input_padding,
352355

television/config/layers.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,15 @@ impl ConfigLayers {
202202
|| self.base_config.ui.status_bar.separator_close.clone(),
203203
|sb| sb.separator_close.clone(),
204204
);
205-
let input_bar_position = self
206-
.channel
207-
.ui
208-
.as_ref()
209-
.and_then(|ui| ui.input_bar.as_ref())
210-
.map_or(self.base_config.ui.input_bar.position, |ib| ib.position);
205+
let input_bar_position = self.channel_cli.input_position.unwrap_or(
206+
self.channel
207+
.ui
208+
.as_ref()
209+
.and_then(|ui| ui.input_bar.as_ref())
210+
.map_or(self.base_config.ui.input_bar.position, |ib| {
211+
ib.position
212+
}),
213+
);
211214

212215
// CLI > channel > base config fields
213216
let ui_scale = self.channel_cli.ui_scale.unwrap_or(

television/screen/layout.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ impl Display for InputPosition {
5353
}
5454
}
5555

56+
impl From<crate::cli::args::InputPosition> for InputPosition {
57+
fn from(value: crate::cli::args::InputPosition) -> Self {
58+
match value {
59+
crate::cli::args::InputPosition::Top => InputPosition::Top,
60+
crate::cli::args::InputPosition::Bottom => InputPosition::Bottom,
61+
}
62+
}
63+
}
64+
5665
#[derive(
5766
Debug,
5867
Clone,

tests/config/cli_overrides.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,41 @@ fn test_empty_cli_args_dont_override() {
237237
PtyTester::assert_exit_ok(&mut child, DEFAULT_DELAY);
238238
}
239239

240+
/// Tests CLI override of input bar position
241+
#[test]
242+
fn test_cli_input_position_override() {
243+
let mut tester = PtyTester::new();
244+
245+
let cmd = tv_with_args(&[
246+
"files",
247+
"--cable-dir",
248+
DEFAULT_CABLE_DIR,
249+
"--input-prompt",
250+
"position-prompt>",
251+
"--input-position",
252+
"bottom",
253+
]);
254+
255+
let mut child = tester.spawn_command_tui(cmd);
256+
257+
let frame = tester.get_tui_frame();
258+
let prompt_index = frame
259+
.find("position-prompt>")
260+
.expect("Expected input prompt in frame");
261+
let results_index = frame
262+
.find("Results")
263+
.expect("Expected results header in frame");
264+
265+
assert!(
266+
prompt_index > results_index,
267+
"Expected input bar below results when using --input-position=bottom.\nFrame:\n{}",
268+
frame
269+
);
270+
271+
tester.send(&ctrl('c'));
272+
PtyTester::assert_exit_ok(&mut child, DEFAULT_DELAY);
273+
}
274+
240275
#[test]
241276
fn test_action_id_mismatch_validation_error() {
242277
let mut tester = PtyTester::new();

0 commit comments

Comments
 (0)