factor out attr names. Add windows symbols to tutotial widget. Improve tutorial aesthetics and text

This commit is contained in:
Luis Morillo 2023-11-15 21:35:56 +01:00
parent 835352428a
commit 987cdaf313
1 changed files with 101 additions and 51 deletions

View File

@ -355,7 +355,7 @@ ui dimAttrs BrickState{ _appSettings = as@BrickSettings{}, ..}
<=> footer <=> footer
where where
footer = footer =
Brick.withAttr (Brick.attrName "help") Brick.withAttr helpAttr
. Brick.txtWrap . Brick.txtWrap
. T.pack . T.pack
. foldr1 (\x y -> x <> " " <> y) . foldr1 (\x y -> x <> " " <> y)
@ -374,9 +374,9 @@ ui dimAttrs BrickState{ _appSettings = as@BrickSettings{}, ..}
in Brick.withDefAttr L.listAttr $ renderSectionList (renderItem minTagSize minVerSize) True bis in Brick.withDefAttr L.listAttr $ renderSectionList (renderItem minTagSize minVerSize) True bis
renderItem minTagSize minVerSize b listResult@ListResult{lTag = lTag', ..} = renderItem minTagSize minVerSize b listResult@ListResult{lTag = lTag', ..} =
let marks = if let marks = if
| lSet -> (Brick.withAttr (Brick.attrName "set") $ Brick.str setSign) | lSet -> (Brick.withAttr setAttr $ Brick.str setSign)
| lInstalled -> (Brick.withAttr (Brick.attrName "installed") $ Brick.str installedSign) | lInstalled -> (Brick.withAttr installedAttr $ Brick.str installedSign)
| otherwise -> (Brick.withAttr (Brick.attrName "not-installed") $ Brick.str notInstalledSign) | otherwise -> (Brick.withAttr notInstalledAttr $ Brick.str notInstalledSign)
ver = case lCross of ver = case lCross of
Nothing -> T.unpack . prettyVer $ lVer Nothing -> T.unpack . prettyVer $ lVer
Just c -> T.unpack (c <> "-" <> prettyVer lVer) Just c -> T.unpack (c <> "-" <> prettyVer lVer)
@ -388,7 +388,7 @@ ui dimAttrs BrickState{ _appSettings = as@BrickSettings{}, ..}
| otherwise = id | otherwise = id
hooray hooray
| elem Latest lTag' && not lInstalled = | elem Latest lTag' && not lInstalled =
Brick.withAttr (Brick.attrName "hooray") Brick.withAttr hoorayAttr
| otherwise = id | otherwise = id
in hooray $ dim in hooray $ dim
( marks ( marks
@ -411,14 +411,14 @@ ui dimAttrs BrickState{ _appSettings = as@BrickSettings{}, ..}
<+> Brick.vLimit 1 (Brick.fill ' ') <+> Brick.vLimit 1 (Brick.fill ' ')
) )
printTag Recommended = Just $ Brick.withAttr (Brick.attrName "recommended") $ Brick.str "recommended" printTag Recommended = Just $ Brick.withAttr recommendedAttr $ Brick.str "recommended"
printTag Latest = Just $ Brick.withAttr (Brick.attrName "latest") $ Brick.str "latest" printTag Latest = Just $ Brick.withAttr latestAttr $ Brick.str "latest"
printTag Prerelease = Just $ Brick.withAttr (Brick.attrName "prerelease") $ Brick.str "prerelease" printTag Prerelease = Just $ Brick.withAttr prereleaseAttr $ Brick.str "prerelease"
printTag Nightly = Just $ Brick.withAttr (Brick.attrName "nightly") $ Brick.str "nightly" printTag Nightly = Just $ Brick.withAttr nightlyAttr $ Brick.str "nightly"
printTag (Base pvp'') = Just $ Brick.str ("base-" ++ T.unpack (prettyPVP pvp'')) printTag (Base pvp'') = Just $ Brick.str ("base-" ++ T.unpack (prettyPVP pvp''))
printTag Old = Nothing printTag Old = Nothing
printTag LatestPrerelease = Just $ Brick.withAttr (Brick.attrName "latest-prerelease") $ Brick.str "latest-prerelease" printTag LatestPrerelease = Just $ Brick.withAttr latestPrereleaseAttr $ Brick.str "latest-prerelease"
printTag LatestNightly = Just $ Brick.withAttr (Brick.attrName "latest-nightly") $ Brick.str "latest-nightly" printTag LatestNightly = Just $ Brick.withAttr latestNightlyAttr $ Brick.str "latest-nightly"
printTag (UnknownTag t) = Just $ Brick.str t printTag (UnknownTag t) = Just $ Brick.str t
printTool Cabal = Brick.str "cabal" printTool Cabal = Brick.str "cabal"
@ -428,12 +428,12 @@ ui dimAttrs BrickState{ _appSettings = as@BrickSettings{}, ..}
printTool Stack = Brick.str "Stack" printTool Stack = Brick.str "Stack"
printNotes ListResult {..} = printNotes ListResult {..} =
(if hlsPowered then [Brick.withAttr (Brick.attrName "hls-powered") $ Brick.str "hls-powered"] else mempty (if hlsPowered then [Brick.withAttr hlsPoweredAttr $ Brick.str "hls-powered"] else mempty
) )
++ (if lStray then [Brick.withAttr (Brick.attrName "stray") $ Brick.str "stray"] else mempty) ++ (if lStray then [Brick.withAttr strayAttr $ Brick.str "stray"] else mempty)
++ (case lReleaseDay of ++ (case lReleaseDay of
Nothing -> mempty Nothing -> mempty
Just d -> [Brick.withAttr (Brick.attrName "day") $ Brick.str (show d)]) Just d -> [Brick.withAttr dayAttr $ Brick.str (show d)])
minHSize :: Int -> Widget n -> Widget n minHSize :: Int -> Widget n -> Widget n
minHSize s' = Brick.hLimit s' . Brick.vLimit 1 . (<+> Brick.fill ' ') minHSize s' = Brick.hLimit s' . Brick.vLimit 1 . (<+> Brick.fill ' ')
@ -453,49 +453,78 @@ drawUI dimAttrs st =
case st ^. mode of case st ^. mode of
Navigation -> [ui dimAttrs st] Navigation -> [ui dimAttrs st]
Tutorial -> Tutorial ->
let tutorial = centerLayer let mkTextBox = Brick.hLimitPercent 70 . Brick.vBox . fmap (Brick.padRight Brick.Max)
$ Brick.hLimitPercent 75 txt_separator = hBorder <+> Brick.str " o " <+> hBorder
$ Brick.vLimitPercent 50 tutorial = centerLayer
$ Brick.withBorderStyle unicode $ Brick.hLimitPercent 75
$ borderWithLabel (Brick.txt "Tutorial") $ Brick.vLimitPercent 50
$ Brick.vBox $ Brick.withBorderStyle unicode
[ Brick.txt "GHCup is a tool for managing your Haskell tooling." $ borderWithLabel (Brick.txt "Tutorial")
, center (Brick.txt "--- o ---") $ Brick.vBox
, Brick.txt "This symbol " (fmap center
<+> Brick.withAttr (Brick.attrName "installed") (Brick.str "") [ mkTextBox [Brick.txt "GHCup is a distribution channel for Haskell's tools."]
<+> Brick.txt " means that the tool is installed but not in used" , txt_separator
, Brick.txt "This symbol " , mkTextBox [
<+> Brick.withAttr (Brick.attrName "set") (Brick.str "✔✔") Brick.hBox [
<+> Brick.txt " means that the tool is installed and in used" Brick.txt "This symbol "
, Brick.txt "This symbol " , Brick.withAttr installedAttr (Brick.str installedSign)
<+> Brick.withAttr (Brick.attrName "not-installed") (Brick.str "") , Brick.txt " means that the tool is installed but not in used"
<+> Brick.txt " means that the tool isn't installed" ]
, center (Brick.txt "--- o ---") , Brick.hBox [
, Brick.txt "Press Enter to exit the tutorial" Brick.txt "This symbol "
] , Brick.withAttr setAttr (Brick.str setSign)
, Brick.txt " means that the tool is installed and in used"
]
, Brick.hBox [
Brick.txt "This symbol "
, Brick.withAttr notInstalledAttr (Brick.str notInstalledSign)
, Brick.txt " means that the tool isn't installed"
]
]
, txt_separator
, mkTextBox [
Brick.hBox [
Brick.withAttr recommendedAttr $ Brick.str "recommended"
, Brick.txt " tag is based on ..."
]
, Brick.hBox [
Brick.withAttr latestAttr $ Brick.str "latest"
, Brick.txt " tag is for the latest distributed version of the tool"
]
, Brick.hBox [
Brick.withAttr latestAttr $ Brick.str "hls-powered"
, Brick.txt " denotes the compiler version supported by the currently set ("
, Brick.withAttr setAttr (Brick.str setSign)
, Brick.txt ") hls"
]
, Brick.txt "base-X.Y.Z.W tag is the minimun version of the base package admited in such ghc version"
]
, Brick.txt " "
])
<=> Brick.padRight Brick.Max (Brick.txt "Press Enter to exit the tutorial")
in [tutorial, ui dimAttrs st] in [tutorial, ui dimAttrs st]
defaultAttributes :: Bool -> AttrMap defaultAttributes :: Bool -> AttrMap
defaultAttributes no_color = Brick.attrMap defaultAttributes no_color = Brick.attrMap
Vty.defAttr Vty.defAttr
[ (L.listSelectedFocusedAttr , Vty.defAttr `withBackColor` Vty.blue) --, (attrName "active" , Vty.defAttr `withBackColor` Vty.blue) [ (L.listSelectedFocusedAttr , Vty.defAttr `withBackColor` Vty.blue) --, (attrName "active" , Vty.defAttr `withBackColor` Vty.blue)
, (L.listSelectedAttr , Vty.defAttr) -- we use list attributes for active. , (L.listSelectedAttr , Vty.defAttr) -- we use list attributes for active.
, (Brick.attrName "not-installed" , Vty.defAttr `withForeColor` Vty.red) , (notInstalledAttr , Vty.defAttr `withForeColor` Vty.red)
, (Brick.attrName "set" , Vty.defAttr `withForeColor` Vty.green) , (setAttr , Vty.defAttr `withForeColor` Vty.green)
, (Brick.attrName "installed" , Vty.defAttr `withForeColor` Vty.green) , (installedAttr , Vty.defAttr `withForeColor` Vty.green)
, (Brick.attrName "recommended" , Vty.defAttr `withForeColor` Vty.green) , (recommendedAttr , Vty.defAttr `withForeColor` Vty.green)
, (Brick.attrName "hls-powered" , Vty.defAttr `withForeColor` Vty.green) , (hlsPoweredAttr , Vty.defAttr `withForeColor` Vty.green)
, (Brick.attrName "latest" , Vty.defAttr `withForeColor` Vty.yellow) , (latestAttr , Vty.defAttr `withForeColor` Vty.yellow)
, (Brick.attrName "latest-prerelease" , Vty.defAttr `withForeColor` Vty.red) , (latestPrereleaseAttr , Vty.defAttr `withForeColor` Vty.red)
, (Brick.attrName "latest-nightly" , Vty.defAttr `withForeColor` Vty.red) , (latestNightlyAttr , Vty.defAttr `withForeColor` Vty.red)
, (Brick.attrName "prerelease" , Vty.defAttr `withForeColor` Vty.red) , (prereleaseAttr , Vty.defAttr `withForeColor` Vty.red)
, (Brick.attrName "nightly" , Vty.defAttr `withForeColor` Vty.red) , (nightlyAttr , Vty.defAttr `withForeColor` Vty.red)
, (Brick.attrName "compiled" , Vty.defAttr `withForeColor` Vty.blue) , (compiledAttr , Vty.defAttr `withForeColor` Vty.blue)
, (Brick.attrName "stray" , Vty.defAttr `withForeColor` Vty.blue) , (strayAttr , Vty.defAttr `withForeColor` Vty.blue)
, (Brick.attrName "day" , Vty.defAttr `withForeColor` Vty.blue) , (dayAttr , Vty.defAttr `withForeColor` Vty.blue)
, (Brick.attrName "help" , Vty.defAttr `withStyle` Vty.italic) , (helpAttr , Vty.defAttr `withStyle` Vty.italic)
, (Brick.attrName "hooray" , Vty.defAttr `withForeColor` Vty.brightWhite) , (hoorayAttr , Vty.defAttr `withForeColor` Vty.brightWhite)
] ]
where where
withForeColor | no_color = const withForeColor | no_color = const
@ -506,6 +535,27 @@ defaultAttributes no_color = Brick.attrMap
withStyle = Vty.withStyle withStyle = Vty.withStyle
notInstalledAttr, setAttr, installedAttr, recommendedAttr, hlsPoweredAttr:: Brick.AttrName
latestAttr, latestPrereleaseAttr, latestNightlyAttr, prereleaseAttr, nightlyAttr:: Brick.AttrName
compiledAttr, strayAttr, dayAttr, helpAttr, hoorayAttr:: Brick.AttrName
notInstalledAttr = Brick.attrName "not-installed"
setAttr = Brick.attrName "set"
installedAttr = Brick.attrName "installed"
recommendedAttr = Brick.attrName "recommended"
hlsPoweredAttr = Brick.attrName "hls-powered"
latestAttr = Brick.attrName "latest"
latestPrereleaseAttr = Brick.attrName "latest-prerelease"
latestNightlyAttr = Brick.attrName "latest-nightly"
prereleaseAttr = Brick.attrName "prerelease"
nightlyAttr = Brick.attrName "nightly"
compiledAttr = Brick.attrName "compiled"
strayAttr = Brick.attrName "stray"
dayAttr = Brick.attrName "day"
helpAttr = Brick.attrName "help"
hoorayAttr = Brick.attrName "hooray"
dimAttributes :: Bool -> AttrMap dimAttributes :: Bool -> AttrMap
dimAttributes no_color = Brick.attrMap dimAttributes no_color = Brick.attrMap
(Vty.defAttr `Vty.withStyle` Vty.dim) (Vty.defAttr `Vty.withStyle` Vty.dim)