Skip to content

Commit

Permalink
dhall format --inplace: Write file atomically
Browse files Browse the repository at this point in the history
Fixes #498.
  • Loading branch information
sjakobi committed Dec 2, 2019
1 parent 85645a2 commit 79f0abb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dhall/src/Dhall/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Data.Monoid ((<>))
import Dhall.Pretty (CharacterSet(..), annToAnsiStyle)
import Dhall.Util (Censor, Input(..), Header(..))

import qualified System.AtomicWrite.Writer.LazyText as AtomicWrite.LazyText
import qualified Data.Text.Prettyprint.Doc as Pretty
import qualified Data.Text.Prettyprint.Doc.Render.Terminal as Pretty.Terminal
import qualified Data.Text.Prettyprint.Doc.Render.Text as Pretty.Text
Expand Down Expand Up @@ -68,8 +69,9 @@ format (Format {..}) = do

case inplace of
InputFile file -> do
System.IO.withFile file System.IO.WriteMode (\handle -> do
Pretty.Terminal.renderIO handle (Pretty.unAnnotateS docStream))
AtomicWrite.LazyText.atomicWriteFile
file
(Pretty.Text.renderLazy docStream)

StandardInput -> do
supportsANSI <- System.Console.ANSI.hSupportsANSI System.IO.stdout
Expand Down

0 comments on commit 79f0abb

Please sign in to comment.