Skip to content

Commit

Permalink
Show all available html themes in the CLI automatically (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored Aug 31, 2023
1 parent 340f192 commit 3c5304f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
24 changes: 19 additions & 5 deletions app/Commands/Html/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ parseHtml = do
<> metavar "THEME"
<> value Ayu
<> showDefault
<> help "Theme for syntax highlighting. Options: ayu (light) and nord (dark)"
<> help ("Theme for syntax highlighting. " <> availableStr)
<> completeWith (map show allThemes)
)
_htmlOutputDir <-
Expand Down Expand Up @@ -77,8 +77,22 @@ parseHtml = do
allThemes :: [Theme]
allThemes = allElements

availableStr :: String
availableStr =
dotSep
[ showCategory (light, filter ((== light) . themeLight) allThemes)
| light <- allElements
]
where
showCategory :: (ThemeLight, [Theme]) -> String
showCategory (light, ts) = show light <> " themes: " <> commaSep (map show ts)
commaSep = intercalate ", "
dotSep = intercalate ". "

parseTheme :: String -> Either String Theme
parseTheme s = case map toLower s of
"nord" -> Right Nord
"ayu" -> Right Ayu
_ -> Left $ "unrecognised theme: " <> s
parseTheme s = case lookup (map toLower s) themes of
Just t -> return t
Nothing -> Left $ "unrecognised theme: " <> s
where
themes :: [(String, Theme)]
themes = [(show theme, theme) | theme <- allThemes]
18 changes: 17 additions & 1 deletion src/Juvix/Compiler/Backend/Html/Data/Options.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Juvix.Compiler.Backend.Html.Data.Options where

import Juvix.Prelude
import Prelude (show)

data HtmlOptions = HtmlOptions
{ _htmlOptionsKind :: HtmlKind,
Expand All @@ -15,7 +16,22 @@ data HtmlOptions = HtmlOptions
data Theme
= Nord
| Ayu
deriving stock (Show, Enum, Bounded, Data)
deriving stock (Enum, Eq, Ord, Bounded, Data)

instance Show Theme where
show = \case
Nord -> "nord"
Ayu -> "ayu"

data ThemeLight
= Dark
| Light
deriving stock (Show, Eq, Enum, Ord, Bounded, Data)

themeLight :: Theme -> ThemeLight
themeLight = \case
Nord -> Dark
Ayu -> Light

data HtmlKind
= HtmlDoc
Expand Down
13 changes: 13 additions & 0 deletions tests/smoke/Commands/html.smoke.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
working-directory: ./../../../examples/

tests:
- name: html-help-theme
command:
- juvix
- html
- --help
stdout:
matches:
regex: |
.*Theme for syntax highlighting. Dark themes: .*Light themes.*
options:
- dot-all
exit-status: 0

- name: html-stdout
command:
shell:
Expand Down

0 comments on commit 3c5304f

Please sign in to comment.