9 releases

0.1.8 Nov 28, 2024
0.1.7 Aug 11, 2023
0.1.1 Jul 28, 2023

#287 in Command-line interface

Download history 1/week @ 2024-08-25 1/week @ 2024-09-01 5/week @ 2024-09-29 13/week @ 2024-10-27 100/week @ 2024-11-24 27/week @ 2024-12-01

127 downloads per month

MIT/Apache

19KB
427 lines

term-detect

Terminal emulator detector

Implementation details

It works using 3 methods.

  1. TERMINAL environment variable
    The terminal is detected by reading the TERMINAL environment variable.
  2. DE (desktop environment) specific checks
    The terminal is detected by checking DE-specific config files.
  3. $PATH search
    The terminal from a list is picked if it's found in $PATH.

Examples

Run fish in private mode in a terminal window. Don't close the window when the command ends.

use std::process::Command;
use term_detect::{DetectionError, InTerminalAuto};

fn main() -> Result<(), DetectionError> {
    let child = Command::new("fish")
        .arg("--private")
        // Konsole-specific flag
        .in_terminal_args(["--noclose"])?
        .spawn()?
        .wait()?;
    Ok(())
}

Dependencies

~325–780KB
~17K SLoC