module Darcs.Patch.Show
( ShowPatchBasic(..)
, displayPatch
, showNicelyFL
, ShowPatchFor(..)
, ShowPatch(..)
, ShowContextPatch(..)
, formatFileName
) where
import Prelude ()
import Darcs.Prelude
import qualified Data.ByteString.Char8 as BC ( unpack )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch.ApplyMonad ( ApplyMonad )
import Darcs.Patch.Format ( FileNameFormat(..) )
import Darcs.Patch.Witnesses.Ordered ( FL, mapFL )
import Darcs.Util.ByteString ( packStringToUTF8, encodeLocale )
import Darcs.Util.English ( plural, Noun(Noun) )
import Darcs.Util.Path ( FileName, encodeWhite, fn2fp )
import Darcs.Util.Printer ( Doc, vcat, text, packedString )
data ShowPatchFor = ForDisplay | ForStorage
displayPatch :: ShowPatchBasic p => p wX wY -> Doc
displayPatch p = showPatch ForDisplay p
showNicelyFL :: ShowPatch p => FL p wX wY -> Doc
showNicelyFL = vcat . mapFL showNicely
class ShowPatchBasic p where
showPatch :: ShowPatchFor -> p wX wY -> Doc
class ShowPatchBasic p => ShowContextPatch p where
showContextPatch :: (Monad m, ApplyMonad (ApplyState p) m)
=> ShowPatchFor -> p wX wY -> m Doc
class ShowPatchBasic p => ShowPatch p where
showNicely :: p wX wY -> Doc
showNicely = showPatch ForDisplay
description :: p wX wY -> Doc
description = showPatch ForDisplay
summary :: p wX wY -> Doc
summaryFL :: FL p wX wY -> Doc
summaryFL = vcat . mapFL summary
thing :: p wX wY -> String
thing _ = "patch"
things :: p wX wY -> String
things x = plural (Noun $ thing x) ""
formatFileName :: FileNameFormat -> FileName -> Doc
formatFileName OldFormat = packedString . packStringToUTF8 . BC.unpack .
encodeLocale . encodeWhite . fn2fp
formatFileName NewFormat = text . encodeWhite . fn2fp
formatFileName UserFormat = text . fn2fp