From 05cc55c52df01905125e47d40122a12525eaf04c Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 20 Sep 2020 23:06:35 +0200 Subject: [PATCH] Improve brick UI --- app/ghcup/BrickMain.hs | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/app/ghcup/BrickMain.hs b/app/ghcup/BrickMain.hs index 7a055ba..ebf7923 100644 --- a/app/ghcup/BrickMain.hs +++ b/app/ghcup/BrickMain.hs @@ -71,18 +71,25 @@ ui AppState {..} = ( padBottom Max $ ( withBorderStyle unicode $ borderWithLabel (str "GHCup") - $ (center $ renderList renderItem True lr) + $ (center $ (header <=> hBorder <=> renderList renderItem True lr)) ) ) - <=> ( withAttr "help" - . txtWrap - . T.pack - . foldr1 (\x y -> x <> " " <> y) - . (++ ["↑↓:Navigation"]) - $ (fmap (\(c, s, _) -> (c : ':' : s)) keyHandlers) - ) + <=> footer 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 {..}) = let marks = if | lSet -> (withAttr "set" $ str "✔✔") @@ -94,15 +101,17 @@ ui AppState {..} = dim = if lNoBindist then updateAttrMap (const dimAttributes) . withAttr "no-bindist" else id + active = if b then withAttr "active" else id in dim ( marks - <+> ( padLeft (Pad 2) - $ minHSize 20 - $ ((if b then withAttr "active" else id) - (str $ (fmap toLower . show $ lTool) <> " " <> ver) - ) + <+> (( padLeft (Pad 2) + $ active + $ minHSize 6 + $ (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 else foldr1 (\x y -> x <+> str "," <+> y) @@ -122,11 +131,12 @@ ui AppState {..} = printTag (Base pvp'') = str ("base-" ++ T.unpack (prettyPVP pvp'')) printTag (UnknownTag t ) = str t - printNotes ListResult{..} = - (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 lNoBindist then [str "no-bindist"] else mempty) + printNotes ListResult {..} = + (if hlsPowered then [withAttr "hls-powered" $ str "hls-powered"] else mempty + ) + ++ (if fromSrc then [withAttr "compiled" $ str "compiled"] else mempty) + ++ (if lStray then [withAttr "stray" $ str "stray"] else mempty) + minHSize :: Int -> Widget n -> Widget n @@ -152,6 +162,8 @@ defaultAttributes = attrMap , ("hls-powered" , Vty.defAttr `Vty.withForeColor` Vty.green) , ("latest" , Vty.defAttr `Vty.withForeColor` Vty.yellow) , ("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) ]