module Client.View.Windows
( windowsImages
) where
import Client.Image.Palette
import Client.State
import Client.State.Focus
import Client.State.Window
import Control.Lens
import Data.List
import qualified Data.Map as Map
import Graphics.Vty.Image
import Irc.Identifier
windowsImages :: ClientState -> [Image]
windowsImages st
= reverse
$ createColumns
$ zipWith (renderWindowColumns pal) names windows
where
windows = views clientWindows Map.toAscList st
pal = clientPalette st
names = clientWindowNames st ++ repeat '?'
renderWindowColumns :: Palette -> Char -> (Focus, Window) -> [Image]
renderWindowColumns pal name (focus, win) =
[ char (view palWindowName pal) name
, renderedFocus pal focus
, renderedWindowInfo pal win
]
createColumns :: [[Image]] -> [Image]
createColumns xs = map makeRow xs
where
columnWidths = maximum . map imageWidth <$> transpose xs
makeRow = horizCat
. intersperse (char defAttr ' ')
. zipWith resizeWidth columnWidths
renderedFocus :: Palette -> Focus -> Image
renderedFocus pal focus =
case focus of
Unfocused ->
char (view palError pal) '*'
NetworkFocus network ->
text' (view palLabel pal) network
ChannelFocus network channel ->
text' (view palLabel pal) network <|>
char defAttr ':' <|>
text' (view palLabel pal) (idText channel)
renderedWindowInfo :: Palette -> Window -> Image
renderedWindowInfo pal win =
string (view newMsgAttrLens pal) (views winUnread show win) <|>
char defAttr '/' <|>
string (view palActivity pal) (views winTotal show win)
where
newMsgAttrLens
| view winMention win = palMention
| otherwise = palActivity