termsize-0.1.6/.gitignore 0100644 0000765 0000024 00000000022 12542621645 0013570 0 ustar 00 0000000 0000000 target
Cargo.lock
termsize-0.1.6/.travis.yml 0100644 0000765 0000024 00000004336 13164005766 0013726 0 ustar 00 0000000 0000000 language: 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.yml 0100644 0000765 0000024 00000001035 13142233244 0014164 0 ustar 00 0000000 0000000 environment:
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.orig 0100644 0000765 0000024 00000001273 13461354331 0014474 0 ustar 00 0000000 0000000 [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.toml 0000644 00000002465 00000000000 0010746 0 ustar 00 # 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.md 0100644 0000765 0000024 00000001432 13461354513 0013415 0 ustar 00 0000000 0000000 # 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.rs 0100644 0000765 0000024 00000000132 13163777677 0014435 0 ustar 00 0000000 0000000 extern crate termsize;
pub fn main() {
println!("{:?}", termsize::get().unwrap());
}
termsize-0.1.6/LICENSE 0100644 0000765 0000024 00000002044 13164002125 0012576 0 ustar 00 0000000 0000000 Copyright (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.md 0100644 0000765 0000024 00000002405 13164002272 0013054 0 ustar 00 0000000 0000000 # termsize
[](https://travis-ci.org/softprops/termsize) [](https://ci.appveyor.com/project/softprops/termsize) [](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-2017 termsize-0.1.6/rustfmt.toml 0100644 0000765 0000024 00000000356 13163777744 0014227 0 ustar 00 0000000 0000000 # 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 = 80 termsize-0.1.6/src/lib.rs 0100644 0000765 0000024 00000001514 13164001537 0013503 0 ustar 00 0000000 0000000 #![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.rs 0100644 0000765 0000024 00000003760 13461354316 0013546 0 ustar 00 0000000 0000000 extern 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.rs 0100644 0000765 0000024 00000000315 13163777677 0014104 0 ustar 00 0000000 0000000 extern 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.rs 0100644 0000765 0000024 00000002416 13163777677 0013564 0 ustar 00 0000000 0000000 extern 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.json 0000644 00000000112 00000000000 0012733 0 ustar 00 {
"git": {
"sha1": "ab5afe6a3f4debe9ed5303e9d0c9a84f24f0fab6"
}
}