Settings

Struct Settings 

Source
pub struct Settings { /* private fields */ }

Implementations§

Source§

impl Settings

Source

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}
Source

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

Source

pub fn canonical(self, v: bool) -> Self

Source

pub fn characters(self, v: u8) -> Self

Source

pub fn timeout(self, v: u8) -> Self

Source

pub fn flush(self, v: char) -> Self

Source

pub fn eol(self, v: char) -> Self

Source

pub fn erase(self, v: char) -> Self

Source

pub fn interrupt(self, v: char) -> Self

Source

pub fn suspend(self, v: char) -> Self

Source

pub fn kill(self, v: char) -> Self

Source

pub fn quit(self, v: char) -> Self

Source

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}
Source

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}
Source

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}
Source

pub fn echo_newline(self, v: bool) -> Self

Source

pub fn signals(self, v: bool) -> Self

Source

pub fn flush_on_signal(self, v: bool) -> Self

Source

pub fn input_processing(self, v: bool) -> Self

Source

pub fn parity(self, v: bool) -> Self

Source

pub fn odd_parity(self, v: bool) -> Self

Source

pub fn hangup(self, v: bool) -> Self

Source

pub fn ignore_modem_ctrl_lines(self, v: bool) -> Self

Source

pub fn post_processing(self, v: bool) -> Self

Source

pub fn make_output_carriage_return_newline(self, v: bool) -> Self

Source

pub fn ignore_break(self, v: bool) -> Self

Source

pub fn interrupt_on_break(self, v: bool) -> Self

Source

pub fn ignore_frame_and_parity_errors(self, v: bool) -> Self

Source

pub fn check_input_parity(self, v: bool) -> Self

Source

pub fn strip_bit8(self, v: bool) -> Self

Source

pub fn make_input_carriage_return_newline(self, v: bool) -> Self

Source

pub fn make_input_newline_carriage_return(self, v: bool) -> Self

Source

pub fn mark_bad_input(self, v: bool) -> Self

Source

pub fn ignore_input_carriage_return(self, v: bool) -> Self

Source

pub fn xon_xoff(self, v: bool) -> Self

Source

pub fn utf8(self, v: bool) -> Self

Trait Implementations§

Source§

impl Clone for Settings

Source§

fn clone(&self) -> Settings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.