module Darcs.UI.PrintPatch
( contextualPrintPatchWithPager
, printContent
, printContentWithPager
, printFriendly
, printSummary
, showFriendly
, showWithSummary
) where
import Darcs.Prelude
import Darcs.Patch ( description, content, summary )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch.ApplyMonad ( ApplyMonadTrans )
import Darcs.Patch.Show
( ShowContextPatch
, ShowPatch
, ShowPatchFor(ForDisplay)
, showPatchWithContext
)
import Darcs.UI.External ( viewDocWith )
import Darcs.UI.Options.All ( Verbosity(..), WithSummary(..) )
import Darcs.Util.Printer ( Doc, prefix, putDocLnWith, ($$) )
import Darcs.Util.Printer.Color ( fancyPrinters )
printFriendly :: ShowPatch p => Verbosity -> WithSummary -> p wX wY -> IO ()
printFriendly :: forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Verbosity -> WithSummary -> p wX wY -> IO ()
printFriendly Verbosity
v WithSummary
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 -> WithSummary -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Verbosity -> WithSummary -> p wX wY -> Doc
showFriendly Verbosity
v WithSummary
s
showFriendly :: ShowPatch p => Verbosity -> WithSummary -> p wX wY -> Doc
showFriendly :: forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Verbosity -> WithSummary -> p wX wY -> Doc
showFriendly Verbosity
Verbose WithSummary
_ = p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
showWithContents
showFriendly Verbosity
_ WithSummary
YesSummary = p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
showWithSummary
showFriendly Verbosity
_ WithSummary
NoSummary = p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description
showWithSummary :: ShowPatch p => p wX wY -> Doc
showWithSummary :: forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
showWithSummary p wX wY
p = p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description p wX wY
p Doc -> Doc -> Doc
$$ String -> Doc -> Doc
prefix String
" " (p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
summary p wX wY
p)
showWithContents :: ShowPatch p => p wX wY -> Doc
showWithContents :: forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
showWithContents p wX wY
p = p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description p wX wY
p Doc -> Doc -> Doc
$$ String -> Doc -> Doc
prefix String
" " (p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
content p wX wY
p)
printSummary :: ShowPatch p => p wX wY -> IO ()
printSummary :: forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printSummary = 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
. String -> Doc -> Doc
prefix String
" " (Doc -> Doc) -> (p wX wY -> Doc) -> p wX wY -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
summary
printContent :: ShowPatch p => p wX wY -> IO ()
printContent :: forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> IO ()
printContent = 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
. String -> Doc -> Doc
prefix String
" " (Doc -> Doc) -> (p wX wY -> Doc) -> p wX wY -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
content
printContentWithPager :: ShowPatch p => p wX wY -> IO ()
= Printers -> Doc -> IO ()
viewDocWith Printers
fancyPrinters (Doc -> IO ()) -> (p wX wY -> Doc) -> p wX wY -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> Doc
prefix String
" " (Doc -> Doc) -> (p wX wY -> Doc) -> p wX wY -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
content
contextualPrintPatchWithPager
:: (ApplyMonadTrans (ApplyState p) IO, ShowContextPatch p)
=> ApplyState p IO
-> p wX wY
-> IO ()
ApplyState p IO
s p wX wY
p = do
ShowPatchFor -> ApplyState p IO -> p wX wY -> IO Doc
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(ApplyMonadTrans (ApplyState p) m, ShowContextPatch p) =>
ShowPatchFor -> ApplyState p m -> p wX wY -> m Doc
showPatchWithContext ShowPatchFor
ForDisplay ApplyState p IO
s p wX wY
p IO Doc -> (Doc -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Printers -> Doc -> IO ()
viewDocWith Printers
fancyPrinters