Classes | Public Types | Public Member Functions | List of all members
rosbag_fancy::Terminal Class Reference

Encapsulates terminal control. More...

#include <terminal.h>

Classes

class  Parser
 Terminal escape sequence parser. More...
 

Public Types

enum  SimpleColor {
  Black, Red, Green, Yellow,
  Blue, Magenta, Cyan, White,
  IntenseBlack, IntenseRed, IntenseGreen, IntenseYellow,
  IntenseBlue, IntenseMagenta, IntenseCyan, IntenseWhite,
  Grayscale = 0xe8
}
 Simple colors. More...
 

Public Member Functions

void setBackgroundColor (uint32_t color)
 Set 24-bit background color. More...
 
void setBold (bool on)
 
void setCursorInvisible ()
 hide cursor More...
 
void setCursorVisible ()
 restore cursor More...
 
void setEcho (bool on)
 
void setForegroundColor (uint32_t color)
 Set 24-bit foreground color. More...
 
 Terminal ()
 

Set indexed foreground/background color

enum  SpecialKey {
  SK_F1 = 0x100, SK_F2, SK_F3, SK_F4,
  SK_F5, SK_F6, SK_F7, SK_F8,
  SK_F9, SK_F10, SK_F11, SK_F12,
  SK_Left, SK_Right, SK_Up, SK_Down,
  SK_Backspace
}
 
bool m_valid
 
bool m_256colors
 
bool m_truecolor
 
std::string m_bgColorStr
 
std::string m_fgColorStr
 
std::string m_opStr
 
std::string m_sgr0Str
 
std::string m_elStr
 
std::string m_upStr
 
std::string m_boldStr
 
std::map< std::string, SpecialKeym_specialKeys
 
std::string m_currentEscapeStr
 
std::chrono::steady_clock::time_point m_escapeStartTime
 
bool m_currentEscapeAborted = false
 
unsigned int m_currentEscapeAbortIdx = 0
 
void setSimpleBackground (SimpleColor color)
 
void setSimpleForeground (SimpleColor color)
 
void setSimplePair (SimpleColor fg, SimpleColor bg)
 
void setStandardColors ()
 Reset fg + bg to standard terminal colors. More...
 
void clearToEndOfLine ()
 Clear characters from cursor to end of line. More...
 
void moveCursorUp (int numLines)
 Move cursor up by numLines. More...
 
void moveCursorToStartOfLine ()
 Move cursor to start of the line. More...
 
bool getSize (int *columns, int *rows)
 Get current window size. More...
 
bool has256Colors () const
 
bool interactive () const
 
void setWindowTitle (const std::string &title)
 
void clearWindowTitle (const std::string &backup)
 
int readKey ()
 

Detailed Description

Encapsulates terminal control.

This class enables low-level manipulation of the terminal. It uses the ncurses/terminfo library internally to stay somewhat portable.

Definition at line 21 of file terminal.h.

Member Enumeration Documentation

◆ SimpleColor

Simple colors.

These colors can be used with the setSimpleForeground(), setSimpleBackground(), setSimplePair() methods.

Enumerator
Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 
IntenseBlack 
IntenseRed 
IntenseGreen 
IntenseYellow 
IntenseBlue 
IntenseMagenta 
IntenseCyan 
IntenseWhite 
Grayscale 

24-step grayscale starts here

Definition at line 30 of file terminal.h.

◆ SpecialKey

Enumerator
SK_F1 
SK_F2 
SK_F3 
SK_F4 
SK_F5 
SK_F6 
SK_F7 
SK_F8 
SK_F9 
SK_F10 
SK_F11 
SK_F12 
SK_Left 
SK_Right 
SK_Up 
SK_Down 
SK_Backspace 

Definition at line 164 of file terminal.h.

Constructor & Destructor Documentation

◆ Terminal()

rosbag_fancy::Terminal::Terminal ( )

Definition at line 122 of file terminal.cpp.

Member Function Documentation

◆ clearToEndOfLine()

void rosbag_fancy::Terminal::clearToEndOfLine ( )

Clear characters from cursor to end of line.

Definition at line 377 of file terminal.cpp.

◆ clearWindowTitle()

void rosbag_fancy::Terminal::clearWindowTitle ( const std::string &  backup)

Definition at line 424 of file terminal.cpp.

◆ getSize()

bool rosbag_fancy::Terminal::getSize ( int *  columns,
int *  rows 
)

Get current window size.

Returns
true on success

Definition at line 398 of file terminal.cpp.

◆ has256Colors()

bool rosbag_fancy::Terminal::has256Colors ( ) const

Returns whether the terminal supports 256 colors. If it does not suppport 256 colors, you should not use the setForegroundColor() / setBackgroundColor() functions.

Definition at line 241 of file terminal.cpp.

◆ interactive()

bool rosbag_fancy::Terminal::interactive ( ) const
inline

Terminal supports escape codes

Definition at line 157 of file terminal.h.

◆ moveCursorToStartOfLine()

void rosbag_fancy::Terminal::moveCursorToStartOfLine ( )

Move cursor to start of the line.

Definition at line 393 of file terminal.cpp.

◆ moveCursorUp()

void rosbag_fancy::Terminal::moveCursorUp ( int  numLines)

Move cursor up by numLines.

Definition at line 385 of file terminal.cpp.

◆ readKey()

int rosbag_fancy::Terminal::readKey ( )

Definition at line 432 of file terminal.cpp.

◆ setBackgroundColor()

void rosbag_fancy::Terminal::setBackgroundColor ( uint32_t  color)

Set 24-bit background color.

This automatically falls back to 256 colors if the terminal does not support true color.

Definition at line 275 of file terminal.cpp.

◆ setBold()

void rosbag_fancy::Terminal::setBold ( bool  on)

Definition at line 332 of file terminal.cpp.

◆ setCursorInvisible()

void rosbag_fancy::Terminal::setCursorInvisible ( )

hide cursor

Definition at line 246 of file terminal.cpp.

◆ setCursorVisible()

void rosbag_fancy::Terminal::setCursorVisible ( )

restore cursor

Definition at line 254 of file terminal.cpp.

◆ setEcho()

void rosbag_fancy::Terminal::setEcho ( bool  on)

Enable/disable automatic echo of keypresses

Definition at line 311 of file terminal.cpp.

◆ setForegroundColor()

void rosbag_fancy::Terminal::setForegroundColor ( uint32_t  color)

Set 24-bit foreground color.

This automatically falls back to 256 colors if the terminal does not support true color.

Definition at line 293 of file terminal.cpp.

◆ setSimpleBackground()

void rosbag_fancy::Terminal::setSimpleBackground ( SimpleColor  color)

Definition at line 350 of file terminal.cpp.

◆ setSimpleForeground()

void rosbag_fancy::Terminal::setSimpleForeground ( SimpleColor  color)

Definition at line 341 of file terminal.cpp.

◆ setSimplePair()

void rosbag_fancy::Terminal::setSimplePair ( SimpleColor  fg,
SimpleColor  bg 
)

Definition at line 359 of file terminal.cpp.

◆ setStandardColors()

void rosbag_fancy::Terminal::setStandardColors ( )

Reset fg + bg to standard terminal colors.

Definition at line 368 of file terminal.cpp.

◆ setWindowTitle()

void rosbag_fancy::Terminal::setWindowTitle ( const std::string &  title)

Definition at line 411 of file terminal.cpp.

Member Data Documentation

◆ m_256colors

bool rosbag_fancy::Terminal::m_256colors
private

Definition at line 176 of file terminal.h.

◆ m_bgColorStr

std::string rosbag_fancy::Terminal::m_bgColorStr
private

Definition at line 179 of file terminal.h.

◆ m_boldStr

std::string rosbag_fancy::Terminal::m_boldStr
private

Definition at line 185 of file terminal.h.

◆ m_currentEscapeAborted

bool rosbag_fancy::Terminal::m_currentEscapeAborted = false
private

Definition at line 191 of file terminal.h.

◆ m_currentEscapeAbortIdx

unsigned int rosbag_fancy::Terminal::m_currentEscapeAbortIdx = 0
private

Definition at line 192 of file terminal.h.

◆ m_currentEscapeStr

std::string rosbag_fancy::Terminal::m_currentEscapeStr
private

Definition at line 189 of file terminal.h.

◆ m_elStr

std::string rosbag_fancy::Terminal::m_elStr
private

Definition at line 183 of file terminal.h.

◆ m_escapeStartTime

std::chrono::steady_clock::time_point rosbag_fancy::Terminal::m_escapeStartTime
private

Definition at line 190 of file terminal.h.

◆ m_fgColorStr

std::string rosbag_fancy::Terminal::m_fgColorStr
private

Definition at line 180 of file terminal.h.

◆ m_opStr

std::string rosbag_fancy::Terminal::m_opStr
private

Definition at line 181 of file terminal.h.

◆ m_sgr0Str

std::string rosbag_fancy::Terminal::m_sgr0Str
private

Definition at line 182 of file terminal.h.

◆ m_specialKeys

std::map<std::string, SpecialKey> rosbag_fancy::Terminal::m_specialKeys
private

Definition at line 187 of file terminal.h.

◆ m_truecolor

bool rosbag_fancy::Terminal::m_truecolor
private

Definition at line 177 of file terminal.h.

◆ m_upStr

std::string rosbag_fancy::Terminal::m_upStr
private

Definition at line 184 of file terminal.h.

◆ m_valid

bool rosbag_fancy::Terminal::m_valid
private

Definition at line 175 of file terminal.h.


The documentation for this class was generated from the following files:


rosbag_fancy
Author(s):
autogenerated on Tue Feb 20 2024 03:20:59