diff --git a/app/Commands/Html/Options.hs b/app/Commands/Html/Options.hs index 0dd06ba2bf..b7e395696d 100644 --- a/app/Commands/Html/Options.hs +++ b/app/Commands/Html/Options.hs @@ -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 <- @@ -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] diff --git a/src/Juvix/Compiler/Backend/Html/Data/Options.hs b/src/Juvix/Compiler/Backend/Html/Data/Options.hs index f61b13d03a..26dd9d652f 100644 --- a/src/Juvix/Compiler/Backend/Html/Data/Options.hs +++ b/src/Juvix/Compiler/Backend/Html/Data/Options.hs @@ -1,6 +1,7 @@ module Juvix.Compiler.Backend.Html.Data.Options where import Juvix.Prelude +import Prelude (show) data HtmlOptions = HtmlOptions { _htmlOptionsKind :: HtmlKind, @@ -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 diff --git a/tests/smoke/Commands/html.smoke.yaml b/tests/smoke/Commands/html.smoke.yaml index bb10af059b..60b50831e2 100644 --- a/tests/smoke/Commands/html.smoke.yaml +++ b/tests/smoke/Commands/html.smoke.yaml @@ -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: