20
20
html_root_url = "http://static.rust-lang.org/doc/master" ) ] ;
21
21
22
22
#[ feature( macro_rules) ] ;
23
+ #[ deny( missing_doc) ] ;
23
24
24
25
extern crate collections;
25
26
@@ -34,7 +35,9 @@ pub mod terminfo;
34
35
35
36
// FIXME (#2807): Windows support.
36
37
38
+ /// Terminal color definitions
37
39
pub mod color {
40
+ /// Number for a terminal color
38
41
pub type Color = u16 ;
39
42
40
43
pub static BLACK : Color = 0u16 ;
@@ -56,8 +59,10 @@ pub mod color {
56
59
pub static BRIGHT_WHITE : Color = 15u16 ;
57
60
}
58
61
62
+ /// Terminal attributes
59
63
pub mod attr {
60
64
/// Terminal attributes for use with term.attr().
65
+ ///
61
66
/// Most attributes can only be turned on and must be turned off with term.reset().
62
67
/// The ones that can be turned off explicitly take a boolean value.
63
68
/// Color is also represented as an attribute for convenience.
@@ -103,13 +108,23 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
103
108
}
104
109
}
105
110
111
+ /// A Terminal that knows how many colors it supports, with a reference to its
112
+ /// parsed TermInfo database record.
106
113
pub struct Terminal < T > {
107
114
priv num_colors : u16 ,
108
115
priv out: T ,
109
116
priv ti: ~TermInfo
110
117
}
111
118
112
119
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.
113
128
pub fn new ( out : T ) -> Result < Terminal < T > , ~str > {
114
129
let term = match os:: getenv ( "TERM" ) {
115
130
Some ( t) => t,
@@ -143,8 +158,8 @@ impl<T: Writer> Terminal<T> {
143
158
/// If the color is a bright color, but the terminal only supports 8 colors,
144
159
/// the corresponding normal color will be used instead.
145
160
///
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.
148
163
pub fn fg ( & mut self , color : color:: Color ) -> io:: IoResult < bool > {
149
164
let color = self . dim_if_necessary ( color) ;
150
165
if self . num_colors > color {
@@ -166,8 +181,8 @@ impl<T: Writer> Terminal<T> {
166
181
/// If the color is a bright color, but the terminal only supports 8 colors,
167
182
/// the corresponding normal color will be used instead.
168
183
///
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.
171
186
pub fn bg ( & mut self , color : color:: Color ) -> io:: IoResult < bool > {
172
187
let color = self . dim_if_necessary ( color) ;
173
188
if self . num_colors > color {
@@ -186,8 +201,8 @@ impl<T: Writer> Terminal<T> {
186
201
}
187
202
188
203
/// 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.
191
206
pub fn attr ( & mut self , attr : attr:: Attr ) -> io:: IoResult < bool > {
192
207
match attr {
193
208
attr:: ForegroundColor ( c) => self . fg ( c) ,
@@ -223,6 +238,7 @@ impl<T: Writer> Terminal<T> {
223
238
}
224
239
225
240
/// Resets all terminal attributes and color to the default.
241
+ /// Returns `Ok()`.
226
242
pub fn reset ( & mut self ) -> io:: IoResult < ( ) > {
227
243
let mut cap = self . ti . strings . find_equiv ( & ( "sgr0" ) ) ;
228
244
if cap. is_none ( ) {
@@ -248,10 +264,13 @@ impl<T: Writer> Terminal<T> {
248
264
} else { color }
249
265
}
250
266
267
+ /// Returns the contained stream
251
268
pub fn unwrap ( self ) -> T { self . out }
252
269
270
+ /// Gets an immutable reference to the stream inside
253
271
pub fn get_ref < ' a > ( & ' a self ) -> & ' a T { & self . out }
254
272
273
+ /// Gets a mutable reference to the stream inside
255
274
pub fn get_mut < ' a > ( & ' a mut self ) -> & ' a mut T { & mut self . out }
256
275
}
257
276
0 commit comments