Improve brick UI

This commit is contained in:
Julian Ospald 2020-09-20 23:06:35 +02:00
parent 571df1349c
commit 05cc55c52d
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 31 additions and 19 deletions

View File

@ -71,18 +71,25 @@ ui AppState {..} =
( padBottom Max ( padBottom Max
$ ( withBorderStyle unicode $ ( withBorderStyle unicode
$ borderWithLabel (str "GHCup") $ borderWithLabel (str "GHCup")
$ (center $ renderList renderItem True lr) $ (center $ (header <=> hBorder <=> renderList renderItem True lr))
) )
) )
<=> ( withAttr "help" <=> footer
. txtWrap
. T.pack
. foldr1 (\x y -> x <> " " <> y)
. (++ ["↑↓:Navigation"])
$ (fmap (\(c, s, _) -> (c : ':' : s)) keyHandlers)
)
where where
footer =
withAttr "help"
. txtWrap
. T.pack
. foldr1 (\x y -> x <> " " <> y)
. (++ ["↑↓:Navigation"])
$ (fmap (\(c, s, _) -> (c : ':' : s)) keyHandlers)
header =
(minHSize 2 $ emptyWidget)
<+> (padLeft (Pad 2) $ minHSize 6 $ str "Tool")
<+> (minHSize 15 $ str "Version")
<+> (padLeft (Pad 1) $ minHSize 25 $ str "Tags")
<+> (padLeft (Pad 5) $ str "Notes")
renderItem b listResult@(ListResult {..}) = renderItem b listResult@(ListResult {..}) =
let marks = if let marks = if
| lSet -> (withAttr "set" $ str "✔✔") | lSet -> (withAttr "set" $ str "✔✔")
@ -94,15 +101,17 @@ ui AppState {..} =
dim = if lNoBindist dim = if lNoBindist
then updateAttrMap (const dimAttributes) . withAttr "no-bindist" then updateAttrMap (const dimAttributes) . withAttr "no-bindist"
else id else id
active = if b then withAttr "active" else id
in dim in dim
( marks ( marks
<+> ( padLeft (Pad 2) <+> (( padLeft (Pad 2)
$ minHSize 20 $ active
$ ((if b then withAttr "active" else id) $ minHSize 6
(str $ (fmap toLower . show $ lTool) <> " " <> ver) $ (str (fmap toLower . show $ lTool))
) )
) )
<+> (padLeft (Pad 1) $ minHSize 20 $ if null lTag <+> (minHSize 15 $ active $ (str ver))
<+> (padLeft (Pad 1) $ minHSize 25 $ if null lTag
then emptyWidget then emptyWidget
else else
foldr1 (\x y -> x <+> str "," <+> y) foldr1 (\x y -> x <+> str "," <+> y)
@ -122,11 +131,12 @@ ui AppState {..} =
printTag (Base pvp'') = str ("base-" ++ T.unpack (prettyPVP pvp'')) printTag (Base pvp'') = str ("base-" ++ T.unpack (prettyPVP pvp''))
printTag (UnknownTag t ) = str t printTag (UnknownTag t ) = str t
printNotes ListResult{..} = printNotes ListResult {..} =
(if hlsPowered then [withAttr "hls-powered" $ str "hls-powered"] else mempty) (if hlsPowered then [withAttr "hls-powered" $ str "hls-powered"] else mempty
++ (if fromSrc then [str "compiled"] else mempty) )
++ (if lStray then [str "stray"] else mempty) ++ (if fromSrc then [withAttr "compiled" $ str "compiled"] else mempty)
++ (if lNoBindist then [str "no-bindist"] else mempty) ++ (if lStray then [withAttr "stray" $ str "stray"] else mempty)
minHSize :: Int -> Widget n -> Widget n minHSize :: Int -> Widget n -> Widget n
@ -152,6 +162,8 @@ defaultAttributes = attrMap
, ("hls-powered" , Vty.defAttr `Vty.withForeColor` Vty.green) , ("hls-powered" , Vty.defAttr `Vty.withForeColor` Vty.green)
, ("latest" , Vty.defAttr `Vty.withForeColor` Vty.yellow) , ("latest" , Vty.defAttr `Vty.withForeColor` Vty.yellow)
, ("prerelease" , Vty.defAttr `Vty.withForeColor` Vty.red) , ("prerelease" , Vty.defAttr `Vty.withForeColor` Vty.red)
, ("compiled" , Vty.defAttr `Vty.withForeColor` Vty.blue)
, ("stray" , Vty.defAttr `Vty.withForeColor` Vty.blue)
, ("help" , Vty.defAttr `Vty.withStyle` Vty.italic) , ("help" , Vty.defAttr `Vty.withStyle` Vty.italic)
] ]