66//! a [terminfo][ti] database, and `WinConsole`, which uses the [Win32 Console
77//! API][win].
88//!
9- //! ```
10- //!
119//! [ansi]: https://en.wikipedia.org/wiki/ANSI_escape_code
1210//! [win]: https://docs.microsoft.com/en-us/windows/console/character-mode-applications
1311//! [ti]: https://en.wikipedia.org/wiki/Terminfo
1412
1513#![ deny( missing_docs) ]
1614
17- use std:: io:: prelude:: * ;
18- use std:: io:: { self , Stderr , Stdout } ;
15+ use std:: io:: { self , prelude:: * } ;
1916
20- pub use terminfo:: TerminfoTerminal ;
17+ pub ( crate ) use terminfo:: TerminfoTerminal ;
2118#[ cfg( windows) ]
22- pub use win:: WinConsole ;
19+ pub ( crate ) use win:: WinConsole ;
2320
24- pub mod terminfo;
21+ pub ( crate ) mod terminfo;
2522
2623#[ cfg( windows) ]
2724mod win;
2825
2926/// Alias for stdout terminals.
30- pub type StdoutTerminal = dyn Terminal < Output = Stdout > + Send ;
31- /// Alias for stderr terminals.
32- pub type StderrTerminal = dyn Terminal < Output = Stderr > + Send ;
27+ pub ( crate ) type StdoutTerminal = dyn Terminal + Send ;
3328
3429#[ cfg( not( windows) ) ]
3530/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
3631/// opened.
37- pub fn stdout ( ) -> Option < Box < StdoutTerminal > > {
32+ pub ( crate ) fn stdout ( ) -> Option < Box < StdoutTerminal > > {
3833 TerminfoTerminal :: new ( io:: stdout ( ) ) . map ( |t| Box :: new ( t) as Box < StdoutTerminal > )
3934}
4035
4136#[ cfg( windows) ]
4237/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
4338/// opened.
44- pub fn stdout ( ) -> Option < Box < StdoutTerminal > > {
39+ pub ( crate ) fn stdout ( ) -> Option < Box < StdoutTerminal > > {
4540 TerminfoTerminal :: new ( io:: stdout ( ) )
4641 . map ( |t| Box :: new ( t) as Box < StdoutTerminal > )
4742 . or_else ( || WinConsole :: new ( io:: stdout ( ) ) . ok ( ) . map ( |t| Box :: new ( t) as Box < StdoutTerminal > ) )
4843}
4944
50- #[ cfg( not( windows) ) ]
51- /// Returns a Terminal wrapping stderr, or None if a terminal couldn't be
52- /// opened.
53- pub fn stderr ( ) -> Option < Box < StderrTerminal > > {
54- TerminfoTerminal :: new ( io:: stderr ( ) ) . map ( |t| Box :: new ( t) as Box < StderrTerminal > )
55- }
56-
57- #[ cfg( windows) ]
58- /// Returns a Terminal wrapping stderr, or None if a terminal couldn't be
59- /// opened.
60- pub fn stderr ( ) -> Option < Box < StderrTerminal > > {
61- TerminfoTerminal :: new ( io:: stderr ( ) )
62- . map ( |t| Box :: new ( t) as Box < StderrTerminal > )
63- . or_else ( || WinConsole :: new ( io:: stderr ( ) ) . ok ( ) . map ( |t| Box :: new ( t) as Box < StderrTerminal > ) )
64- }
65-
6645/// Terminal color definitions
6746#[ allow( missing_docs) ]
68- pub mod color {
47+ #[ cfg_attr( not( windows) , allow( dead_code) ) ]
48+ pub ( crate ) mod color {
6949 /// Number for a terminal color
70- pub type Color = u32 ;
71-
72- pub const BLACK : Color = 0 ;
73- pub const RED : Color = 1 ;
74- pub const GREEN : Color = 2 ;
75- pub const YELLOW : Color = 3 ;
76- pub const BLUE : Color = 4 ;
77- pub const MAGENTA : Color = 5 ;
78- pub const CYAN : Color = 6 ;
79- pub const WHITE : Color = 7 ;
80-
81- pub const BRIGHT_BLACK : Color = 8 ;
82- pub const BRIGHT_RED : Color = 9 ;
83- pub const BRIGHT_GREEN : Color = 10 ;
84- pub const BRIGHT_YELLOW : Color = 11 ;
85- pub const BRIGHT_BLUE : Color = 12 ;
86- pub const BRIGHT_MAGENTA : Color = 13 ;
87- pub const BRIGHT_CYAN : Color = 14 ;
88- pub const BRIGHT_WHITE : Color = 15 ;
89- }
90-
91- /// Terminal attributes for use with term.attr().
92- ///
93- /// Most attributes can only be turned on and must be turned off with term.reset().
94- /// The ones that can be turned off explicitly take a boolean value.
95- /// Color is also represented as an attribute for convenience.
96- #[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
97- pub enum Attr {
98- /// Bold (or possibly bright) mode
99- Bold ,
100- /// Dim mode, also called faint or half-bright. Often not supported
101- Dim ,
102- /// Italics mode. Often not supported
103- Italic ( bool ) ,
104- /// Underline mode
105- Underline ( bool ) ,
106- /// Blink mode
107- Blink ,
108- /// Standout mode. Often implemented as Reverse, sometimes coupled with Bold
109- Standout ( bool ) ,
110- /// Reverse mode, inverts the foreground and background colors
111- Reverse ,
112- /// Secure mode, also called invis mode. Hides the printed text
113- Secure ,
114- /// Convenience attribute to set the foreground color
115- ForegroundColor ( color:: Color ) ,
116- /// Convenience attribute to set the background color
117- BackgroundColor ( color:: Color ) ,
50+ pub ( crate ) type Color = u32 ;
51+
52+ pub ( crate ) const BLACK : Color = 0 ;
53+ pub ( crate ) const RED : Color = 1 ;
54+ pub ( crate ) const GREEN : Color = 2 ;
55+ pub ( crate ) const YELLOW : Color = 3 ;
56+ pub ( crate ) const BLUE : Color = 4 ;
57+ pub ( crate ) const MAGENTA : Color = 5 ;
58+ pub ( crate ) const CYAN : Color = 6 ;
59+ pub ( crate ) const WHITE : Color = 7 ;
11860}
11961
12062/// A terminal with similar capabilities to an ANSI Terminal
12163/// (foreground/background colors etc).
12264pub trait Terminal : Write {
123- /// The terminal's output writer type.
124- type Output : Write ;
125-
12665 /// Sets the foreground color to the given color.
12766 ///
12867 /// If the color is a bright color, but the terminal only supports 8 colors,
@@ -132,23 +71,6 @@ pub trait Terminal: Write {
13271 /// if there was an I/O error.
13372 fn fg ( & mut self , color : color:: Color ) -> io:: Result < bool > ;
13473
135- /// Sets the background color to the given color.
136- ///
137- /// If the color is a bright color, but the terminal only supports 8 colors,
138- /// the corresponding normal color will be used instead.
139- ///
140- /// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
141- /// if there was an I/O error.
142- fn bg ( & mut self , color : color:: Color ) -> io:: Result < bool > ;
143-
144- /// Sets the given terminal attribute, if supported. Returns `Ok(true)`
145- /// if the attribute was supported, `Ok(false)` otherwise, and `Err(e)` if
146- /// there was an I/O error.
147- fn attr ( & mut self , attr : Attr ) -> io:: Result < bool > ;
148-
149- /// Returns `true` if the given terminal attribute is supported.
150- fn supports_attr ( & self , attr : Attr ) -> bool ;
151-
15274 /// Resets all terminal attributes and colors to their defaults.
15375 ///
15476 /// Returns `Ok(true)` if the terminal was reset, `Ok(false)` otherwise, and `Err(e)` if there
@@ -160,15 +82,4 @@ pub trait Terminal: Write {
16082 /// else that might flush stdout's buffer (e.g., writing a line of text), you should flush after
16183 /// calling reset.
16284 fn reset ( & mut self ) -> io:: Result < bool > ;
163-
164- /// Gets an immutable reference to the stream inside
165- fn get_ref ( & self ) -> & Self :: Output ;
166-
167- /// Gets a mutable reference to the stream inside
168- fn get_mut ( & mut self ) -> & mut Self :: Output ;
169-
170- /// Returns the contained stream, destroying the `Terminal`
171- fn into_inner ( self ) -> Self :: Output
172- where
173- Self : Sized ;
17485}
0 commit comments