libcsdbg  1.28
C++ exception (and generic) stack trace debug library
style & csdbg::style::to_string ( string dst) const
virtual

Set a string with all the style escape sequences.

Parameters
[in]dstthe destination string
Returns
*this
Exceptions
std::bad_alloc
csdbg::exception
Attention
Initial string contents are erased

Definition at line 260 of file style.cpp.

References csdbg::string::append(), BLINKING, BOLD, CLEAR, csdbg::string::clear(), DIM, HIDDEN, INVERTED, is_attr_enabled(), m_bgcolor, m_fgcolor, UNDERLINED, and unlikely.

Referenced by apply().

261 {
262  dst.clear();
263 
264  /* Add the background color, if not translucent */
265  if ( unlikely(m_bgcolor != CLEAR) )
266  dst.append("\e[48;5;%dm", m_bgcolor);
267 
268  /* Add the foreground color */
269  dst.append("\e[38;5;%dm", m_fgcolor);
270 
271  /* Add the escape sequence for each text formatting attribute */
272  if ( unlikely(is_attr_enabled(BOLD)) )
273  dst.append("\e[1m");
274 
275  if ( unlikely(is_attr_enabled(DIM)) )
276  dst.append("\e[2m");
277 
279  dst.append("\e[4m");
280 
282  dst.append("\e[5m");
283 
285  dst.append("\e[7m");
286 
288  dst.append("\e[8m");
289 
290  return const_cast<style&> (*this);
291 }
color_t m_bgcolor
Background color.
Definition: style.hpp:30
virtual bool is_attr_enabled(attrset_t) const
Check if a set of text formatting attributes is enabled.
Definition: style.cpp:222
style(const i8 *, color_t=WHITE, color_t=CLEAR, attrset_t=0)
Object constructor.
Definition: style.cpp:25
color_t m_fgcolor
Foreground (text) color.
Definition: style.hpp:28
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function:

+ Here is the caller graph for this function: