sources/coloredline.cpp

changeset 113
b3a33bc2e482
parent 109
e4966d7e615d
child 132
8a4690db252e
child 131
4996c8684b93
--- a/sources/coloredline.cpp	Sun Jan 10 20:05:27 2016 +0200
+++ b/sources/coloredline.cpp	Sun Jan 10 20:53:44 2016 +0200
@@ -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;
 	}
 
@@ -135,6 +160,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);

mercurial