Skip to main content

Crate ratresume

Crate ratresume 

Source
Expand description

§ratresume 🐀

Crates.io Documentation GitHub release License: MIT Ratatui

A Rust library for reporting program-resume commands with Program Resume Protocol (OSC 7577).

flowchart LR
    App[Your TUI] -->|report command| Terminal[Terminal]
    Terminal -->|restart app| App

Q: What is this for?
A: ratresume allows your app to tell a supporting terminal how to restart your app with the same arguments and working directory after a terminal session is restored.

§Quick start

Add ratresume to your project:

cargo add ratresume

Call Reporter::from_env to read OSC7577_TOKEN.
Supporting terminals set this variable; if it is missing, no report will be sent.

ⓘ
let mut reporter = ratresume::Reporter::from_env()?;

Describe how your app restores its saved state:

ⓘ
let session_path = std::path::Path::new("/tmp/session.json");
let argv = vec![
    "my-tui".to_owned(),
    "--resume".to_owned(),
    session_path.to_string_lossy().into_owned(),
];
let cwd = std::env::current_dir()?;

Call Reporter::report to send the resume command to the terminal:

ⓘ
if let Some(reporter) = reporter.as_mut() {
    reporter.report(&argv, Some(&cwd))?;
}

A supporting terminal can use this command to restart your app with the same arguments and working directory when restoring the session.

§Usage

Here is a simple function that reports how to resume the current application with --resume <session_path>:

fn report_resume_command(
    session_path: &std::path::Path,
) -> Result<(), ratresume::Error> {
    let Some(mut reporter) = ratresume::Reporter::from_env()? else {
        return Ok(());
    };

    let executable = std::env::current_exe()?;
    let cwd = std::env::current_dir()?;
    let session_path = session_path.to_string_lossy().into_owned();
    let argv = vec![
        executable.to_string_lossy().into_owned(),
        "--resume".to_owned(),
        session_path,
    ];

    reporter.report(&argv, Some(&cwd))?;

    Ok(())
}

§Examples

  • ratatui.rs is a small counter app that saves its value and reports how to resume itself.

    Run it with:

    cargo run --example ratatui

    Use the arrow keys to change the counter and q to quit.

§Contributing

See CONTRIBUTING.md for development checks and contribution guidelines.

Please report security issues through GitHub Security Advisories, not public issues. See SECURITY.md for details.

§License

Licensed under The MIT License.

🦀 ノ( º _ º ノ) - respect crables!

Copyright © 2026, Orhun Parmaksız

Structs§

Reporter
Sends resume and clear reports to the terminal that launched this process.

Enums§

Error
Errors returned while preparing or writing an OSC 7577 report.

Constants§

TOKEN_ENV
Environment variable set by a terminal that supports OSC 7577.