Skip to content

Commit

Permalink
imp(help): use term_size instead of home-grown solution
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli committed Aug 29, 2016
1 parent b7793a2 commit fc7327e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 42 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
35 changes: 1 addition & 34 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)> {
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc7327e

Please sign in to comment.