prettytty

Module cmd

Source
Expand description

A library of useful terminal commands.

This module provides a number of straight-forward struct and enum types that implement the Command trait and, where needed, also the Sgr and Query traits. Organized by topic, this library covers the following 84 commands:

Most commands are implemented by zero-sized unit structs and enum variants. Commands that require arguments may come in one or both of two flavors, a static flavor relying on const generics and a dynamic flavor storing the arguments. The command name for the latter flavor starts with Dyn; it obviously is not zero-sized.

If a command name starts with Request, it also implements the Query trait and hence knows how to parse the response’s payload. When implementing your own queries, you may find util::ByteParser useful.

You can easily combine several commands into a compound command with the fuse! and fuse_sgr! macros.

§Example

Executing a command is as simple as writing its display:

println!(
    "{}Wow!{}",
    fuse_sgr!(Format::Bold, Format::Underlined, SetForeground8::<124>),
    ResetStyle
);

The invocation of the fuse_sgr! macro in the above example is not strictly necessary. Separately writing Format::Bold, Format::Underlined, and SetForeground8::<124> to the console would set the same style. However, that would also write three distinct ANSI escape sequences, whereas fuse_sgr! returns a value that writes only one ANSI escape sequence. After receiving the above text, the terminal prints wow!. Wow indeed 😜

Structs§

Enums§