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 (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 ForDisplay p
printPatchPager :: ShowPatch p => p wX wY -> IO ()
printPatchPager p = viewDocWith fancyPrinters $ showPatch ForDisplay p
contextualPrintPatch :: (ShowContextPatch p, ApplyState p ~ Tree) => Tree IO
-> p wX wY -> IO ()
contextualPrintPatch s p = do
(contextedPatch, _) <- virtualTreeIO (showContextPatch ForDisplay p) s
putDocLnWith fancyPrinters contextedPatch