{-# Language OverloadedStrings #-}
module Client.View.RtsStats
( rtsStatsLines
) where
import Client.Image.PackedImage
import Client.Image.Palette
import Control.Lens
import Graphics.Vty.Attributes
import RtsStats
rtsStatsLines :: Maybe Stats -> Palette -> [Image']
rtsStatsLines Nothing pal = [text' (view palError pal) "Statistics not available"]
rtsStatsLines (Just stats) pal
| null entries = [text' (view palError pal) "Statistics empty"]
| otherwise = zipWith (\v l -> padV wv v <> " " <> l) valueImages labelImages
where
entries = statsToEntries stats
labelImages = map (text' (view palLabel pal) . fst) entries
valueImages = map (text' defAttr . snd) entries
wv = maximum (0 : map imageWidth valueImages)
padV n img = string defAttr (replicate (n - imageWidth img) ' ') <> img