Skip to content
Snippets Groups Projects
Commit 54ce18f1 authored by Ticki's avatar Ticki
Browse files

Better documentation, fix TIOCGWINSZ

parent 34f1d6a4
No related branches found
No related tags found
No related merge requests found
extern crate libterm;
use libterm::terminal_size;
fn main() {
println!("Size is {:?}", terminal_size().unwrap())
}
......@@ -4,6 +4,9 @@ use {IntoRawMode, TerminalError};
/// Extension to `Read` trait.
pub trait ReadExt {
/// Read a password.
///
/// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will
/// complete the password input.
fn read_passwd<W: Write>(&mut self, writer: &mut W) -> Result<Option<String>, TerminalError>;
}
......
......@@ -18,8 +18,11 @@ pub use error::TerminalError;
mod raw;
pub use raw::{IntoRawMode, TerminalRestorer};
// TODO Redox terminal size
#[cfg(not(target_os = "redox"))]
mod size;
pub use size::termsize;
#[cfg(not(target_os = "redox"))]
pub use size::terminal_size;
mod color;
pub use color::Color;
......
......@@ -3,7 +3,7 @@ use libc::{c_ushort, STDOUT_FILENO};
use std::mem;
use termios::tiocgwinsz;
use termios::TIOCGWINSZ;
use TerminalError;
#[repr(C)]
......@@ -16,11 +16,11 @@ struct TermSize {
/// Get the size of the terminal. If the program isn't running in a terminal, it will return
/// `None`.
pub fn termsize() -> Result<(usize, usize), TerminalError> {
pub fn terminal_size() -> Result<(usize, usize), TerminalError> {
unsafe {
let mut size: TermSize = mem::zeroed();
if ioctl(STDOUT_FILENO, tiocgwinsz as u64, &mut size as *mut _) == 0 {
if ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut size as *mut _) == 0 {
Ok((size.col as usize, size.row as usize))
} else {
Err(TerminalError::TermSizeError)
......
use libc::{c_int, c_uint, c_uchar};
extern {
pub static tiocgwinsz: c_int;
#[cfg(not(target_os = "macos"))]
pub const TIOCGWINSZ: u64 = 0x00005413;
#[cfg(target_os = "macos")]
pub const TIOCGWINSZ: u64 = 0x40087468;
extern {
pub fn tcgetattr(filedes: c_int, termptr: *mut Termios) -> c_int;
pub fn tcsetattr(filedes: c_int, opt: c_int, termptr: *mut Termios) -> c_int;
pub fn cfmakeraw(termptr: *mut Termios);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment