ratresume 0.1.0

A Rust library for reporting program-resume commands with OSC 7577
Documentation
# ratresume 🐀

[![Crates.io](https://img.shields.io/crates/v/ratresume?logo=rust)](https://crates.io/crates/ratresume)
[![Documentation](https://img.shields.io/docsrs/ratresume?logo=docsdotrs)](https://docs.rs/ratresume)
[![GitHub release](https://img.shields.io/github/v/release/orhun/ratresume?include_prereleases&logo=github)](https://github.com/orhun/ratresume/releases)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Ratatui](https://img.shields.io/badge/Ratatui-compatible-orange?logo=ratatui&logoColor=fff)](https://ratatui.rs)

A Rust library for reporting program-resume commands with [Program Resume Protocol (OSC 7577)](https://www.superlogical.com/rex/docs/build/program-resume).

```mermaid
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:

```bash
cargo add ratresume
```

Call [`Reporter::from_env`](https://docs.rs/ratresume/latest/ratresume/struct.Reporter.html#method.from_env)
to read `OSC7577_TOKEN`.  
Supporting terminals set this variable; if it is
missing, no report will be sent.

```rust,ignore
let mut reporter = ratresume::Reporter::from_env()?;
```

Describe how your app restores its saved state:

```rust,ignore
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`](https://docs.rs/ratresume/latest/ratresume/struct.Reporter.html#method.report) to send the resume command to the terminal:

```rust,ignore
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>`:

```rust
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`]./examples/ratatui.rs is a small counter app that saves its
  value and reports how to resume itself.

  Run it with:

  ```sh
  cargo run --example ratatui
  ```

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

## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md) for development checks and contribution guidelines.

Please report security issues through [GitHub Security Advisories](https://github.com/orhun/ratresume/security/advisories/new),
not public issues. See [SECURITY.md](./SECURITY.md) for details.

## License

Licensed under [The MIT License](./LICENSE).

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

## Copyright

Copyright © 2026, [Orhun Parmaksız](mailto:orhunparmaksiz@gmail.com)