Skip to content

Commit

Permalink
No need to use the pretty-printer when the line-width is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgurakgun committed Aug 9, 2018
1 parent dae2e47 commit 8287369
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Conjure/UI/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,20 @@ onlyPreamble


writeModel :: MonadIO m => Int -> OutputFormat -> Maybe FilePath -> Model -> m ()
writeModel lnWidth Plain Nothing spec = liftIO $ putStrLn (render lnWidth spec)
writeModel lnWidth Plain (Just fp) spec = liftIO $ writeFile fp (render lnWidth spec)
writeModel lnWidth Plain Nothing spec
| lnWidth == 0 = liftIO $ putStrLn (show spec)
| otherwise = liftIO $ putStrLn (render lnWidth spec)
writeModel lnWidth Plain (Just fp) spec
| lnWidth == 0 = liftIO $ writeFile fp (show spec)
| otherwise = liftIO $ writeFile fp (render lnWidth spec)
writeModel _lnWidth Binary Nothing spec = liftIO $ BS.putStrLn (Data.Serialize.encode spec)
writeModel _lnWidth Binary (Just fp) spec = liftIO $ BS.writeFile fp (Data.Serialize.encode spec)
writeModel lnWidth JSON Nothing spec = liftIO $ putStrLn (render lnWidth (toJSON spec))
writeModel lnWidth JSON (Just fp) spec = liftIO $ writeFile fp (render lnWidth (toJSON spec))
writeModel lnWidth JSON Nothing spec
| lnWidth == 0 = liftIO $ putStrLn (show (toJSON spec))
| otherwise = liftIO $ putStrLn (render lnWidth (toJSON spec))
writeModel lnWidth JSON (Just fp) spec
| lnWidth == 0 = liftIO $ writeFile fp (show (toJSON spec))
| otherwise = liftIO $ writeFile fp (render lnWidth (toJSON spec))


writeModels :: MonadIO m => Int -> OutputFormat -> FilePath -> String -> [Model] -> m ()
Expand Down

0 comments on commit 8287369

Please sign in to comment.