Struct TerminalTermion

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

Implementations§

Source§

impl TerminalTermion

Source

pub fn new() -> Self

Examples found in repository?
examples/prompt.rs (line 9)
6fn main() {
7	let options = PromptBufferOptions { echo: true, ..Default::default() };
8	
9	let mut term = TerminalTermion::new();	
10	let mut prompt = PromptBuffer::new(options);
11	prompt.print_prompt(&mut term);
12
13	let mut counter = 1;
14	let mut switch = false;
15	
16	loop {
17
18		let key_result = prompt.handle_terminal_key(&mut term, |m| {
19			if let Some(mut m) = m.with_prefix("p3/") {
20				if let Some(mut ctx) = m.command("hello") {
21					ctx.get_terminal().print_line("Hello world - P3");
22				}
23
24				if let Some(mut ctx) = m.command("ping") {
25					ctx.get_terminal().print_line("Pong");
26				}
27
28				if let Some(mut m) = m.with_prefix("more/") {
29					if let Some(mut ctx) = m.command("here") {
30						ctx.get_terminal().print_line("Yep, here");
31					}
32				}
33			}
34
35			if let Some(mut ctx) = m.property("counter", validate_property_min_max(1, 100)) {
36				ctx.apply(&mut counter);
37			}
38			if let Some(mut ctx) = m.property("switch", ValueBool) {
39				ctx.apply(&mut switch);
40			}
41			if let Some(mut ctx) = m.command("p1/hello") {
42				ctx.get_terminal().print_line("Hello world - P1");
43			}
44			if let Some(mut ctx) = m.command("p1/s1/hello") {
45				ctx.get_terminal().print_line("Hello world - P1 S1");
46			}
47			if let Some(mut ctx) = m.command("p1/s1/reset") {
48				ctx.get_terminal().print_line("Reset.");
49			}
50			if let Some(mut ctx) = m.command("p2/hello") {
51				ctx.get_terminal().print_line("Hello world - P2");
52			}
53
54			if let Some(mut ctx) = m.command("lines") {
55				ctx.get_terminal().print_line("Line 1");
56				ctx.get_terminal().print_line("Line 2");
57				println!("Line 3");
58				println!("Line 4");
59			}
60		});
61
62		match key_result {
63			Ok(PromptEvent::Break) => {
64				break;
65			},
66			_ => ()
67		}
68	}
69
70	println!("Exit.");
71}

Trait Implementations§

Source§

impl CharacterTerminalReader for TerminalTermion

Source§

impl CharacterTerminalWriter for TerminalTermion

Source§

fn print(&mut self, bytes: &[u8])

Source§

fn print_str(&mut self, s: &str)

Source§

fn print_line(&mut self, s: &str)

Source§

fn write_str(&mut self, s: &str) -> Result<(), Error>

Source§

fn newline(&mut self)

Source§

fn print_newline_sequence(&mut self)

Source§

impl Drop for TerminalTermion

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Write for TerminalTermion

Source§

fn write_str(&mut self, s: &str) -> Result<(), FmtError>

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. 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> 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, 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.