Cross-platform pseudoterminal (PTY/ConPTY) implementation with async support

Overview

pseudoterminal

The pseudoterminal crate is a versatile pseudoterminal (PTY) implementation designed for Rust, offering asynchronous capabilities. This library provides a straightforward and efficient means to interact with child processes via pseudoterminals. Whether you're building interactive command-line applications, custom terminals, or automating terminal interactions, pseudoterminal is your reliable companion.

Warning

Some key features of this crate are not implemented yet such as complete windows support and non-blocking io.

Key Features

  • Cross-Platform Compatibility: Works seamlessly on both Windows and Unix-based systems, ensuring broad compatibility for your projects.
  • Asynchronous Support: Easily integrates with asynchronous programming paradigms using libraries like Tokio, enhancing your application's efficiency.
  • Terminal Size Manipulation: Provides methods for obtaining and modifying terminal dimensions, enabling dynamic terminal layout adjustments.

Getting Started

Installation

To include the pseudoterminal crate in your Rust project, simply add it as a dependency in your Cargo.toml:

[dependencies]
pseudoterminal = "0.1.0"

Example

Here's a basic example illustrating how to use the pseudoterminal crate to spawn a terminal process and engage with it interactively:

use pseudoterminal::CommandExt;
use std::io::{stdin, stdout, Read, Write};
use std::process::Command;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new pseudoterminal
    let mut cmd = Command::new("bash"); // Replace with your desired command
    let mut terminal = cmd.spawn_terminal()?;

    // Read from and write to the terminal
    let mut input_buffer = String::new();
    let mut output_buffer = [0u8; 1024];

    loop {
        // Read from user input or other sources
        stdin().read_line(&mut input_buffer)?;

        // Write input to the terminal
        terminal
            .termin
            .as_mut()
            .unwrap()
            .write_all(input_buffer.as_bytes())?;

        // Read output from the terminal
        let bytes_read = terminal
            .termout
            .as_mut()
            .unwrap()
            .read(&mut output_buffer)?;

        // Write read bytes to stdout
        stdout().write_all(&output_buffer[..bytes_read])?;
        stdout().flush()?;

        // Clear the input buffer
        input_buffer.clear();
    }
}

This example showcases how to spawn a terminal process using pseudoterminal, transmit input to it, and receive its output. You can effortlessly swap "bash" with any other command you wish to execute.

Documentation

For comprehensive documentation, including an in-depth API reference and practical usage examples, please consult the official documentation at https://docs.rs/pseudoterminal.

License

This crate is distributed under the permissive MIT License. For more details, please review the [LICENSE] file.

You might also like...
Cross-platform terminal screen clearing library

ClearScreen Cross-platform terminal screen clearing library. API documentation. Dual-licensed with Apache 2.0 and MIT. Uses Caretaker Maintainership.

Cross-platform terminal program to download IEEE journals
Cross-platform terminal program to download IEEE journals

IEEE Journal Downloader A cross-platform terminal program which tries to download every article in a specified journal and merge the documents into on

📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.
📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.

📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.

Native cross-platform full feature terminal-based sequence editor for git interactive rebase.
Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Cross-platform Rust rewrite of the GNU coreutils
Cross-platform Rust rewrite of the GNU coreutils

Cross-platform Rust rewrite of the GNU coreutils

Rust-battery - Rust crate providing cross-platform information about the notebook batteries.

battery Rust crate providing cross-platform information about the notebook batteries. Table of contents Overview Supported platforms Install Examples

Cross-platform CLI Rimworld Mod manager. Still under development

rwm Inspired by Spoons rmm. This is a cross-platform Mod Manager for RimWorld intended to work with macOS, linux and Windows Up to now, you must have

Build light & secure cross-platform applications with a web-based UI
Build light & secure cross-platform applications with a web-based UI

Millennium Icon by XFaon. *Stats are from Tauri and may not be fully accurate. Millennium is a cross-platform webview framework written in Rust. With

A cross-platform file sorting program

Cabinet Cross-platform file sorting system that sorts files based on their attributes, such as file type, file name and date modified. Disclaimer: Not

Comments
  • Update Cargo.toml add repository

    Update Cargo.toml add repository

    to allow crates.is, rust-digger, and others to link to it

    I build the Rust Digger to help Crate authors with some simple verifications. The list of your crates to see which one does not have the repository link yet. I hope it will help.

    opened by szabgab 0
Owner
Michael
No longer jobless Rustacean
Michael
Tricking shells into interactive mode when local PTY's are not available

Remote Pseudoterminals Remote Pseudoterminals or "RPTY" is a Rust library which intercepts calls to the Linux kernel's TTY/PTY-related libc functions

null 135 Dec 4, 2022
Cross-platform casting SDK, support Android, Windows, Linux

mirror Cross-platform casting SDK, support Android, Windows, Linux Low-latency transport protocols use [SRT](https://github.com/Haivision/srt) Video:

Lazy Panda 10 Feb 29, 2024
A cross platform, rust implementation for the Tegra X1 bootROM exploit

Switcheroo A CLI and GUI for the RCM BootRom exploit (Fusée Gelée exploit for Nintendo Switch) Only works on unpatched Switches: https://ismyswitchpat

Ethan Budd 35 Nov 5, 2022
A cross-platform implementation of Dirman in Rust.

A Directory Manager for Neorg The neorg-dirman crate is a core module which provides a basic interface for workspaces. Workspaces are the backbone of

Neorg 9 Mar 17, 2023
A minimal readline with multiline and async support

RustyLine Async A minimal readline with multiline and async support. Inspired by rustyline , async-readline & termion-async-input.

Zyansheep 16 Dec 15, 2022
Cross-platform Rust library for coloring and formatting terminal output

Coloring terminal output Documentation term-painter is a cross-platform (i.e. also non-ANSI terminals) Rust library for coloring and formatting termin

Lukas Kalbertodt 75 Jul 28, 2022
Cross platform terminal library rust

Cross-platform Terminal Manipulation Library Crossterm is a pure-rust, terminal manipulation library that makes it possible to write cross-platform te

crossterm-rs 2.1k Jan 2, 2023
A cross platform minimalistic text user interface

titik Titik is a crossplatform TUI widget library with the goal of being able to interact intuitively on these widgets. It uses crossterm as the under

Jovansonlee Cesar 113 Dec 31, 2022
Alacritty - A fast, cross-platform, OpenGL terminal emulator

Alacritty is a modern terminal emulator that comes with sensible defaults, but allows for extensive configuration. By integrating with other applications, rather than reimplementing their functionality, it manages to provide a flexible set of features with high performance. The supported platforms currently consist of BSD, Linux, macOS and Windows.

Alacritty 43.8k Dec 31, 2022
A cross-platform graphical process/system monitor with a customizable interface and a multitude of features

A cross-platform graphical process/system monitor with a customizable interface and a multitude of features. Supports Linux, macOS, and Windows. Inspired by both gtop and gotop.

Clement Tsang 5.8k Jan 8, 2023