module Darcs.UI.PrintPatch
( printPatch
, contextualPrintPatch
, printPatchPager
, printFriendly
, showFriendly
) where
import Prelude ()
import Darcs.Prelude
import Darcs.Util.Tree.Monad( virtualTreeIO )
import Darcs.Util.Tree( Tree )
import Darcs.Util.Printer.Color ( fancyPrinters )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch ( showContextPatch, showPatch, showNicely, description,
summary )
import Darcs.Patch.Show ( ShowPatch, ShowContextPatch, ShowPatchFor(ForDisplay) )
import Darcs.UI.External ( viewDocWith )
import Darcs.UI.Options.All ( Verbosity(..), Summary(..), WithContext(..) )
import Darcs.Util.Printer ( Doc, putDocLnWith )
printFriendly :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
printFriendly :: Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
printFriendly (Just pristine :: Tree IO
pristine) _ _ YesContext = Tree IO -> p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY.
(ShowContextPatch p, ApplyState p ~ Tree) =>
Tree IO -> p wX wY -> IO ()
contextualPrintPatch Tree IO
pristine
printFriendly _ v :: Verbosity
v s :: Summary
s _ = Printers -> Doc -> IO ()
putDocLnWith Printers
fancyPrinters (Doc -> IO ()) -> (p wX wY -> Doc) -> p wX wY -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Verbosity -> Summary -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Verbosity -> Summary -> p wX wY -> Doc
showFriendly Verbosity
v Summary
s
showFriendly :: ShowPatch p => Verbosity -> Summary -> p wX wY -> Doc
showFriendly :: Verbosity -> Summary -> p wX wY -> Doc
showFriendly Verbose _ = p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
showNicely
showFriendly _ YesSummary = p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
summary
showFriendly _ NoSummary = p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description
printPatch :: ShowPatch p => p wX wY -> IO ()
printPatch :: p wX wY -> IO ()
printPatch p :: p wX wY
p = Printers -> Doc -> IO ()
putDocLnWith Printers
fancyPrinters (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ ShowPatchFor -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
ForDisplay p wX wY
p
printPatchPager :: ShowPatch p => p wX wY -> IO ()
p :: p wX wY
p = Printers -> Doc -> IO ()
viewDocWith Printers
fancyPrinters (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ ShowPatchFor -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
ForDisplay p wX wY
p
contextualPrintPatch :: (ShowContextPatch p, ApplyState p ~ Tree) => Tree IO
-> p wX wY -> IO ()
contextualPrintPatch :: Tree IO -> p wX wY -> IO ()
contextualPrintPatch s :: Tree IO
s p :: p wX wY
p = do
(contextedPatch :: Doc
contextedPatch, _) <- TreeIO Doc -> Tree IO -> IO (Doc, Tree IO)
forall a. TreeIO a -> Tree IO -> IO (a, Tree IO)
virtualTreeIO (ShowPatchFor -> p wX wY -> TreeIO Doc
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(ShowContextPatch p, ApplyMonad (ApplyState p) m) =>
ShowPatchFor -> p wX wY -> m Doc
showContextPatch ShowPatchFor
ForDisplay p wX wY
p) Tree IO
s
Printers -> Doc -> IO ()
putDocLnWith Printers
fancyPrinters Doc
contextedPatch