2020 html_root_url = "http://static.rust-lang.org/doc/master" ) ] ;
2121
2222#[ feature( macro_rules) ] ;
23+ #[ deny( missing_doc) ] ;
2324
2425extern crate collections;
2526
@@ -34,7 +35,9 @@ pub mod terminfo;
3435
3536// FIXME (#2807): Windows support.
3637
38+ /// Terminal color definitions
3739pub 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
5963pub 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.
106113pub struct Terminal < T > {
107114 priv num_colors : u16 ,
108115 priv out: T ,
109116 priv ti: ~TermInfo
110117}
111118
112119impl < 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
0 commit comments