openMSX
Public Member Functions | List of all members
openmsx::ConsoleLine Class Reference

This class represents a single text line in the console. More...

#include <CommandConsole.hh>

Public Member Functions

 ConsoleLine ()=default
 Construct empty line. More...
 
 ConsoleLine (std::string line, uint32_t rgb=0xffffff)
 Construct line with a single color (by default white). More...
 
void addChunk (string_view text, uint32_t rgb)
 Append a chunk with a (different) color. More...
 
size_t numChars () const
 Get the number of UTF8 characters in this line. More...
 
const std::string & str () const
 Get the total string, ignoring color differences. More...
 
size_t numChunks () const
 Get the number of different chunks. More...
 
uint32_t chunkColor (size_t i) const
 Get the color for the i-th chunk. More...
 
string_view chunkText (size_t i) const
 Get the text for the i-th chunk. More...
 
ConsoleLine substr (size_t pos, size_t len) const
 Get a part of total line. More...
 

Detailed Description

This class represents a single text line in the console.

The line can have several chunks with different colors.

Definition at line 22 of file CommandConsole.hh.

Constructor & Destructor Documentation

◆ ConsoleLine() [1/2]

openmsx::ConsoleLine::ConsoleLine ( )
default

Construct empty line.

◆ ConsoleLine() [2/2]

openmsx::ConsoleLine::ConsoleLine ( std::string  line,
uint32_t  rgb = 0xffffff 
)
explicit

Construct line with a single color (by default white).

Definition at line 32 of file CommandConsole.cc.

Member Function Documentation

◆ addChunk()

void openmsx::ConsoleLine::addChunk ( string_view  text,
uint32_t  rgb 
)

Append a chunk with a (different) color.

This is currently the only way to construct a multi-colored line/

Definition at line 38 of file CommandConsole.cc.

References string_view::data(), and string_view::size().

◆ chunkColor()

uint32_t openmsx::ConsoleLine::chunkColor ( size_t  i) const

Get the color for the i-th chunk.

Definition at line 49 of file CommandConsole.cc.

Referenced by numChunks(), and openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().

◆ chunkText()

string_view openmsx::ConsoleLine::chunkText ( size_t  i) const

Get the text for the i-th chunk.

Definition at line 55 of file CommandConsole.cc.

References string_view::npos, and string_view::substr().

Referenced by numChunks(), and openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().

◆ numChars()

size_t openmsx::ConsoleLine::numChars ( ) const

Get the number of UTF8 characters in this line.

So multi-byte characters are counted as a single character.

Definition at line 44 of file CommandConsole.cc.

References utf8::unchecked::size().

◆ numChunks()

size_t openmsx::ConsoleLine::numChunks ( ) const
inline

Get the number of different chunks.

Each chunk is a a part of the line that has the same color.

Definition at line 43 of file CommandConsole.hh.

References chunkColor(), chunkText(), and substr().

Referenced by openmsx::OSDConsoleRenderer::~OSDConsoleRenderer().

◆ str()

const std::string& openmsx::ConsoleLine::str ( ) const
inline

Get the total string, ignoring color differences.

Definition at line 39 of file CommandConsole.hh.

◆ substr()

ConsoleLine openmsx::ConsoleLine::substr ( size_t  pos,
size_t  len 
) const

Get a part of total line.

The result keeps the same colors as this line. E.g. used to get part of (long) line that should be wrapped over multiple console lines.

Parameters
posFirst character (multi-byte sequence counted as 1 character).
lenLength of the substring, also counted in characters

Definition at line 65 of file CommandConsole.cc.

References utf8::unchecked::advance(), begin(), end(), and utf8::unchecked::next().

Referenced by numChunks().


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