Skip to content

Documentation sprint: Terminfo documentation strings #12948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/libterm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
html_root_url = "http://static.rust-lang.org/doc/master")];

#[feature(macro_rules)];
#[deny(missing_doc)];

extern crate collections;

Expand All @@ -34,7 +35,9 @@ pub mod terminfo;

// FIXME (#2807): Windows support.

/// Terminal color definitions
pub mod color {
/// Number for a terminal color
pub type Color = u16;

pub static BLACK: Color = 0u16;
Expand All @@ -56,8 +59,10 @@ pub mod color {
pub static BRIGHT_WHITE: Color = 15u16;
}

/// Terminal attributes
pub mod attr {
/// Terminal attributes for use with term.attr().
///
/// Most attributes can only be turned on and must be turned off with term.reset().
/// The ones that can be turned off explicitly take a boolean value.
/// Color is also represented as an attribute for convenience.
Expand Down Expand Up @@ -103,13 +108,23 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
}
}

/// A Terminal that knows how many colors it supports, with a reference to its
/// parsed TermInfo database record.
pub struct Terminal<T> {
priv num_colors: u16,
priv out: T,
priv ti: ~TermInfo
}

impl<T: Writer> Terminal<T> {
/// Returns a wrapped output stream (`Terminal<T>`) as a `Result`.
///
/// Returns `Err()` if the TERM environment variable is undefined.
/// TERM should be set to something like `xterm-color` or `screen-256color`.
///
/// Returns `Err()` on failure to open the terminfo database correctly.
/// Also, in the event that the individual terminfo database entry can not
/// be parsed.
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
let term = match os::getenv("TERM") {
Some(t) => t,
Expand Down Expand Up @@ -143,8 +158,8 @@ impl<T: Writer> Terminal<T> {
/// If the color is a bright color, but the terminal only supports 8 colors,
/// the corresponding normal color will be used instead.
///
/// Returns Ok(true) if the color was set, Ok(false) otherwise, and Err(e)
/// if there was an I/O error
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
/// if there was an I/O error.
pub fn fg(&mut self, color: color::Color) -> io::IoResult<bool> {
let color = self.dim_if_necessary(color);
if self.num_colors > color {
Expand All @@ -166,8 +181,8 @@ impl<T: Writer> Terminal<T> {
/// If the color is a bright color, but the terminal only supports 8 colors,
/// the corresponding normal color will be used instead.
///
/// Returns Ok(true) if the color was set, Ok(false) otherwise, and Err(e)
/// if there was an I/O error
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
/// if there was an I/O error.
pub fn bg(&mut self, color: color::Color) -> io::IoResult<bool> {
let color = self.dim_if_necessary(color);
if self.num_colors > color {
Expand All @@ -186,8 +201,8 @@ impl<T: Writer> Terminal<T> {
}

/// Sets the given terminal attribute, if supported.
/// Returns Ok(true) if the attribute was supported, Ok(false) otherwise,
/// and Err(e) if there was an I/O error.
/// Returns `Ok(true)` if the attribute was supported, `Ok(false)` otherwise,
/// and `Err(e)` if there was an I/O error.
pub fn attr(&mut self, attr: attr::Attr) -> io::IoResult<bool> {
match attr {
attr::ForegroundColor(c) => self.fg(c),
Expand Down Expand Up @@ -223,6 +238,7 @@ impl<T: Writer> Terminal<T> {
}

/// Resets all terminal attributes and color to the default.
/// Returns `Ok()`.
pub fn reset(&mut self) -> io::IoResult<()> {
let mut cap = self.ti.strings.find_equiv(&("sgr0"));
if cap.is_none() {
Expand All @@ -248,10 +264,13 @@ impl<T: Writer> Terminal<T> {
} else { color }
}

/// Returns the contained stream
pub fn unwrap(self) -> T { self.out }

/// Gets an immutable reference to the stream inside
pub fn get_ref<'a>(&'a self) -> &'a T { &self.out }

/// Gets a mutable reference to the stream inside
pub fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.out }
}

Expand Down
7 changes: 5 additions & 2 deletions src/libterm/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[allow(missing_doc)];
//! Terminfo database interface.

use collections::HashMap;

/// A parsed terminfo entry.
/// A parsed terminfo database entry.
pub struct TermInfo {
/// Names for the terminal
priv names: Vec<~str> ,
Expand All @@ -25,7 +25,10 @@ pub struct TermInfo {
}

pub mod searcher;

/// TermInfo format parsing.
pub mod parser {
//! ncurses-compatible compiled terminfo format parsing (term(5))
pub mod compiled;
}
pub mod parm;
2 changes: 1 addition & 1 deletion src/libterm/terminfo/parm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ enum FormatState {
}

/// Types of parameters a capability can use
#[deriving(Clone)]
#[allow(missing_doc)]
#[deriving(Clone)]
pub enum Param {
String(~str),
Number(int)
Expand Down
2 changes: 1 addition & 1 deletion src/libterm/terminfo/parser/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#[allow(non_uppercase_statics)];

/// ncurses-compatible compiled terminfo format parsing (term(5))
//! ncurses-compatible compiled terminfo format parsing (term(5))

use collections::HashMap;
use std::io;
Expand Down
5 changes: 3 additions & 2 deletions src/libterm/terminfo/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/// Implement ncurses-compatible database discovery
/// Does not support hashed database, only filesystem!
//! ncurses-compatible database discovery
//!
//! Does not support hashed database, only filesystem!

use std::io::File;
use std::os::getenv;
Expand Down