mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Auto merge of #639 - nabijaczleweli:improvement/help/wrap-use-term_size, r=kbknapp
Use term_size instead of home-grown solution Ref: #631
This commit is contained in:
commit
26d5207728
3 changed files with 1 additions and 42 deletions
|
@ -26,10 +26,6 @@ unicode-width = "~0.1.3"
|
|||
unicode-segmentation = "~0.1.2"
|
||||
term_size = { version = "~0.1.0", optional = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
kernel32-sys = "~0.2.2"
|
||||
winapi = "~0.2.8"
|
||||
|
||||
[dev-dependencies]
|
||||
regex = "~0.1.69"
|
||||
|
||||
|
|
|
@ -14,41 +14,8 @@ use app::{App, AppSettings};
|
|||
use app::parser::Parser;
|
||||
use fmt::{Format, Colorizer};
|
||||
|
||||
#[cfg(all(feature = "wrap_help", not(target_os = "windows")))]
|
||||
#[cfg(feature = "wrap_help")]
|
||||
use term_size;
|
||||
#[cfg(all(feature = "wrap_help", target_os = "windows"))]
|
||||
mod term_size {
|
||||
use kernel32::{GetConsoleScreenBufferInfo, GetStdHandle};
|
||||
use winapi::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT, STD_OUTPUT_HANDLE};
|
||||
|
||||
pub fn dimensions() -> Option<(usize, usize)> {
|
||||
let null_coord = COORD{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
};
|
||||
let null_smallrect = SMALL_RECT{
|
||||
Left: 0,
|
||||
Top: 0,
|
||||
Right: 0,
|
||||
Bottom: 0,
|
||||
};
|
||||
|
||||
let stdout_h = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) };
|
||||
let mut console_data = CONSOLE_SCREEN_BUFFER_INFO{
|
||||
dwSize: null_coord,
|
||||
dwCursorPosition: null_coord,
|
||||
wAttributes: 0,
|
||||
srWindow: null_smallrect,
|
||||
dwMaximumWindowSize: null_coord,
|
||||
};
|
||||
|
||||
if unsafe { GetConsoleScreenBufferInfo(stdout_h, &mut console_data) } != 0 {
|
||||
Some(((console_data.srWindow.Right - console_data.srWindow.Left) as usize, (console_data.srWindow.Bottom - console_data.srWindow.Top) as usize))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "wrap_help"))]
|
||||
mod term_size {
|
||||
pub fn dimensions() -> Option<(usize, usize)> {
|
||||
|
|
|
@ -416,10 +416,6 @@ extern crate vec_map;
|
|||
#[cfg(feature = "wrap_help")]
|
||||
extern crate term_size;
|
||||
extern crate unicode_segmentation;
|
||||
#[cfg(target_os = "windows")]
|
||||
extern crate kernel32;
|
||||
#[cfg(target_os = "windows")]
|
||||
extern crate winapi;
|
||||
|
||||
#[cfg(feature = "yaml")]
|
||||
pub use yaml_rust::YamlLoader;
|
||||
|
|
Loading…
Reference in a new issue