module Darcs.Patch.Prim.V3.Show
( showHunk )
where
import Prelude hiding ( pi )
import ByteStringUtils ( fromPS2Hex )
import Data.Char ( isSpace, ord, chr )
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import Darcs.Patch.FileHunk ( FileHunk(..), IsHunk(..), showFileHunk )
import Darcs.Patch.FileName ( FileName )
import Darcs.Patch.Format ( PatchListFormat, FileNameFormat(..) )
import Darcs.Patch.Show ( ShowPatchBasic(..), ShowPatch(..), formatFileName )
import Darcs.Patch.Summary ( plainSummaryPrim, plainSummaryPrims )
import Darcs.Patch.Viewing ( showContextHunk )
import Darcs.Patch.Prim.Class ( PrimShow(..) )
import Darcs.Patch.Prim.V3.Core ( Prim(..), Hunk(..), UUID(..) )
import Darcs.Patch.Prim.V3.Details ()
import Darcs.Witnesses.Show ( appPrec, Show1(..), Show2(..), ShowDict(..) )
import Printer ( Doc, renderString, vcat,
text, userchunk, packedString, blueText,
($$), (<+>), (<>),
)
#include "gadts.h"
instance PatchListFormat Prim
instance ShowPatchBasic Prim where
showPatch = showPrim OldFormat
instance ShowPatch Prim where
showContextPatch p = return $ showPatch p
summary = plainSummaryPrim
summaryFL = plainSummaryPrims
thing _ = "change"
instance Show (Prim C(x y)) where
show = renderString . showPrim undefined
instance Show2 Prim where
showDict2 = ShowDictClass
instance Show1 (Prim C(x)) where
showDict1 = ShowDictClass
instance PrimShow Prim where
showPrim _ (TextHunk u h) = showHunk "hunk" u h
showPrim _ (BinaryHunk u h) = showHunk "binhunk" u h
showPrim _ (Manifest f (d,p)) = showManifest "manifest" d f p
showPrim _ (Demanifest f (d,p)) = showManifest "demanifest" d f p
showPrim _ Identity = blueText "identity"
showManifest txt dir file path = blueText txt <+>
formatUUID file <+>
formatUUID dir <+>
packedString (encodeWhite path)
showHunk txt id (Hunk off old new) = blueText txt <+>
formatUUID id <+>
text (show off) <+>
hunktext old <+>
hunktext new
where hunktext bit | B.null bit = text "!"
| otherwise = text "." <> packedString (encodeWhite bit)
formatUUID (UUID x) = packedString x
encodeWhite :: B.ByteString -> B.ByteString
encodeWhite = BC.concatMap encode
where encode c
| isSpace c || c == '\\' = B.concat [ "\\", BC.pack $ show $ ord c, "\\" ]
| otherwise = BC.singleton c