Skip to content
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

Allow offset values in --terminal-width #392

Merged
merged 1 commit into from
Oct 31, 2018
Merged
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
18 changes: 17 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,23 @@ impl App {
term_width: self
.matches
.value_of("terminal-width")
.and_then(|w| w.parse().ok())
.and_then(|w| {
if w.starts_with("+") || w.starts_with("-") {
// Treat argument as a delta to the current terminal width
w.parse().ok().map(|delta: i16| {
let old_width: u16 = Term::stdout().size().1;
let new_width: i32 = old_width as i32 + delta as i32;

if new_width <= 0 {
old_width as usize
} else {
new_width as usize
}
})
} else {
w.parse().ok()
}
})
.unwrap_or(Term::stdout().size().1 as usize),
loop_through: !(self.interactive_output
|| self.matches.value_of("color") == Some("always")
Expand Down
8 changes: 6 additions & 2 deletions src/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.long("terminal-width")
.takes_value(true)
.value_name("width")
.hidden(true)
.help("Set the width of the terminal"),
.hidden_short_help(true)
.help(
"Explicitly set the width of the terminal instead of determining it \
automatically. If prefixed with '+' or '-', the value will be treated \
as an offset to the actual terminal width.",
),
)
.arg(
Arg::with_name("no-config")
Expand Down