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:
- Terminal identification:
- Window title management:
- Screen management:
- Scrolling:
- Cursor management:
SetCursor::Default
,SetCursor::BlinkingBlock
,SetCursor::SteadyBlock
,SetCursor::BlinkingUnderscore
,SetCursor::SteadyUnderscore
,SetCursor::BlinkingBar
, andSetCursor::SteadyBar
.HideCursor
andShowCursor
RequestCursorPosition
- Relative
MoveUp
,MoveDown
,MoveLeft
,MoveRight
,DynMoveUp
,DynMoveDown
,DynMoveLeft
, andDynMoveRight
- Absolute
MoveToColumn
,MoveToRow
,MoveTo
,DynMoveToColumn
,DynMoveToRow
, andDynMoveTo
SaveCursorPosition
andRestoreCursorPosition
- Managing content:
EraseLine
andEraseRestOfLine
BeginBatch
andEndBatch
to group updatesRequestBatchMode
BeginPaste
andEndPaste
to perform bracketed paste operationsDynLink
to add hyperlinks
- Styling content:
ResetStyle
RequestActiveStyle
SetDefaultForeground
,SetForeground8
,SetForeground24
,DynSetForeground8
, andDynSetForeground24
SetDefaultBackground
,SetBackground8
,SetBackground24
,DynSetBackground8
, andDynSetBackground24
Format::Bold
,Format::Thin
, andFormat::Regular
Format::Italic
andFormat::Upright
Format::Underlined
andFormat::NotUnderlined
Format::Blinking
andFormat::NotBlinking
Format::Reversed
andFormat::NotReversed
Format::Hidden
andFormat::NotHidden
Format::NotStricken
andFormat::NotStricken
RequestColor::Black
,RequestColor::Red
, and so on for all 16 ANSI colors, alsoRequestColor::Foreground
,RequestColor::Background
,RequestColor::Cursor
, andRequestColor::Selection
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 indeed 😜
Structs§
- The unit
BeginBatch
command. - The unit
BeginPaste
command. - The unit
DisableReverseMode
command. - The dynamic
DynLink(ID, HREF, TEXT)
command. - The dynamic
DynMoveDown(ROWS)
command. - The dynamic
DynMoveLeft(COLUMNS)
command. - The dynamic
DynMoveRight(COLUMNS)
command. - The dynamic
DynMoveTo(ROW, COLUMN)
command. - The dynamic
DynMoveToColumn(COLUMN)
command. - The dynamic
DynMoveToRow(ROW)
command. - The dynamic
DynMoveUp(ROWS)
command. - The dynamic
DynScrollDown(ROWS)
command. - The dynamic
DynScrollUp(ROWS)
command. - The dynamic
DynSetBackground8(COLOR)
command. - The dynamic
DynSetBackground24(R, G, B)
command. - The dynamic
DynSetForeground8(COLOR)
command. - The dynamic
DynSetForeground24(R, G, B)
command. - The dynamic
DynSetScrollRegion(TOP, BOTTOM)
command. - The dynamic
DynSetWindowTitle(String)
command. - The unit
EnableReverseMode
command. - The unit
EndBatch
command. - The unit
EndPaste
command. - The unit
EnterAlternateScreen
command. - The unit
EraseLine
command. - The unit
EraseRestOfLine
command. - The unit
EraseScreen
command. - The unit
ExitAlternateScreen
command. - The unit
HideCursor
command. - The static
MoveDown<ROWS>
command. - The static
MoveLeft<COLUMNS>
command. - The static
MoveRight<COLUMNS>
command. - The static
MoveTo<ROW, COLUMN>
command. - The static
MoveToColumn<COLUMN>
command. - The static
MoveToRow<ROW>
command. - The static
MoveUp<ROWS>
command. - The unit
RequestActiveStyle
command. - The unit
RequestBatchMode
command. - The unit
RequestCursorPosition
command. - The unit
RequestScreenSize
command. - The unit
RequestTerminalId
command. - The unit
ResetScrollRegion
command. - The unit
ResetStyle
command. - The unit
RestoreCursorPosition
command. - The unit
RestoreWindowTitle
command. - The unit
SaveCursorPosition
command. - The unit
SaveWindowTitle
command. - The static
ScrollDown<ROWS>
command. - The static
ScrollUp<ROWS>
command. - The static
SetBackground8<COLOR>
command. - The static
SetBackground24<R, G, B>
command. - The unit
SetDefaultBackground
command. - The unit
SetDefaultForeground
command. - The static
SetForeground8<COLOR>
command. - The static
SetForeground24<R, G, B>
command. - The static
SetScrollRegion<TOP, BOTTOM>
command. - The unit
ShowCursor
command.
Enums§
- The current batch processing mode.
- The enumeration of unit
Format
commands. - The enumeration of unit
RequestColor
commands.