From c6e861083be4236d468fe02a744ea8823ded7290 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 22 Nov 2016 22:45:12 +0100 Subject: [PATCH] fix: Avoid unnecessary color change Ref #181 --- include/components/renderer.hpp | 2 ++ src/components/controller.cpp | 8 +++++++- src/components/parser.cpp | 10 ++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index 2c2d3f33..5c95a793 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -73,6 +73,8 @@ class renderer { uint32_t m_background{0}; uint32_t m_foreground{0}; + gc m_background_gc{gc::NONE}; + gc m_foreground_gc{gc::NONE}; edge m_reserve_at{edge::NONE}; uint16_t m_reserve; diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 1401a51b..eb8691b7 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -550,9 +550,15 @@ void controller::on_update() { block_contents += padding_right; } + // Strip unnecessary reset tags + block_contents = string_util::replace_all(block_contents, "T-}%{T", "T"); block_contents = string_util::replace_all(block_contents, "B-}%{B#", "B#"); block_contents = string_util::replace_all(block_contents, "F-}%{F#", "F#"); - block_contents = string_util::replace_all(block_contents, "T-}%{T", "T"); + block_contents = string_util::replace_all(block_contents, "U-}%{U#", "U#"); + block_contents = string_util::replace_all(block_contents, "Uu-}%{Uu#", "Uu#"); + block_contents = string_util::replace_all(block_contents, "Uo-}%{Uo#", "Uo#"); + + // Join consecutive tags contents += string_util::replace_all(block_contents, "}%{", " "); } diff --git a/src/components/parser.cpp b/src/components/parser.cpp index cb25368b..6866b4e3 100644 --- a/src/components/parser.cpp +++ b/src/components/parser.cpp @@ -64,10 +64,12 @@ void parser::codeblock(string data) { case 'U': if (g_signals::parser::color_change) { - if (value[0] == 'u' && data.find(" Uu") == string::npos) { - g_signals::parser::color_change(gc::UL, parse_color(value.substr(1), m_bar.underline.color)); - } else if (value[0] == 'o' && data.find(" Uo") == string::npos) { - g_signals::parser::color_change(gc::OL, parse_color(value.substr(1), m_bar.overline.color)); + if (value[0] == 'u') { + if (data.find(" Uu") == string::npos) + g_signals::parser::color_change(gc::UL, parse_color(value.substr(1), m_bar.underline.color)); + } else if (value[0] == 'o') { + if (data.find(" Uo") == string::npos) + g_signals::parser::color_change(gc::OL, parse_color(value.substr(1), m_bar.overline.color)); } else if (data.find(" U") == string::npos) { g_signals::parser::color_change(gc::UL, parse_color(value, m_bar.underline.color)); g_signals::parser::color_change(gc::OL, parse_color(value, m_bar.overline.color));