Skip to content

Commit a6c14dd

Browse files
committed
Documentation sprint: Terminfo
1 parent 2c7f3b8 commit a6c14dd

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

src/libterm/lib.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
html_root_url = "http://static.rust-lang.org/doc/master")];
2121

2222
#[feature(macro_rules)];
23+
#[deny(missing_doc)];
2324

2425
extern crate collections;
2526

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

3536
// FIXME (#2807): Windows support.
3637

38+
/// Terminal color definitions
3739
pub mod color {
40+
/// Number for a terminal color
3841
pub type Color = u16;
3942

4043
pub static BLACK: Color = 0u16;
@@ -56,8 +59,10 @@ pub mod color {
5659
pub static BRIGHT_WHITE: Color = 15u16;
5760
}
5861

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

111+
/// A Terminal that knows how many colors it supports, with a reference to its
112+
/// parsed TermInfo database record.
106113
pub struct Terminal<T> {
107114
priv num_colors: u16,
108115
priv out: T,
109116
priv ti: ~TermInfo
110117
}
111118

112119
impl<T: Writer> Terminal<T> {
120+
/// Returns a wrapped output stream (`Terminal<T>`) as a `Result`.
121+
///
122+
/// Returns `Err()` if the TERM environment variable is undefined.
123+
/// TERM should be set to something like `xterm-color` or `screen-256color`.
124+
///
125+
/// Returns `Err()` on failure to open the terminfo database correctly.
126+
/// Also, in the event that the individual terminfo database entry can not
127+
/// be parsed.
113128
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
114129
let term = match os::getenv("TERM") {
115130
Some(t) => t,
@@ -143,8 +158,8 @@ impl<T: Writer> Terminal<T> {
143158
/// If the color is a bright color, but the terminal only supports 8 colors,
144159
/// the corresponding normal color will be used instead.
145160
///
146-
/// Returns Ok(true) if the color was set, Ok(false) otherwise, and Err(e)
147-
/// if there was an I/O error
161+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
162+
/// if there was an I/O error.
148163
pub fn fg(&mut self, color: color::Color) -> io::IoResult<bool> {
149164
let color = self.dim_if_necessary(color);
150165
if self.num_colors > color {
@@ -166,8 +181,8 @@ impl<T: Writer> Terminal<T> {
166181
/// If the color is a bright color, but the terminal only supports 8 colors,
167182
/// the corresponding normal color will be used instead.
168183
///
169-
/// Returns Ok(true) if the color was set, Ok(false) otherwise, and Err(e)
170-
/// if there was an I/O error
184+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
185+
/// if there was an I/O error.
171186
pub fn bg(&mut self, color: color::Color) -> io::IoResult<bool> {
172187
let color = self.dim_if_necessary(color);
173188
if self.num_colors > color {
@@ -186,8 +201,8 @@ impl<T: Writer> Terminal<T> {
186201
}
187202

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

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

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

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

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

src/libterm/terminfo/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[allow(missing_doc)];
11+
//! Terminfo database interface.
1212
1313
use collections::HashMap;
1414

15-
/// A parsed terminfo entry.
15+
/// A parsed terminfo database entry.
1616
pub struct TermInfo {
1717
/// Names for the terminal
1818
priv names: Vec<~str> ,
@@ -25,7 +25,10 @@ pub struct TermInfo {
2525
}
2626

2727
pub mod searcher;
28+
29+
/// TermInfo format parsing.
2830
pub mod parser {
31+
//! ncurses-compatible compiled terminfo format parsing (term(5))
2932
pub mod compiled;
3033
}
3134
pub mod parm;

src/libterm/terminfo/parm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ enum FormatState {
3838
}
3939

4040
/// Types of parameters a capability can use
41-
#[deriving(Clone)]
4241
#[allow(missing_doc)]
42+
#[deriving(Clone)]
4343
pub enum Param {
4444
String(~str),
4545
Number(int)

src/libterm/terminfo/parser/compiled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#[allow(non_uppercase_statics)];
1212

13-
/// ncurses-compatible compiled terminfo format parsing (term(5))
13+
//! ncurses-compatible compiled terminfo format parsing (term(5))
1414
1515
use collections::HashMap;
1616
use std::io;

src/libterm/terminfo/searcher.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/// Implement ncurses-compatible database discovery
12-
/// Does not support hashed database, only filesystem!
11+
//! ncurses-compatible database discovery
12+
//!
13+
//! Does not support hashed database, only filesystem!
1314
1415
use std::io::File;
1516
use std::os::getenv;

0 commit comments

Comments
 (0)