Reorganize optionally depending on term_width

This commit is contained in:
Árpád Goretity 2017-10-06 13:14:01 +02:00
parent 3224e2e1cd
commit ac97edde90
3 changed files with 116 additions and 114 deletions

View file

@ -25,7 +25,6 @@ unicode-width = "0.1.4"
textwrap = "0.8.0"
strsim = { version = "0.6.0", optional = true }
ansi_term = { version = "0.9.0", optional = true }
term_size = { version = "0.3.0", optional = true }
yaml-rust = { version = "0.3.5", optional = true }
clippy = { version = "~0.0.131", optional = true }
atty = { version = "0.2.2", optional = true }
@ -37,10 +36,10 @@ lazy_static = "0.2"
version-sync = "0.3"
[features]
default = ["suggestions", "color", "wrap_help", "vec_map"]
default = ["suggestions", "color", "vec_map"]
suggestions = ["strsim"]
color = ["ansi_term", "atty"]
wrap_help = ["term_size"]
wrap_help = ["textwrap/term_size"]
yaml = ["yaml-rust"]
unstable = [] # for building with unstable clap features (doesn't require nightly Rust) (currently none)
nightly = [] # for building with unstable Rust features (currently none)

View file

@ -16,13 +16,16 @@ use map::VecMap;
// Third Party
use unicode_width::UnicodeWidthStr;
#[cfg(feature = "wrap_help")]
use term_size;
use textwrap;
#[cfg(feature = "wrap_help")]
fn term_width() -> usize {
textwrap::termwidth()
}
#[cfg(not(feature = "wrap_help"))]
mod term_size {
pub fn dimensions() -> Option<(usize, usize)> { None }
fn term_width() -> usize {
120
}
fn str_width(s: &str) -> usize { UnicodeWidthStr::width(s) }
@ -101,7 +104,7 @@ impl<'a> Help<'a> {
term_w: match term_w {
Some(width) => if width == 0 { usize::MAX } else { width },
None => {
cmp::min(term_size::dimensions().map_or(120, |(w, _)| w),
cmp::min(term_width(),
match max_w {
None | Some(0) => usize::MAX,
Some(mw) => mw,

View file

@ -329,7 +329,9 @@
//!
//! * `suggestions`: Turns on the `Did you mean '--myoption'?` feature for when users make typos. (builds dependency `strsim`)
//! * `color`: Turns on colored error messages. This feature only works on non-Windows OSs. (builds dependency `ansi-term` and `atty`)
//! * `wrap_help`: Wraps the help at the actual terminal width when available, instead of 120 chracters. (builds dependency `term_size`)
//! * `wrap_help`: Wraps the help at the actual terminal width when
//! available, instead of 120 chracters. (builds dependency `textwrap`
//! with feature `term_size`)
//!
//! To disable these, add this to your `Cargo.toml`:
//!
@ -541,8 +543,6 @@ extern crate unicode_width;
extern crate bitflags;
#[cfg(feature = "vec_map")]
extern crate vec_map;
#[cfg(feature = "wrap_help")]
extern crate term_size;
extern crate textwrap;
#[cfg(feature = "color")]
extern crate atty;