pub struct Settings { /* private fields */ }Implementations§
Source§impl Settings
impl Settings
Sourcepub fn raw(self) -> Self
pub fn raw(self) -> Self
Convenience method to configure the terminal to be in “raw” mode
This method is roughly equivalent to the termios C API’s cfmakeraw() function. It configures the terminal
to stop responding to signals, perform no post, or input processing, and turns off echoing and canonical mode.
Examples found in repository?
examples/raw.rs (line 16)
6pub fn main() {
7 let term = Term::new().unwrap();
8
9 // save the terminal's settings
10 let settings = term.settings();
11
12 term.print("Entering raw mode...\n").unwrap();
13
14 // Clone the settings an add the necessary options for raw mode
15 // stop & start output can be confusing (usually they are Ctrl-S & Ctrl-Q) so disable them.
16 term.update(settings.clone().raw().stop_output('\0').start_output('\0'))
17 .unwrap();
18 term.print("Try pressing a few keys keys (Ctrl-C to quit): ")
19 .unwrap();
20
21 for key in term
22 .read_keys()
23 .map(Result::unwrap)
24 .take_while(|k| k != &Key::Control('C'))
25 {
26 term.save_cursor();
27 term.clear_line_after_cursor();
28 term.print(format!("{:?}", key)).unwrap();
29 term.flush();
30 term.restore_cursor();
31 }
32
33 // In raw mode '\n' will do nothing but move the cursor down a line,
34 // so the '\r' is necessary to move the cursor back to the start.
35 term.print("\n\r").unwrap();
36
37 // Revert back to the settings saved before entering raw mode
38 term.update(settings).unwrap();
39}Sourcepub fn char_size(self, x: u8) -> Self
pub fn char_size(self, x: u8) -> Self
Set the character size, x must be in the range 5-8 otherwise this method will panic
pub fn canonical(self, v: bool) -> Self
pub fn characters(self, v: u8) -> Self
pub fn timeout(self, v: u8) -> Self
pub fn flush(self, v: char) -> Self
pub fn eol(self, v: char) -> Self
pub fn erase(self, v: char) -> Self
pub fn interrupt(self, v: char) -> Self
pub fn suspend(self, v: char) -> Self
pub fn kill(self, v: char) -> Self
pub fn quit(self, v: char) -> Self
Sourcepub fn start_output(self, v: char) -> Self
pub fn start_output(self, v: char) -> Self
Examples found in repository?
examples/raw.rs (line 16)
6pub fn main() {
7 let term = Term::new().unwrap();
8
9 // save the terminal's settings
10 let settings = term.settings();
11
12 term.print("Entering raw mode...\n").unwrap();
13
14 // Clone the settings an add the necessary options for raw mode
15 // stop & start output can be confusing (usually they are Ctrl-S & Ctrl-Q) so disable them.
16 term.update(settings.clone().raw().stop_output('\0').start_output('\0'))
17 .unwrap();
18 term.print("Try pressing a few keys keys (Ctrl-C to quit): ")
19 .unwrap();
20
21 for key in term
22 .read_keys()
23 .map(Result::unwrap)
24 .take_while(|k| k != &Key::Control('C'))
25 {
26 term.save_cursor();
27 term.clear_line_after_cursor();
28 term.print(format!("{:?}", key)).unwrap();
29 term.flush();
30 term.restore_cursor();
31 }
32
33 // In raw mode '\n' will do nothing but move the cursor down a line,
34 // so the '\r' is necessary to move the cursor back to the start.
35 term.print("\n\r").unwrap();
36
37 // Revert back to the settings saved before entering raw mode
38 term.update(settings).unwrap();
39}Sourcepub fn stop_output(self, v: char) -> Self
pub fn stop_output(self, v: char) -> Self
Examples found in repository?
examples/raw.rs (line 16)
6pub fn main() {
7 let term = Term::new().unwrap();
8
9 // save the terminal's settings
10 let settings = term.settings();
11
12 term.print("Entering raw mode...\n").unwrap();
13
14 // Clone the settings an add the necessary options for raw mode
15 // stop & start output can be confusing (usually they are Ctrl-S & Ctrl-Q) so disable them.
16 term.update(settings.clone().raw().stop_output('\0').start_output('\0'))
17 .unwrap();
18 term.print("Try pressing a few keys keys (Ctrl-C to quit): ")
19 .unwrap();
20
21 for key in term
22 .read_keys()
23 .map(Result::unwrap)
24 .take_while(|k| k != &Key::Control('C'))
25 {
26 term.save_cursor();
27 term.clear_line_after_cursor();
28 term.print(format!("{:?}", key)).unwrap();
29 term.flush();
30 term.restore_cursor();
31 }
32
33 // In raw mode '\n' will do nothing but move the cursor down a line,
34 // so the '\r' is necessary to move the cursor back to the start.
35 term.print("\n\r").unwrap();
36
37 // Revert back to the settings saved before entering raw mode
38 term.update(settings).unwrap();
39}Sourcepub fn echo(self, v: bool) -> Self
pub fn echo(self, v: bool) -> Self
Examples found in repository?
examples/term.rs (line 28)
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 echo_newline(self, v: bool) -> Self
pub fn signals(self, v: bool) -> Self
pub fn flush_on_signal(self, v: bool) -> Self
pub fn input_processing(self, v: bool) -> Self
pub fn parity(self, v: bool) -> Self
pub fn odd_parity(self, v: bool) -> Self
pub fn hangup(self, v: bool) -> Self
pub fn ignore_modem_ctrl_lines(self, v: bool) -> Self
pub fn post_processing(self, v: bool) -> Self
pub fn make_output_carriage_return_newline(self, v: bool) -> Self
pub fn ignore_break(self, v: bool) -> Self
pub fn interrupt_on_break(self, v: bool) -> Self
pub fn ignore_frame_and_parity_errors(self, v: bool) -> Self
pub fn check_input_parity(self, v: bool) -> Self
pub fn strip_bit8(self, v: bool) -> Self
pub fn make_input_carriage_return_newline(self, v: bool) -> Self
pub fn make_input_newline_carriage_return(self, v: bool) -> Self
pub fn mark_bad_input(self, v: bool) -> Self
pub fn ignore_input_carriage_return(self, v: bool) -> Self
pub fn xon_xoff(self, v: bool) -> Self
pub fn utf8(self, v: bool) -> Self
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Settings
impl !RefUnwindSafe for Settings
impl Send for Settings
impl !Sync for Settings
impl Unpin for Settings
impl UnwindSafe for Settings
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more