termsize-0.1.6/.gitignore010064400007650000024000000000221254262164500135700ustar0000000000000000target Cargo.lock termsize-0.1.6/.travis.yml010064400007650000024000000043361316400576600137260ustar0000000000000000language: rust sudo: false matrix: fast_finish: true include: - rust: nightly - rust: nightly os: osx - rust: beta - rust: beta os: osx - rust: stable - rust: stable os: osx allow_failures: - rust: nightly cache: cargo: true apt: true directories: - target/debug/deps - target/debug/build addons: apt: packages: - libcurl4-openssl-dev - libelf-dev - libdw-dev - binutils-dev - libiberty-dev before_cache: # Travis can't cache files that are not readable by "others" - chmod -R a+r $HOME/.cargo # https://github.com/travis-ci/travis-ci/issues/7669#issuecomment-299149209 before_install: # install kcov - > if [ ! -d "$HOME/.kcov/bin" ]; then wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake -DCMAKE_INSTALL_PREFIX:PATH=$HOME/.kcov .. && make && make install && cd ../.. fi - export PATH=$HOME/.kcov/bin:$PATH - > if [ "$TRAVIS_OS_NAME" == "linux" ]; then stty cols 80 else # man resize echo "osx on travis doesnt support stty cols 80" fi script: - cargo build after_success: - '[ $TRAVIS_RUST_VERSION = stable ] && [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && (ls target/debug && RUSTFLAGS="-C link-dead-code" cargo test --no-run && for file in target/debug/termsize-*; do if [[ "${file: -2}" != ".d" ]]; then mkdir -p "target/cov/$(basename $file)"; kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; fi; done && kcov --coveralls-id=$COVERALLS_REPO_TOKEN --merge target/cov target/cov/* && echo "covered") || true' - '[ $TRAVIS_RUST_VERSION = stable ] && [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && cargo doc --no-deps && echo "" > target/doc/index.html && pip install --user ghp-import && /home/travis/.local/bin/ghp-import -n target/doc && git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages && echo "documented"'termsize-0.1.6/appveyor.yml010064400007650000024000000010351314223324400141640ustar0000000000000000environment: matrix: - TARGET: nightly-x86_64-pc-windows-msvc - TARGET: nightly-i686-pc-windows-msvc - TARGET: nightly-x86_64-pc-windows-gnu - TARGET: nightly-i686-pc-windows-gnu install: - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe" - ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null - ps: $env:PATH="$env:PATH;C:\rust\bin" - call "%VCVARS%" || ver>nul - rustc -vV - cargo -vV build: false test_script: - cargo test --verbose termsize-0.1.6/Cargo.toml.orig010064400007650000024000000012731346135433100144740ustar0000000000000000[package] name = "termsize" version = "0.1.6" authors = ["softprops "] description = "Retrieves terminal size" repository = "https://github.com/softprops/termsize" homepage = "https://github.com/softprops/termsize" documentation = "http://softprops.github.io/termsize" keywords = ["tty", "terminal", "term", "size", "dimensions"] license = "MIT" readme = "README.md" [badges] travis-ci = { repository = "softprops/termsize" } coveralls = { repository = "softprops/termsize" } [target.'cfg(unix)'.dependencies] atty = "0.2" libc = "0.2" [target.'cfg(windows)'.dependencies] winapi = "0.2" kernel32-sys = "0.2" [target.'cfg(target_os = "redox")'.dependencies] termion = "1.5" termsize-0.1.6/Cargo.toml0000644000000024650000000000000107460ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "termsize" version = "0.1.6" authors = ["softprops "] description = "Retrieves terminal size" homepage = "https://github.com/softprops/termsize" documentation = "http://softprops.github.io/termsize" readme = "README.md" keywords = ["tty", "terminal", "term", "size", "dimensions"] license = "MIT" repository = "https://github.com/softprops/termsize" [target."cfg(target_os = \"redox\")".dependencies.termion] version = "1.5" [target."cfg(unix)".dependencies.atty] version = "0.2" [target."cfg(unix)".dependencies.libc] version = "0.2" [target."cfg(windows)".dependencies.kernel32-sys] version = "0.2" [target."cfg(windows)".dependencies.winapi] version = "0.2" [badges.coveralls] repository = "softprops/termsize" [badges.travis-ci] repository = "softprops/termsize" termsize-0.1.6/CHANGELOG.md010064400007650000024000000014321346135451300134150ustar0000000000000000# 0.1.6 * fix `TIOCGWINSZ` size issue on FreeBSD [#6](https://github.com/softprops/termsize/pull/9) # 0.1.5 * added support for [Redox OS](https://github.com/redox-os/redox) [@ids1024](https://github.com/softprops/termsize/pull/8) # 0.1.4 * added support for [Fuchsia](https://en.wikipedia.org/wiki/Google_Fuchsia) OS [@antiagainst](https://github.com/softprops/termsize/pull/5) # 0.1.3 * add support for new targets arm-unknown-linux-gnueabihf and armv7-unknown-linux-gnueabihf [@wimh](https://github.com/softprops/termsize/pull/3) # 0.1.2 * replaced hardcoded per-platform constants for TIOCGWINSZ with the one defined in libc [@antiagainst](https://github.com/softprops/termsize/pull/4) # 0.1.1 * fixed broken windows support (added automated testing) # 0.1.0 * initial release termsize-0.1.6/examples/ts.rs010064400007650000024000000001321316377767700144350ustar0000000000000000extern crate termsize; pub fn main() { println!("{:?}", termsize::get().unwrap()); } termsize-0.1.6/LICENSE010064400007650000024000000020441316400212500125760ustar0000000000000000Copyright (c) 2015-2017 Doug Tangren Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.termsize-0.1.6/README.md010064400007650000024000000024051316400227200130540ustar0000000000000000# termsize [![Build Status](https://travis-ci.org/softprops/termsize.svg)](https://travis-ci.org/softprops/termsize) [![Build status](https://ci.appveyor.com/api/projects/status/ilics7dppw0vl6gb?svg=true)](https://ci.appveyor.com/project/softprops/termsize) [![Coverage Status](https://coveralls.io/repos/softprops/termsize/badge.svg?branch=master&service=github)](https://coveralls.io/github/softprops/termsize?branch=master) > because terminal size matters Termsize is a rust crate providing a multi-platform interface for resolving your terminal's current size in rows and columns. On most unix systems, this is similar invoking the [stty(1)](http://man7.org/linux/man-pages/man1/stty.1.html) program, requesting the terminal size. ## [Documentation](https://softprops.github.com/termsize) ## install add the following to your `Cargo.toml` file ```toml [dependencies] termsize = "0.1" ``` ## usage Termize provides one function, `get`, which returns a `termsize::Size` struct exposing two fields: `rows` and `cols` representing the number of rows and columns a a terminal's stdout supports. ```rust extern crate termsize; pub fn main() { termsize::get().map(|size| { println!("rows {} cols {}", size.rows, size.cols) }); } ``` Doug Tangren (softprops) 2015-2017termsize-0.1.6/rustfmt.toml010064400007650000024000000003561316377774400142270ustar0000000000000000# keep imports tidy reorder_imported_names = true reorder_imports = true reorder_imports_in_group = true # there is no try! use_try_shorthand = true # don't create rustfmt artifacts write_mode = "Replace" # reduce wide load max_width = 80termsize-0.1.6/src/lib.rs010064400007650000024000000015141316400153700135030ustar0000000000000000#![deny(missing_docs)] //! Termsize is a tiny crate that provides a simple //! interface for retrieving the current //! [terminal interface](http://www.manpagez.com/man/4/tty/) size //! //! ```rust //! extern crate termsize; //! //! termsize::get().map(|size| { //! println!("rows {} cols {}", size.rows, size.cols) //! }); //! ``` /// Container for number of rows and columns #[derive(Debug)] pub struct Size { /// number of rows pub rows: u16, /// number of columns pub cols: u16, } #[cfg(unix)] mod nix; #[cfg(unix)] pub use self::nix::get; #[cfg(windows)] mod win; #[cfg(windows)] pub use self::win::get; #[cfg(target_os = "redox")] mod redox; #[cfg(target_os = "redox")] pub use self::redox::get; #[cfg(test)] mod tests { use super::get; #[test] fn test_get() { assert!(get().is_some()) } } termsize-0.1.6/src/nix.rs010064400007650000024000000037601346135431600135460ustar0000000000000000extern crate libc; extern crate atty; use self::libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort}; use self::libc::ioctl; use self::super::Size; /// A representation of the size of the current terminal #[repr(C)] #[derive(Debug)] pub struct UnixSize { /// number of rows pub rows: c_ushort, /// number of columns pub cols: c_ushort, x: c_ushort, y: c_ushort, } /// Gets the current terminal size pub fn get() -> Option { // http://rosettacode.org/wiki/Terminal_control/Dimensions#Library:_BSD_libc if atty::isnt(atty::Stream::Stdout) { return None; } let us = UnixSize { rows: 0, cols: 0, x: 0, y: 0, }; let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &us) }; if r == 0 { Some(Size { rows: us.rows, cols: us.cols, }) } else { None } } #[cfg(test)] mod tests { use super::get; use super::super::Size; use std::process::{Command, Output, Stdio}; #[cfg(target_os = "macos")] fn stty_size() -> Output { Command::new("stty") .arg("-f") .arg("/dev/stderr") .arg("size") .stderr(Stdio::inherit()) .output() .unwrap() } #[cfg(not(target_os = "macos"))] fn stty_size() -> Output { Command::new("stty") .arg("-F") .arg("/dev/stderr") .arg("size") .stderr(Stdio::inherit()) .output() .unwrap() } #[test] fn test_shell() { let output = stty_size(); assert!(output.status.success()); let stdout = String::from_utf8(output.stdout).unwrap(); let mut data = stdout.split_whitespace(); let rs = data.next().unwrap().parse::().unwrap(); let cs = data.next().unwrap().parse::().unwrap(); if let Some(Size { rows, cols }) = get() { assert_eq!(rows, rs); assert_eq!(cols, cs); } } } termsize-0.1.6/src/redox.rs010064400007650000024000000003151316377767700141040ustar0000000000000000extern crate termion; use self::super::Size; /// Gets the current terminal size pub fn get() -> Option { termion::terminal_size().ok().map(|(cols, rows)| { Size { rows, cols } }) } termsize-0.1.6/src/win.rs010064400007650000024000000024161316377767700135640ustar0000000000000000extern crate winapi; extern crate kernel32; use self::super::Size; use std::ptr; /// Gets the current terminal size pub fn get() -> Option { // http://rosettacode.org/wiki/Terminal_control/Dimensions#Windows use self::kernel32::{self, GetConsoleScreenBufferInfo}; use self::winapi::{self, CONSOLE_SCREEN_BUFFER_INFO, HANDLE, INVALID_HANDLE_VALUE}; let handle: HANDLE = unsafe { kernel32::CreateFileA( b"CONOUT$\0".as_ptr() as *const i8, winapi::GENERIC_READ | winapi::GENERIC_WRITE, winapi::FILE_SHARE_WRITE, ptr::null_mut(), winapi::OPEN_EXISTING, 0, ptr::null_mut(), ) }; if handle == INVALID_HANDLE_VALUE { return None; } let info = unsafe { // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx let mut info = ::std::mem::uninitialized(); if GetConsoleScreenBufferInfo(handle, &mut info) == 0 { None } else { Some(info) } }; info.map(|inf| { Size { rows: (inf.srWindow.Bottom - inf.srWindow.Top + 1) as u16, cols: (inf.srWindow.Right - inf.srWindow.Left + 1) as u16, } }) } termsize-0.1.6/.cargo_vcs_info.json0000644000000001120000000000000127330ustar00{ "git": { "sha1": "ab5afe6a3f4debe9ed5303e9d0c9a84f24f0fab6" } }