{-# Language OverloadedStrings #-}
module Client.View.Digraphs (digraphLines) where
import Client.Image.Message (cleanChar)
import Client.State
import Control.Lens
import Data.List
import Data.List.Split
import qualified Data.Text as Text
import Digraphs
import Graphics.Vty.Image
digraphLines ::
ClientState ->
[Image]
digraphLines st
= map (horizCat . intersperse sep)
$ chunksOf entriesPerLine
$ map (text' defAttr)
$ filter matcher
$ map (Text.pack . drawEntry)
$ digraphListToList digraphs
where
w = view clientWidth st
matcher = clientMatcher st
entriesPerLine = max 1
$ (w + sepWidth) `quot` (entryWidth + sepWidth)
entryWidth :: Int
entryWidth = 5
sepWidth :: Int
sepWidth = imageWidth sep
sep :: Image
sep = text' defAttr " "
drawEntry :: (Char,Char,Char) -> String
drawEntry (x,y,z) = output ++ replicate (entryWidth - wcswidth output) ' '
where
output = x:y:z2
dottedCircle = '\x25cc'
z1 = cleanChar z
z2 | wcwidth z1 == 0 = [' ', dottedCircle, z1]
| otherwise = [' ', z1]