mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
feat(help): support wrapping help at console width on windows
Closes #455
This commit is contained in:
parent
853a90de01
commit
0d93d9b953
3 changed files with 42 additions and 1 deletions
|
@ -23,6 +23,10 @@ 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"
|
||||
|
||||
|
|
|
@ -16,7 +16,40 @@ use fmt::{Format, Colorizer};
|
|||
|
||||
#[cfg(all(feature = "wrap_help", not(target_os = "windows")))]
|
||||
use term_size;
|
||||
#[cfg(any(not(feature = "wrap_help"), target_os = "windows"))]
|
||||
#[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)> {
|
||||
None
|
||||
|
|
|
@ -416,6 +416,10 @@ 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