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
WindowsSpecific:Windows TerminalCMD/PowerShell
MacOSSpecific:Terminal.appITerm2KittyGhostty
- Other terminals:
AlacrittyWezTerm
- Editor terminals:
VSCodeNVIM
- Generic Linux Terminals
§Relaunching
WindowsOnly:Windows Terminal
MacOSOnly:ITerm2GhosttyKitty
- Cross-platform:
WezTermAlacritty
Modules§
Structs§
- Terminal
Identifier - Represents a terminal identifier, which consists of a terminal type and a set of signatures that can be used to identify that terminal.
- Terminal
Type Iter - An iterator over the variants of TerminalType
Enums§
- Operating
System - Represents the different target operating systems we can support.
- Target
Operating System - Represents a target operating system for a terminal signature.
- Terminal
Signature - Represents a kind of ‘signature’ that can be used to identify which terminal we are running in.
- Terminal
Type - 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§
- Terminal
Provider - 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
trueif 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 tofalse, 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 tofalse, 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
trueif 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.