module Darcs.UI.PrintPatch
( contextualPrintPatch
, printContent
, printContentWithPager
, printFriendly
, printSummary
, showFriendly
, showWithSummary
) where
import Darcs.Prelude
import Darcs.Patch ( description, showContextPatch, content, summary )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch.Show ( ShowContextPatch, ShowPatch, ShowPatchFor(ForDisplay) )
import Darcs.UI.External ( viewDocWith )
import Darcs.UI.Options.All ( Verbosity(..), WithContext(..), WithSummary(..) )
import Darcs.Util.Printer ( Doc, prefix, putDocLnWith, ($$) )
import Darcs.Util.Printer.Color ( fancyPrinters )
import Darcs.Util.Tree ( Tree )
import Darcs.Util.Tree.Monad ( virtualTreeIO )
printFriendly :: (ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) => Maybe (Tree IO)
-> Verbosity -> WithSummary -> WithContext -> p wX wY -> IO ()
printFriendly (Just pristine) _ _ YesContext = contextualPrintPatch pristine
printFriendly _ v s _ = putDocLnWith fancyPrinters . showFriendly v s
showFriendly :: ShowPatch p => Verbosity -> WithSummary -> p wX wY -> Doc
showFriendly Verbose _ = showWithContents
showFriendly _ YesSummary = showWithSummary
showFriendly _ NoSummary = description
showWithSummary :: ShowPatch p => p wX wY -> Doc
showWithSummary p = description p $$ prefix " " (summary p)
showWithContents :: ShowPatch p => p wX wY -> Doc
showWithContents p = description p $$ prefix " " (content p)
printSummary :: ShowPatch p => p wX wY -> IO ()
printSummary = putDocLnWith fancyPrinters . prefix " " . summary
printContent :: ShowPatch p => p wX wY -> IO ()
printContent = putDocLnWith fancyPrinters . prefix " " . content
printContentWithPager :: ShowPatch p => p wX wY -> IO ()
printContentWithPager = viewDocWith fancyPrinters . prefix " " . content
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