6
6
//! a [terminfo][ti] database, and `WinConsole`, which uses the [Win32 Console
7
7
//! API][win].
8
8
//!
9
- //! ```
10
- //!
11
9
//! [ansi]: https://en.wikipedia.org/wiki/ANSI_escape_code
12
10
//! [win]: https://docs.microsoft.com/en-us/windows/console/character-mode-applications
13
11
//! [ti]: https://en.wikipedia.org/wiki/Terminfo
14
12
15
13
#![ deny( missing_docs) ]
16
14
17
- use std:: io:: prelude:: * ;
18
- use std:: io:: { self , Stderr , Stdout } ;
15
+ use std:: io:: { self , prelude:: * } ;
19
16
20
- pub use terminfo:: TerminfoTerminal ;
17
+ pub ( crate ) use terminfo:: TerminfoTerminal ;
21
18
#[ cfg( windows) ]
22
- pub use win:: WinConsole ;
19
+ pub ( crate ) use win:: WinConsole ;
23
20
24
- pub mod terminfo;
21
+ pub ( crate ) mod terminfo;
25
22
26
23
#[ cfg( windows) ]
27
24
mod win;
28
25
29
26
/// 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 ;
33
28
34
29
#[ cfg( not( windows) ) ]
35
30
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
36
31
/// opened.
37
- pub fn stdout ( ) -> Option < Box < StdoutTerminal > > {
32
+ pub ( crate ) fn stdout ( ) -> Option < Box < StdoutTerminal > > {
38
33
TerminfoTerminal :: new ( io:: stdout ( ) ) . map ( |t| Box :: new ( t) as Box < StdoutTerminal > )
39
34
}
40
35
41
36
#[ cfg( windows) ]
42
37
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
43
38
/// opened.
44
- pub fn stdout ( ) -> Option < Box < StdoutTerminal > > {
39
+ pub ( crate ) fn stdout ( ) -> Option < Box < StdoutTerminal > > {
45
40
TerminfoTerminal :: new ( io:: stdout ( ) )
46
41
. map ( |t| Box :: new ( t) as Box < StdoutTerminal > )
47
42
. or_else ( || WinConsole :: new ( io:: stdout ( ) ) . ok ( ) . map ( |t| Box :: new ( t) as Box < StdoutTerminal > ) )
48
43
}
49
44
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
-
66
45
/// Terminal color definitions
67
46
#[ allow( missing_docs) ]
68
- pub mod color {
47
+ #[ cfg_attr( not( windows) , allow( dead_code) ) ]
48
+ pub ( crate ) mod color {
69
49
/// 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 ;
118
60
}
119
61
120
62
/// A terminal with similar capabilities to an ANSI Terminal
121
63
/// (foreground/background colors etc).
122
64
pub trait Terminal : Write {
123
- /// The terminal's output writer type.
124
- type Output : Write ;
125
-
126
65
/// Sets the foreground color to the given color.
127
66
///
128
67
/// If the color is a bright color, but the terminal only supports 8 colors,
@@ -132,23 +71,6 @@ pub trait Terminal: Write {
132
71
/// if there was an I/O error.
133
72
fn fg ( & mut self , color : color:: Color ) -> io:: Result < bool > ;
134
73
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
-
152
74
/// Resets all terminal attributes and colors to their defaults.
153
75
///
154
76
/// Returns `Ok(true)` if the terminal was reset, `Ok(false)` otherwise, and `Err(e)` if there
@@ -160,15 +82,4 @@ pub trait Terminal: Write {
160
82
/// else that might flush stdout's buffer (e.g., writing a line of text), you should flush after
161
83
/// calling reset.
162
84
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 ;
174
85
}
0 commit comments