Skip to content

Commit

Permalink
Try to get this working on older compilers.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Jul 10, 2018
1 parent 43a81ed commit cfe085e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import qualified Data.Text.IO as T
import qualified Data.Text.Lazy.IO as LT
import Options.Applicative
( Parser, ReadM, execParser, fullDesc, help, helper, info, long
, maybeReader, option, progDesc, short, showDefaultWith, value, (<**>))
, option, progDesc, readerError, short, showDefaultWith, str, value, (<**>))
import Data.Semigroup ((<>))
import Text.Pretty.Simple
( pStringOpt, OutputOptions
Expand All @@ -37,22 +37,23 @@ import Text.Pretty.Simple
, defaultOutputOptionsNoColor
)

data Color = DarkBg
| LightBg
data Color = DarkBg
| LightBg
| NoColor

newtype Args = Args { color :: Color }

colorReader :: ReadM Color
colorReader = maybeReader colorReader'
where
colorReader' "dark-bg" = Just DarkBg
colorReader' "light-bg" = Just LightBg
colorReader' "no-color" = Just NoColor
colorReader' _ = Nothing
colorReader = do
string <- str
case string of
"dark-bg" -> pure DarkBg
"light-bg" -> pure LightBg
"no-color" -> pure NoColor
x -> readerError $ "Could not parse " <> x <> " as a color."

args :: Parser Args
args = Args
args = Args
<$> option colorReader
( long "color"
<> short 'c'
Expand All @@ -63,7 +64,7 @@ args = Args

main :: IO ()
main = do
args' <- execParser opts
args' <- execParser opts
input <- T.getContents
let printOpt = getPrintOpt $ color args'
output = pStringOpt printOpt $ unpack input
Expand Down
1 change: 1 addition & 0 deletions pretty-simple.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ executable pretty-simple
hs-source-dirs: app
build-depends: base
, pretty-simple
, semigroups
, text
, optparse-applicative
default-language: Haskell2010
Expand Down

0 comments on commit cfe085e

Please sign in to comment.