11 releases

0.3.1 Oct 8, 2018
0.3.0 Dec 3, 2017
0.2.2 Jan 27, 2016
0.2.1 Nov 5, 2015
0.0.3 Mar 29, 2015

#28 in Command-line interface

Download history 26883/week @ 2019-12-02 27803/week @ 2019-12-09 28368/week @ 2019-12-16 16041/week @ 2019-12-23 22245/week @ 2019-12-30 35091/week @ 2020-01-06 33126/week @ 2020-01-13 33287/week @ 2020-01-20 35046/week @ 2020-01-27 28682/week @ 2020-02-03 25123/week @ 2020-02-10 23226/week @ 2020-02-17 24420/week @ 2020-02-24 25775/week @ 2020-03-02 25416/week @ 2020-03-09 25193/week @ 2020-03-16

107,887 downloads per month
Used in 551 crates (32 directly)

MIT license

56KB
972 lines

Termios Rust Bindings

The termios crate provides safe bindings for the Rust programming language to the terminal I/O interface implemented by Unix operating systems. The safe bindings are a small wrapper around the raw C functions, which converts integer return values to std::io::Result to indicate success or failure.

Dependencies

In order to use the termios crate, you must have a native libc library that implements the termios API. This should be available on any Unix operating system. This library contains the termios definitions for the following platforms:

  • Linux (x86_64, armv6l)
  • Android (x86)
  • OS X (x86_64)
  • FreeBSD (amd64)
  • OpenBSD (amd64)
  • DragonFly BSD (x86_64)

Usage

Add termios as a dependency in Cargo.toml:

[dependencies]
termios = "0.3"

Import the termios crate and any symbols needed from termios. You may also need std::os::unix::io::RawFd for file descriptors and std::io::Result to propagate errors.

extern crate termios;

use std::io;
use std::os::unix::io::RawFd;

use termios::*;

fn setup_fd(fd: RawFd) -> io::Result<()> {
  let mut termios = try!(Termios::from_fd(fd));

  termios.c_iflag = IGNPAR | IGNBRK;
  termios.c_oflag = 0;
  termios.c_cflag = CS8 | CREAD | CLOCAL;
  termios.c_lflag = 0;

  try!(cfsetspeed(&mut termios, B9600));
  try!(tcsetattr(fd, TCSANOW, &termios));
  try!(tcflush(fd, TCIOFLUSH));

  Ok(())
}

Contributors

License

Copyright © 2015 David Cuddeback

Distributed under the MIT License.

Dependencies