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 )
import Darcs.UI.External ( viewDocWith )
import Darcs.UI.Options.All ( Verbosity(..), Summary(..), WithContext(..) )
import Darcs.Util.Printer ( Doc, putDocLnWith, RenderMode(..) )
printFriendly :: (ShowPatch p, ApplyState p ~ Tree) => Maybe (Tree IO)
-> Verbosity -> Summary -> WithContext -> p wX wY -> IO ()
printFriendly (Just pristine) _ _ YesContext = contextualPrintPatch pristine
printFriendly _ v s _ = putDocLnWith fancyPrinters . showFriendly v s
showFriendly :: ShowPatch p => Verbosity -> Summary -> p wX wY -> Doc
showFriendly Verbose _ = showNicely
showFriendly _ YesSummary = summary
showFriendly _ NoSummary = description
printPatch :: ShowPatch p => p wX wY -> IO ()
printPatch p = putDocLnWith fancyPrinters $ showPatch p
printPatchPager :: ShowPatch p => p wX wY -> IO ()
printPatchPager p = viewDocWith fancyPrinters Standard $ showPatch p
contextualPrintPatch :: (ShowPatch p, ApplyState p ~ Tree) => Tree IO
-> p wX wY -> IO ()
contextualPrintPatch s p = do
(contextedPatch, _) <- virtualTreeIO (showContextPatch p) s
putDocLnWith fancyPrinters contextedPatch