pub struct TermWriter<'a, O>{ /* private fields */ }Implementations§
Source§impl<'a, O> TermWriter<'a, O>
impl<'a, O> TermWriter<'a, O>
pub fn write_bytes(self, buf: &[u8]) -> Self
Sourcepub fn print<T: AsRef<str>>(self, s: T) -> Self
pub fn print<T: AsRef<str>>(self, s: T) -> Self
Examples found in repository?
5pub fn main() {
6 let term = Term::new().unwrap();
7
8 // save the terminal's settings
9 let settings = term.settings();
10
11 term.writer()
12 .bold()
13 .println("Demo Signup Form")
14 .println("")
15 .done()
16 .unwrap();
17
18 term.writer()
19 .foreground("green")
20 .print("\t--> ")
21 .print("Username: ")
22 .done()
23 .unwrap();
24
25 let name = term.readline().unwrap();
26
27 // Turn echo off to hide the password
28 term.update(settings.clone().echo(false)).unwrap();
29
30 term.writer()
31 .foreground("green")
32 .print("\t--> ")
33 .print("Password: ")
34 .done()
35 .unwrap();
36 let password = term.readline().unwrap();
37
38 term.println("");
39
40 term.writer()
41 .foreground("green")
42 .print("\t--> ")
43 .print("Password (Confirm): ")
44 .done()
45 .unwrap();
46 let password2 = term.readline().unwrap();
47
48 // restore the original settings
49 term.update(settings).unwrap();
50
51 term.println("");
52 term.println("");
53
54 if password != password2 {
55 term.writer()
56 .foreground("red")
57 .bold()
58 .println("Passwords don't match!")
59 .done()
60 .unwrap();
61 } else {
62 term.writer()
63 .foreground("cyan")
64 .print("Thank you, ")
65 .foreground("cyan")
66 .bold()
67 .println(name.trim())
68 .done()
69 .unwrap();
70 }
71}Sourcepub fn println<T: AsRef<str>>(self, s: T) -> Self
pub fn println<T: AsRef<str>>(self, s: T) -> Self
Examples found in repository?
5pub fn main() {
6 let term = Term::new().unwrap();
7
8 // save the terminal's settings
9 let settings = term.settings();
10
11 term.writer()
12 .bold()
13 .println("Demo Signup Form")
14 .println("")
15 .done()
16 .unwrap();
17
18 term.writer()
19 .foreground("green")
20 .print("\t--> ")
21 .print("Username: ")
22 .done()
23 .unwrap();
24
25 let name = term.readline().unwrap();
26
27 // Turn echo off to hide the password
28 term.update(settings.clone().echo(false)).unwrap();
29
30 term.writer()
31 .foreground("green")
32 .print("\t--> ")
33 .print("Password: ")
34 .done()
35 .unwrap();
36 let password = term.readline().unwrap();
37
38 term.println("");
39
40 term.writer()
41 .foreground("green")
42 .print("\t--> ")
43 .print("Password (Confirm): ")
44 .done()
45 .unwrap();
46 let password2 = term.readline().unwrap();
47
48 // restore the original settings
49 term.update(settings).unwrap();
50
51 term.println("");
52 term.println("");
53
54 if password != password2 {
55 term.writer()
56 .foreground("red")
57 .bold()
58 .println("Passwords don't match!")
59 .done()
60 .unwrap();
61 } else {
62 term.writer()
63 .foreground("cyan")
64 .print("Thank you, ")
65 .foreground("cyan")
66 .bold()
67 .println(name.trim())
68 .done()
69 .unwrap();
70 }
71}Sourcepub fn bold(self) -> Self
pub fn bold(self) -> Self
Examples found in repository?
5pub fn main() {
6 let term = Term::new().unwrap();
7
8 // save the terminal's settings
9 let settings = term.settings();
10
11 term.writer()
12 .bold()
13 .println("Demo Signup Form")
14 .println("")
15 .done()
16 .unwrap();
17
18 term.writer()
19 .foreground("green")
20 .print("\t--> ")
21 .print("Username: ")
22 .done()
23 .unwrap();
24
25 let name = term.readline().unwrap();
26
27 // Turn echo off to hide the password
28 term.update(settings.clone().echo(false)).unwrap();
29
30 term.writer()
31 .foreground("green")
32 .print("\t--> ")
33 .print("Password: ")
34 .done()
35 .unwrap();
36 let password = term.readline().unwrap();
37
38 term.println("");
39
40 term.writer()
41 .foreground("green")
42 .print("\t--> ")
43 .print("Password (Confirm): ")
44 .done()
45 .unwrap();
46 let password2 = term.readline().unwrap();
47
48 // restore the original settings
49 term.update(settings).unwrap();
50
51 term.println("");
52 term.println("");
53
54 if password != password2 {
55 term.writer()
56 .foreground("red")
57 .bold()
58 .println("Passwords don't match!")
59 .done()
60 .unwrap();
61 } else {
62 term.writer()
63 .foreground("cyan")
64 .print("Thank you, ")
65 .foreground("cyan")
66 .bold()
67 .println(name.trim())
68 .done()
69 .unwrap();
70 }
71}pub fn blink(self) -> Self
pub fn italics(self) -> Self
pub fn underline(self) -> Self
pub fn invisible(self) -> Self
pub fn standout(self) -> Self
pub fn dim(self) -> Self
pub fn clear(self) -> Self
Sourcepub fn done(self) -> Result<usize>
pub fn done(self) -> Result<usize>
Examples found in repository?
5pub fn main() {
6 let term = Term::new().unwrap();
7
8 // save the terminal's settings
9 let settings = term.settings();
10
11 term.writer()
12 .bold()
13 .println("Demo Signup Form")
14 .println("")
15 .done()
16 .unwrap();
17
18 term.writer()
19 .foreground("green")
20 .print("\t--> ")
21 .print("Username: ")
22 .done()
23 .unwrap();
24
25 let name = term.readline().unwrap();
26
27 // Turn echo off to hide the password
28 term.update(settings.clone().echo(false)).unwrap();
29
30 term.writer()
31 .foreground("green")
32 .print("\t--> ")
33 .print("Password: ")
34 .done()
35 .unwrap();
36 let password = term.readline().unwrap();
37
38 term.println("");
39
40 term.writer()
41 .foreground("green")
42 .print("\t--> ")
43 .print("Password (Confirm): ")
44 .done()
45 .unwrap();
46 let password2 = term.readline().unwrap();
47
48 // restore the original settings
49 term.update(settings).unwrap();
50
51 term.println("");
52 term.println("");
53
54 if password != password2 {
55 term.writer()
56 .foreground("red")
57 .bold()
58 .println("Passwords don't match!")
59 .done()
60 .unwrap();
61 } else {
62 term.writer()
63 .foreground("cyan")
64 .print("Thank you, ")
65 .foreground("cyan")
66 .bold()
67 .println(name.trim())
68 .done()
69 .unwrap();
70 }
71}pub fn err(&self) -> &Option<Error>
pub fn written(&self) -> usize
Sourcepub fn foreground<T: Into<Color>>(self, color: T) -> Self
pub fn foreground<T: Into<Color>>(self, color: T) -> Self
Set the terminal’s foreground color.
T a ansi::Color enum, a number (u8) or a string.
strings may name a color, or provide custom r, g, and b values.
Any of the following are valid:
- “black”
- “red”
- “green”
- “yellow”
- “blue”
- “magenta”
- “cyan”
- “grey”
- “white” (same as “bright grey”)
- “bright*” (
*may be any of the other named colors) - “#rrggbb”
- “#rgb”
- “rgb(r, g, b)”
Numbers are also valid, the number must fit inside a u8 (so it should be in the range 0-255).
§Compatibility
Everything layed out above will work as far as this library, but the chances of it actually being supported across any meaningful number of terminals is closed to 0.
§24-bit Colors
Full RGB (that is, 24-bit color) terminals are pretty rare. When full 24-bit colors are not supported, the color will get as close as it can with whatever the terminal provides.
§8-bit Colors
256 color terminals are fairly common, using depending on indices beyond 15 is still risky though.
§4/3-bit Colors
Basically all terminals will support 3-bits, many will support 4 (that 4th bit gives the option of a “bright” variant).
Examples found in repository?
5pub fn main() {
6 let term = Term::new().unwrap();
7
8 // save the terminal's settings
9 let settings = term.settings();
10
11 term.writer()
12 .bold()
13 .println("Demo Signup Form")
14 .println("")
15 .done()
16 .unwrap();
17
18 term.writer()
19 .foreground("green")
20 .print("\t--> ")
21 .print("Username: ")
22 .done()
23 .unwrap();
24
25 let name = term.readline().unwrap();
26
27 // Turn echo off to hide the password
28 term.update(settings.clone().echo(false)).unwrap();
29
30 term.writer()
31 .foreground("green")
32 .print("\t--> ")
33 .print("Password: ")
34 .done()
35 .unwrap();
36 let password = term.readline().unwrap();
37
38 term.println("");
39
40 term.writer()
41 .foreground("green")
42 .print("\t--> ")
43 .print("Password (Confirm): ")
44 .done()
45 .unwrap();
46 let password2 = term.readline().unwrap();
47
48 // restore the original settings
49 term.update(settings).unwrap();
50
51 term.println("");
52 term.println("");
53
54 if password != password2 {
55 term.writer()
56 .foreground("red")
57 .bold()
58 .println("Passwords don't match!")
59 .done()
60 .unwrap();
61 } else {
62 term.writer()
63 .foreground("cyan")
64 .print("Thank you, ")
65 .foreground("cyan")
66 .bold()
67 .println(name.trim())
68 .done()
69 .unwrap();
70 }
71}pub fn background<T: Into<Color>>(self, color: T) -> Self
pub fn shift_cursor(self, x: isize, y: isize) -> Self
pub fn default_background(self) -> Self
pub fn default_foreground(self) -> Self
Trait Implementations§
Source§impl<'a, O> Write for TermWriter<'a, O>
impl<'a, O> Write for TermWriter<'a, O>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)