Crate terminal_relaunch

Crate terminal_relaunch 

Source
Expand description

§Terminal Relaunch

A simple Rust library for detecting terminal capabilities and relaunching programs in better terminals with enhanced feature support, such as RGB ANSI colour and full Unicode rendering support for emojis.

§Quick Start

use terminal_relaunch::{relaunch_if_available_and_exit, CURRENT_TERMINAL};

fn main() {
    // Check if we should attempt to relaunch
    match relaunch_if_available_and_exit() {
        Ok(()) => println!("Terminal features met!"),
        Err(e) => eprintln!("Terminal could not relaunch: {e:?}"),
    }

    // Continue with your application..
    println!("Terminal information: {}", CURRENT_TERMINAL.verbose_format())
}

§Usage Examples

§Detect Current Terminal

use terminal_relaunch::CURRENT_TERMINAL;

println!("Terminal: {}", CURRENT_TERMINAL.verbose_format());

§Check Feature Support

use terminal_relaunch::{SUPPORTS_FULL_UNICODE, SUPPORTS_RGB_ANSI_COLOURS};

if *SUPPORTS_FULL_UNICODE {
    println!("✨ Unicode emojis work!");
}

if *SUPPORTS_RGB_ANSI_COLOURS {
    println!("\x1b[38;2;255;0;0mRGB colors work!\x1b[0m");
}

§Supported Terminals

§Detection

  • Windows Specific:
    • Windows Terminal
    • CMD/PowerShell
  • MacOS Specific:
    • Terminal.app
    • ITerm2
    • Kitty
    • Ghostty
  • Other terminals:
    • Alacritty
    • WezTerm
  • Editor terminals:
    • VSCode
    • NVIM
  • Generic Linux Terminals

§Relaunching

  • Windows Only:
    • Windows Terminal
  • MacOS Only:
    • ITerm2
    • Ghostty
    • Kitty
  • Cross-platform:
    • WezTerm
    • Alacritty

Modules§

errors
logging
terminal_providers

Structs§

TerminalIdentifier
Represents a terminal identifier, which consists of a terminal type and a set of signatures that can be used to identify that terminal.
TerminalTypeIter
An iterator over the variants of TerminalType

Enums§

OperatingSystem
Represents the different target operating systems we can support.
TargetOperatingSystem
Represents a target operating system for a terminal signature.
TerminalSignature
Represents a kind of ‘signature’ that can be used to identify which terminal we are running in.
TerminalType
Represents the different types of terminals we can identify.

Constants§

RELAUNCHED_ARGUMENT
Argument passed to relaunched terminals to indicate a relaunch has occurred.

Statics§

CURRENT_TERMINAL
The current terminal type detected at runtime.
SUPPORTS_FULL_UNICODE
If the current terminal supports full unicode rendering.
SUPPORTS_RGB_ANSI_COLOURS
If the current terminal supports full RGB (ANSI) colours.

Traits§

TerminalProvider
A trait for terminal providers that can supply terminal types, check installation status and relaunch the program in their terminal.

Functions§

find_alternative_terminal
Returns an alternative preferred terminal provider, if one is found and installed.
find_current_terminal
Attempts to identify the current terminal type based on a list of known terminal identification signatures.
get_all_terminal_identifiers
Returns an iterator over possible terminal identifiers.
get_default_terminal_for_os
Returns the default terminal type for a given operating system.
get_possible_terminal_identifiers_for
Returns an iterator over possible terminal identifiers for the given operating system.
get_preferred_terminals_for_os
Returns an iterator over possible preferred terminals for the given operating system.
get_provider_for_terminal
Returns a terminal provider for the given terminal type, if available.
has_been_relaunched
Returns true if the current program has been relaunched by the library in a new terminal already.
is_only_try_preferred_terminal
Gets whether we should only try to relaunch in the preferred terminal type. If set to true, only the preferred terminal will be considered for relaunching. If set to false, if we try to relaunch in the preferred terminal and it is not available, we will attempt to find any other preferred terminal that is available.
is_rgb_ansi_overridden
Reads the current override for rgb (ANSI) colour support detection.
is_unicode_overridden
Reads the current override for full unicode support detection.
preferred_terminal
Get the currently set preferred terminal type, if any.
relaunch_if_available
Attempts to relaunch the current program in a preferred terminal, if we have not already relaunched the application, and if the current terminal does not meet the preferred terminal requirements, i.e. full unicode and RGB (ANSI) colour support. and an alternative preferred terminal is found and installed.
relaunch_if_available_and_exit
Attempts to relaunch the current program in a preferred terminal, if we have not already relaunched the application, and if the current terminal does not meet the preferred terminal requirements, i.e. full unicode and RGB (ANSI) colour support. and an alternative preferred terminal is found and installed.
relaunch_if_available_and_exit_with
Attempts to relaunch the current program in a preferred terminal, if we have not already relaunched the application, and if the current terminal does not meet the preferred terminal requirements, i.e. full unicode and RGB (ANSI) colour support. and an alternative preferred terminal is found and installed.
set_only_try_preferred_terminal
Sets whether we should only try to relaunch in the preferred terminal type. If set to true, only the preferred terminal will be considered for relaunching. If set to false, if we try to relaunch in the preferred terminal and it is not available, we will attempt to find any other preferred terminal that is available.
set_preferred_terminal
Sets a preferred terminal type to use for relaunching, if available.
set_rgb_ansi_override
Overrides the detected RGB (ANSI) colour support for the current terminal.
set_unicode_support_override
Overrides the detected full unicode support for the current terminal.
should_attempt_relaunch
Returns true if we should attempt to find and relaunch in a preferred terminal.
try_relaunch_in_preferred_terminal
Attempts to relaunch the current program in a preferred terminal, if one is found and installed.