Crate unsegen_terminal

Source
Expand description

A pluggable unsegen ANSI terminal.

§Examples:

extern crate unsegen;
use std::io::stdout;

use unsegen::base;
use unsegen::widget::{RenderingHints, Widget};
use unsegen::container::Container;

use unsegen_terminal::{SlaveInputSink, Terminal};

use std::sync::mpsc;

struct MpscSlaveInputSink(mpsc::Sender<Box<[u8]>>);

impl SlaveInputSink for MpscSlaveInputSink {
    fn receive_bytes_from_pty(&mut self, data: Box<[u8]>) {
        self.0.send(data).unwrap();
    }
}

fn main() {
    let stdout = stdout();

    let (pty_sink, pty_src) = mpsc::channel();

    let mut term = base::Terminal::new(stdout.lock()).unwrap();

    let mut term_widget = Terminal::new(MpscSlaveInputSink(pty_sink)).unwrap();
    println!("Created pty: {}", term_widget.slave_name().to_str().unwrap());

    while let Ok(bytes) = pty_src.recv() {
        // Read input and do further processing here...

        // When you write to the created pty, the input should appear on screen!
        term_widget.add_byte_input(&bytes);
        {
            let win = term.create_root_window();

            // Only required because Parameter C cannot be infered. Probably not required in a
            // real application
            let term_widget: &dyn Container<()> = &term_widget;

            term_widget.as_widget().draw(win, RenderingHints::default());
        }
        term.present();
    }
}

Structs§

  • An unsegen Behavior that passes all (raw!) inputs through to the modelled terminal.
  • unsegen Widget that models a pseudoterminal and displays its contents to the window when drawn.

Traits§

  • Implement this trait by forwarding all received bytes to your main loop (somehow, for example using using chan). Then, in the main loop call Terminal::add_byte_input and update the screen.