Better documentation, fix TIOCGWINSZ
This commit is contained in:
parent
34f1d6a44c
commit
54ce18f17d
|
@ -0,0 +1,7 @@
|
|||
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)
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue