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

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

#include <ConsoleLine.hh>

Classes

struct  Chunk
 

Public Member Functions

 ConsoleLine ()=default
 Construct empty line. More...
 
void clear ()
 Reinitialize to an empty line. More...
 
 ConsoleLine (std::string line, uint32_t rgb=0xffffffff)
 Construct line with a single color (by default white). More...
 
void addChunk (std::string_view text, uint32_t rgb=0xffffffff)
 Append a chunk with a (different) color. More...
 
void addLine (const ConsoleLine &ln)
 Append another line (possibly containing multiple chunks). More...
 
ConsoleLine splitAtColumn (unsigned column)
 Split this line at a given column number. 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...
 
std::string_view chunkText (size_t i) const
 Get the text for the i-th chunk. More...
 
const auto & getChunks () const
 

Detailed Description

This class represents a single text line in the console.

The line can have several chunks with different colors.

Definition at line 13 of file ConsoleLine.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 = 0xffffffff 
)
explicit

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

Definition at line 12 of file ConsoleLine.cc.

Member Function Documentation

◆ addChunk()

void openmsx::ConsoleLine::addChunk ( std::string_view  text,
uint32_t  rgb = 0xffffffff 
)

Append a chunk with a (different) color.

Definition at line 18 of file ConsoleLine.cc.

Referenced by splitAtColumn().

◆ addLine()

void openmsx::ConsoleLine::addLine ( const ConsoleLine ln)

Append another line (possibly containing multiple chunks).

Definition at line 24 of file ConsoleLine.cc.

References strAppend().

Referenced by openmsx::ImGuiConsole::paint().

◆ chunkColor()

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

Get the color for the i-th chunk.

Definition at line 77 of file ConsoleLine.cc.

◆ chunkText()

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

Get the text for the i-th chunk.

Definition at line 83 of file ConsoleLine.cc.

◆ clear()

void openmsx::ConsoleLine::clear ( )
inline

Reinitialize to an empty line.

Definition at line 20 of file ConsoleLine.hh.

Referenced by openmsx::ImGuiConsole::paint().

◆ getChunks()

const auto & openmsx::ConsoleLine::getChunks ( ) const
inline

Definition at line 53 of file ConsoleLine.hh.

◆ 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 72 of file ConsoleLine.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 47 of file ConsoleLine.hh.

◆ splitAtColumn()

ConsoleLine openmsx::ConsoleLine::splitAtColumn ( unsigned  column)

Split this line at a given column number.

This line will contain (up to) 'column' number of characters. The remainder of the line is returned, this could be an empty line.

Definition at line 40 of file ConsoleLine.cc.

References addChunk(), utf8::distance(), view::drop(), utf8::unchecked::next(), openmsx::ConsoleLine::Chunk::pos, and ranges::upper_bound().

Referenced by TEST_CASE().

◆ str()

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

Get the total string, ignoring color differences.

Definition at line 43 of file ConsoleLine.hh.


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