MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / main

Function main

examples/termios.rs:5–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4#[cfg(all(not(windows), feature = "termios"))]
5fn main() -> std::io::Result<()> {
6 use rustix::termios::{tcgetattr, tcsetattr, OptionalActions};
7 use std::io::{Read as _, Write as _};
8
9 let tty = std::io::stdin();
10 let termios = tcgetattr(&tty)?;
11 println!("Original termios: {:?}", termios);
12
13 print!("Original settings; enter some text: ");
14 std::io::stdout().flush()?;
15 let mut buffer = String::new();
16 let _input = std::io::stdin().read_line(&mut buffer)?;
17
18 tcsetattr(&tty, OptionalActions::Flush, &termios)?;
19
20 print!("Reset original settings; enter some text: ");
21 std::io::stdout().flush()?;
22 let _input = std::io::stdin().read_line(&mut buffer)?;
23
24 let mut raw = termios.clone();
25 raw.make_raw();
26
27 println!("Raw termios: {:?}", raw);
28
29 tcsetattr(&tty, OptionalActions::Flush, &raw)?;
30
31 print!("Raw settings; press any key…");
32 std::io::stdout().flush()?;
33 let mut buf = [0_u8];
34 let _input = std::io::stdin().read(&mut buf)?;
35
36 tcsetattr(&tty, OptionalActions::Flush, &termios)?;
37 println!();
38
39 print!("Reset original settings again; enter some text: ");
40 std::io::stdout().flush()?;
41 let _input = std::io::stdin().read_line(&mut buffer)?;
42
43 Ok(())
44}
45
46#[cfg(any(windows, not(feature = "termios")))]
47fn main() -> Result<(), &'static str> {

Callers

nothing calls this directly

Calls 7

stdinFunction · 0.85
stdoutFunction · 0.85
cloneMethod · 0.80
make_rawMethod · 0.80
tcgetattrFunction · 0.50
tcsetattrFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected