File: PrintPatch.hs

package info (click to toggle)
darcs 2.12.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,748 kB
  • sloc: haskell: 42,936; sh: 11,086; ansic: 837; perl: 129; makefile: 8
file content (74 lines) | stat: -rw-r--r-- 3,034 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-- Copyright (C) 2003 David Roundy
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2, or (at your option)
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; see the file COPYING.  If not, write to
-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-- Boston, MA 02110-1301, USA.

{-# LANGUAGE CPP #-}

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.Flags ( DarcsFlag(Summary, Verbose), isUnified )
import Darcs.UI.Options.All ( Verbosity(..), Summary(..), WithContext(..) )

import Darcs.Util.Printer ( Doc, putDocLnWith, RenderMode(..) )

-- | @'printFriendly' opts patch@ prints @patch@ in accordance with the flags
-- in opts, ie, whether @--verbose@ or @--summary@ were passed at the
-- command-line.
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' flags patch@ returns a 'Doc' representing the right
-- way to show @patch@ given the list @flags@ of flags darcs was invoked with.
showFriendly :: ShowPatch p => Verbosity -> Summary -> p wX wY -> Doc
showFriendly Verbose _          = showNicely
showFriendly _       YesSummary = summary
showFriendly _       NoSummary  = description

-- | 'printPatch' prints a patch on standard output.
printPatch :: ShowPatch p => p wX wY -> IO ()
printPatch p = putDocLnWith fancyPrinters $ showPatch p

-- | 'printPatchPager' runs '$PAGER' and shows a patch in it.
printPatchPager :: ShowPatch p => p wX wY -> IO ()
printPatchPager p = viewDocWith fancyPrinters Standard $ showPatch p

-- | 'contextualPrintPatch' prints a patch, together with its context, on
-- standard output.
contextualPrintPatch :: (ShowPatch p, ApplyState p ~ Tree) => Tree IO
                     -> p wX wY -> IO ()
contextualPrintPatch s p = do
    (contextedPatch, _) <- virtualTreeIO (showContextPatch p) s
    putDocLnWith fancyPrinters contextedPatch