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 86
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§
- Begin
Batch - The unit
BeginBatch
command. - Begin
Paste - The unit
BeginPaste
command. - Disable
Autowrap - The unit
DisableAutowrap
command. - Disable
Reverse Mode - The unit
DisableReverseMode
command. - DynLink
- The dynamic
DynLink(ID, HREF, TEXT)
command. - DynMove
Down - The dynamic
DynMoveDown(ROWS)
command. - DynMove
Left - The dynamic
DynMoveLeft(COLUMNS)
command. - DynMove
Right - The dynamic
DynMoveRight(COLUMNS)
command. - DynMove
To - The dynamic
DynMoveTo(ROW, COLUMN)
command. - DynMove
ToColumn - The dynamic
DynMoveToColumn(COLUMN)
command. - DynMove
ToRow - The dynamic
DynMoveToRow(ROW)
command. - DynMove
Up - The dynamic
DynMoveUp(ROWS)
command. - DynScroll
Down - The dynamic
DynScrollDown(ROWS)
command. - DynScroll
Up - The dynamic
DynScrollUp(ROWS)
command. - DynSet
Background8 - The dynamic
DynSetBackground8(COLOR)
command. - DynSet
Background24 - The dynamic
DynSetBackground24(R, G, B)
command. - DynSet
Foreground8 - The dynamic
DynSetForeground8(COLOR)
command. - DynSet
Foreground24 - The dynamic
DynSetForeground24(R, G, B)
command. - DynSet
Scroll Region - The dynamic
DynSetScrollRegion(TOP, BOTTOM)
command. - DynSet
Window Title - The dynamic
DynSetWindowTitle(String)
command. - Enable
Autowrap - The unit
EnableAutowrap
command. - Enable
Reverse Mode - The unit
EnableReverseMode
command. - EndBatch
- The unit
EndBatch
command. - EndPaste
- The unit
EndPaste
command. - Enter
Alternate Screen - The unit
EnterAlternateScreen
command. - Erase
Line - The unit
EraseLine
command. - Erase
Rest OfLine - The unit
EraseRestOfLine
command. - Erase
Screen - The unit
EraseScreen
command. - Exit
Alternate Screen - The unit
ExitAlternateScreen
command. - Hide
Cursor - The unit
HideCursor
command. - Move
Down - The static
MoveDown<ROWS>
command. - Move
Left - The static
MoveLeft<COLUMNS>
command. - Move
Right - The static
MoveRight<COLUMNS>
command. - MoveTo
- The static
MoveTo<ROW, COLUMN>
command. - Move
ToColumn - The static
MoveToColumn<COLUMN>
command. - Move
ToRow - The static
MoveToRow<ROW>
command. - MoveUp
- The static
MoveUp<ROWS>
command. - Request
Active Style - The unit
RequestActiveStyle
command. - Request
Batch Mode - The unit
RequestBatchMode
command. - Request
Cursor Position - The unit
RequestCursorPosition
command. - Request
Screen Size - The unit
RequestScreenSize
command. - Request
Terminal Id - The unit
RequestTerminalId
command. - Reset
Scroll Region - The unit
ResetScrollRegion
command. - Reset
Style - The unit
ResetStyle
command. - Restore
Cursor Position - The unit
RestoreCursorPosition
command. - Restore
Window Title - The unit
RestoreWindowTitle
command. - Save
Cursor Position - The unit
SaveCursorPosition
command. - Save
Window Title - The unit
SaveWindowTitle
command. - Scroll
Down - The static
ScrollDown<ROWS>
command. - Scroll
Up - The static
ScrollUp<ROWS>
command. - SetBackground8
- The static
SetBackground8<COLOR>
command. - SetBackground24
- The static
SetBackground24<R, G, B>
command. - SetDefault
Background - The unit
SetDefaultBackground
command. - SetDefault
Foreground - The unit
SetDefaultForeground
command. - SetForeground8
- The static
SetForeground8<COLOR>
command. - SetForeground24
- The static
SetForeground24<R, G, B>
command. - SetScroll
Region - The static
SetScrollRegion<TOP, BOTTOM>
command. - Show
Cursor - The unit
ShowCursor
command.
Enums§
- Batch
Mode - The current batch processing mode.
- Format
- The enumeration of unit
Format
commands. - Request
Color - The enumeration of unit
RequestColor
commands. - SetCursor