--- a/sources/coloredline.cpp Mon Jan 25 04:15:31 2016 +0200 +++ b/sources/coloredline.cpp Wed Jul 20 12:55:39 2016 +0300 @@ -1,5 +1,5 @@ /* - Copyright 2014, 2015 Teemu Piippo + Copyright 2014 - 2016 Teemu Piippo All rights reserved. Redistribution and use in source and binary forms, with or without @@ -105,23 +105,48 @@ if (m_boldActive) m_data << RLINE_OFF_BOLD; + m_boldActive = false; + // Chars may be in uppercase if (ch >= 'A' and ch <= 'V') ch += 'a' - 'A'; if (ch >= 'a' and ch <= 'v' and ch != 'l') { - auto colorInfo = colorCodes[ch - 'a']; - m_activeColor = colorInfo.color; - m_boldActive = colorInfo.bold; - assert (m_activeColor < 8); - set_color (m_activeColor, true); - - if (m_boldActive) - m_data << RLINE_ON_BOLD; + const ColorCodeInfo& colorInfo = colorCodes[ch - 'a']; + activate_color(colorInfo.color, colorInfo.bold); } - m_colorCodeStage = 0; + if (ch == '[') + m_colorCodeStage = 2; + else + m_colorCodeStage = 0; + return; + } + else if (m_colorCodeStage == 2) + { + if (ch == ']') + { + String color = m_incomingColorName.to_lowercase(); + + for (size_t i = 0; i < countof(colorCodes); ++i) + { + const ColorCodeInfo& colorInfo = colorCodes[i]; + + if (String(colorInfo.name).to_lowercase() == color) + { + activate_color(colorInfo.color, colorInfo.bold); + m_colorCodeStage = 0; + break; + } + } + + m_incomingColorName = ""; + m_colorCodeStage = 0; + } + else if (isprint(ch)) + m_incomingColorName += ch; + return; } @@ -143,6 +168,22 @@ // ------------------------------------------------------------------------------------------------- // +void ColoredLine::activate_color (Color color, bool bold) +{ + if (m_boldActive) + m_data << RLINE_OFF_BOLD; + + m_activeColor = color; + m_boldActive = bold; + assert (m_activeColor < 8); + set_color (m_activeColor, true); + + if (m_boldActive) + m_data << RLINE_ON_BOLD; +} + +// ------------------------------------------------------------------------------------------------- +// void ColoredLine::set_color (Color a, bool on) { assert (a < 8);