Skip to content

Commit

Permalink
Work around GHCJS bug
Browse files Browse the repository at this point in the history
  • Loading branch information
georgefst committed Aug 21, 2020
1 parent 3c48dd7 commit 5574725
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/Text/Pretty/Simple/Internal/OutputPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ hCheckTTY h options = liftIO $ conv <$> tty
-- suitable for passing to any /prettyprinter/ backend.
-- Used by 'Simple.pString' etc.
layoutString :: OutputOptions -> String -> SimpleDocStream Style
layoutString opts =
annotateStyle opts
. layoutSmart defaultLayoutOptions
layoutString opts = annotateStyle opts . layoutString' opts

layoutString' :: OutputOptions -> String -> SimpleDocStream Annotation
layoutString' opts =
layoutSmart defaultLayoutOptions
{layoutPageWidth = AvailablePerLine (outputOptionsPageWidth opts) 1}
. prettyExprs' opts
. preprocess opts
Expand Down
25 changes: 10 additions & 15 deletions web/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Miso hiding (go, set)
import Miso.String (MisoString, fromMisoString, ms)
import Prettyprinter.Render.Util.SimpleDocTree (SimpleDocTree (..), treeForm)
import Text.Pretty.Simple
import Text.Pretty.Simple.Internal (layoutString)
import Text.Pretty.Simple.Internal (Annotation (..), layoutString')

#ifndef __GHCJS__
runApp :: JSM () -> IO ()
Expand Down Expand Up @@ -59,19 +59,14 @@ main = runApp $ startApp App {..}
mountPoint = Nothing -- Nothing defaults to 'body'
logLevel = Off

--TODO submit GHCJS/Miso bug
renderStyle :: Style -> View action -> View action
#ifdef __GHCJS__
renderStyle s = span_ [style_ $ Map.singleton "color" "blue"] . pure
#else
renderStyle Style {..} =
--TODO use all fields
(if styleBold then b_ [] . pure else id) . case styleColor of
Nothing -> id
Just (c, i) -> span_ [style_ $ uncurry Map.singleton $ renderColor c i] . pure
where
renderColor c _i = ("color", ms $ show c) --TODO use intensities (consult ANSI color chart)
#endif
renderAnn :: Annotation -> View act -> View act
renderAnn = \case
Open -> b_ [] . pure . span_ [style_ $ Map.singleton "color" "red"] . pure
Close -> b_ [] . pure . span_ [style_ $ Map.singleton "color" "red"] . pure
Comma -> b_ [] . pure . span_ [style_ $ Map.singleton "color" "red"] . pure
Quote -> b_ [] . pure . span_ [style_ $ Map.singleton "color" "black"] . pure
String -> b_ [] . pure . span_ [style_ $ Map.singleton "color" "blue"] . pure
Num -> b_ [] . pure . span_ [style_ $ Map.singleton "color" "green"] . pure

updateModel :: Action -> Model -> Effect Action Model
updateModel = \case
Expand Down Expand Up @@ -125,7 +120,7 @@ unChecked :: Checked -> Bool
unChecked (Checked b) = b

pPrintStringHtml :: OutputOptions -> String -> View act
pPrintStringHtml opts = renderHtml . fmap renderStyle . treeForm . layoutString opts
pPrintStringHtml opts = renderHtml . fmap renderAnn . treeForm . layoutString' opts

renderHtml :: SimpleDocTree (View act -> View act) -> View act
renderHtml =
Expand Down

0 comments on commit 5574725

Please sign in to comment.