Skip to content
Snippets Groups Projects
Commit e9bbf9b3 authored by Jens Nolte's avatar Jens Nolte
Browse files

Re-implement invalidation of pango-formatted text

parent 7b03f030
No related branches found
No related tags found
No related merge requests found
......@@ -133,23 +133,30 @@ toImportance' (tMax, tCritical, tError, tWarning, tNormal, tMinimal) val
valueOtherwise tNormal' Nothing v = 1 - logarithmicMatch v tNormal'
invalidateBlock :: BlockOutput -> BlockOutput
invalidateBlock block@BlockOutput{ _fullText, _shortText } = block {
_fullText = normalText . rawText $ _fullText,
_shortText = normalText . rawText <$> _shortText,
_invalid = True
}
removePango :: BlockText -> T.Text
removePango (BlockText b) = foldr ((<>) . removePangoFromSegment) "" b
rawText :: BlockText -> T.Text
rawText (BlockText b) = foldMap rawTextFromSegment b
where
removePangoFromSegment :: BlockTextSegment -> T.Text
removePangoFromSegment BlockTextSegment { active=_active, importance=_importance, text } = text
removePangoFromSegment (PangoTextSegment text) =
rawTextFromSegment :: BlockTextSegment -> T.Text
rawTextFromSegment BlockTextSegment{text} = text
rawTextFromSegment (PangoTextSegment text) =
case parsePango text of
Left _ -> text
Right parsed -> removeFormatting parsed
printedLength :: BlockText -> Int64
printedLength (BlockText b) = foldr ((+) . printedLength') 0 b
printedLength (BlockText b) = sum . map segmentLength $ b
where
printedLength' :: BlockTextSegment -> Int64
printedLength' BlockTextSegment { text, active=_, importance=_ } = T.length text
printedLength' (PangoTextSegment _) = 0
segmentLength :: BlockTextSegment -> Int64
segmentLength BlockTextSegment { text } = T.length text
segmentLength (PangoTextSegment pango) = either (const $ T.length pango) (T.length . removeFormatting) $ parsePango pango
mkText :: Bool -> Importance -> T.Text -> BlockText
mkText active importance text = BlockText [BlockTextSegment { text = pangoFriendly text, active, importance }]
......
......@@ -187,7 +187,7 @@ sharedInterval seconds = do
updateClickHandler Nothing _ = return ()
updateClickHandler (Just (block, _)) _ = do
-- Give user feedback that the block is updating
let outdatedBlock = block & invalid.~True
let outdatedBlock = invalidateBlock block
-- The invalidated block output has no event handler
liftIO $ void $ atomically $ send output . Just $ (outdatedBlock, Nothing)
-- Notify bar about changed block state to display the feedback
......
......@@ -71,7 +71,7 @@ rainbowTheme time blocks = reverse $ evalState (mapM rainbowBlock $ reverse bloc
where
rainbowBlock :: BlockOutput -> State Integer BlockOutput
rainbowBlock block = do
let text = removePango $ block ^. fullText
let text = rawText $ block ^. fullText
let chars = T.unpack . T.reverse $ text
coloredChars <- mapM rainbowChar chars
let rainbowText = T.concat . reverse $ coloredChars
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment