From e29693101f9677e93d90e6cb32a211e7f01e3c22 Mon Sep 17 00:00:00 2001
From: Jan Beinke <git@janbeinke.com>
Date: Fri, 12 Jan 2024 20:45:12 +0100
Subject: [PATCH] Fix bug in rainbow theme generation with `&` escape sequences

---
 qbar/src/QBar/Theme.hs | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/qbar/src/QBar/Theme.hs b/qbar/src/QBar/Theme.hs
index cf70679..8990a93 100644
--- a/qbar/src/QBar/Theme.hs
+++ b/qbar/src/QBar/Theme.hs
@@ -155,7 +155,7 @@ rainbowTheme = AnimatedTheme rainbowThemePipe
         rainbowBlock :: BlockOutput -> State Integer ThemedBlockOutput
         rainbowBlock block@BlockOutput{_blockName} = do
           let text = rawText $ block ^. fullText
-          let chars = T.unpack . T.reverse $ text
+          let chars = reverse . splitToChars $ text
           coloredChars <- mapM rainbowChar chars
           let rainbowText = reverse coloredChars
           return $ ThemedBlockOutput {
@@ -163,10 +163,10 @@ rainbowTheme = AnimatedTheme rainbowThemePipe
             _fullText = ThemedBlockText rainbowText,
             _shortText = Nothing
           }
-        rainbowChar :: Char -> State Integer ThemedBlockTextSegment
+        rainbowChar :: T.Text -> State Integer ThemedBlockTextSegment
         rainbowChar char = do
           color <- nextRainbowColor
-          return $ mkThemedSegment (color, Nothing) $ T.singleton char
+          return $ mkThemedSegment (color, Nothing) $ char
         nextRainbowColor :: State Integer Color
         -- nextRainbowColor = state $ \index -> (rainbowColor (fromInteger index), index + 1)
         nextRainbowColor = do
@@ -178,3 +178,13 @@ rainbowTheme = AnimatedTheme rainbowThemePipe
           let hue' = position * 3
               color = hsv hue' 0.8 1.0
           in ColorRGB color
+        splitToChars :: T.Text -> [T.Text]
+        splitToChars = splitStringToChars . T.unpack
+        splitStringToChars :: String -> [T.Text]
+        splitStringToChars [] = []
+        splitStringToChars ('&':xs) = splitStringToCharsAmp "&" xs
+        splitStringToChars (x:xs) = T.singleton x : splitStringToChars xs
+        splitStringToCharsAmp :: String -> String -> [T.Text]
+        splitStringToCharsAmp _ [] = []
+        splitStringToCharsAmp acc (';':xs) = T.pack (acc <> ";") : splitStringToChars xs
+        splitStringToCharsAmp acc (x:xs) = splitStringToCharsAmp (acc <> [x]) xs
-- 
GitLab