StdioTerminal

Struct StdioTerminal 

Source
pub struct StdioTerminal { /* private fields */ }
Expand description

Unix terminal using stdin/stdout with termios.

Provides a Terminal implementation for Unix-like systems (Linux, macOS, BSD) using standard input/output with termios for raw mode and ANSI escape sequences for cursor control.

§Examples

use editline::terminals::StdioTerminal;

let terminal = StdioTerminal::new();

Implementations§

Source§

impl StdioTerminal

Source

pub fn new() -> Self

Creates a new Unix terminal using stdin/stdout.

The terminal starts in normal mode. Call Terminal::enter_raw_mode to enable character-by-character input.

Examples found in repository?
examples/simple_repl.rs (line 14)
6fn main() {
7    println!("Simple REPL - Type something and press Enter");
8    println!("Type 'exit' or press Ctrl-D to quit");
9    println!("Features: line editing, history (up/down), word navigation (Ctrl+arrows)");
10    println!("Press Ctrl-C to cancel current line");
11    println!();
12
13    let mut editor = LineEditor::new(1024, 50);
14    let mut terminal = StdioTerminal::new();
15
16    loop {
17        print!("> ");
18        std::io::Write::flush(&mut std::io::stdout()).unwrap();
19
20        match editor.read_line(&mut terminal) {
21            Ok(line) => {
22                if line == "exit" {
23                    println!("Goodbye!");
24                    break;
25                } else if !line.is_empty() {
26                    println!("typed: {}", line);
27                }
28            }
29            Err(e) => {
30                // Handle Ctrl-C and Ctrl-D
31                match e {
32                    editline::Error::Eof => {
33                        // Ctrl-D pressed - exit gracefully
34                        println!("\nGoodbye!");
35                        break;
36                    }
37                    editline::Error::Interrupted => {
38                        // Ctrl-C pressed - show message and continue
39                        println!("\nInterrupted. Type 'exit' or press Ctrl-D to quit.");
40                        continue;
41                    }
42                    _ => {
43                        eprintln!("\nError reading input: {}", e);
44                        break;
45                    }
46                }
47            }
48        }
49    }
50}

Trait Implementations§

Source§

impl Default for StdioTerminal

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for StdioTerminal

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Terminal for StdioTerminal

Source§

fn read_byte(&mut self) -> Result<u8>

Reads a single byte from the input source. Read more
Source§

fn write(&mut self, data: &[u8]) -> Result<()>

Writes raw bytes to the output. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes any buffered output. Read more
Source§

fn enter_raw_mode(&mut self) -> Result<()>

Enters raw mode for character-by-character input. Read more
Source§

fn exit_raw_mode(&mut self) -> Result<()>

Exits raw mode and restores normal terminal settings. Read more
Source§

fn cursor_left(&mut self) -> Result<()>

Moves the cursor left by one position. Read more
Source§

fn cursor_right(&mut self) -> Result<()>

Moves the cursor right by one position. Read more
Source§

fn clear_eol(&mut self) -> Result<()>

Clears from the cursor position to the end of the line. Read more
Source§

fn parse_key_event(&mut self) -> Result<KeyEvent>

Parses the next key event from input. 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.