[darcs-devel] darcs patch: rewrite ColourPrinter with a policy data... (and 14 more)

Ian Lynagh igloo at earth.li
Thu Apr 7 05:54:58 PDT 2005


On Wed, Apr 06, 2005 at 08:32:59AM -0400, David Roundy wrote:
> On Wed, Apr 06, 2005 at 07:22:56AM -0400, ptp at lysator.liu.se wrote:
> > I've been working on the color escaping thing, but I ran
> > into a problem.  I think I need more kinds of printers,
> > and/or some special Doc constructors in the Printer module,
> > so that i.e. PatchShow can use a sourceText constructor to
> > send entire lines for trailing space escaping.
> > 
> > Anyhow, the "trailing space patch" shows how it might look
> > like, so people can comment on wished for modifications.
> > It sometimes escpaes spaces in the patch heading.
> 
> I guess you want something perhaps like
> 
> data Printable = S !String
>                | PS !PackedString
>                | Both !String !PackedString
>                | PSLINE !PackedString
> 
> packedStringLn :: PackedString -> Doc
> packedStringLn x = printable . PSLINE
> 
> which we would then use in hunk patches?
> 
> showHunk f line old new =
>            blueText "hunk" <+> fn2d f <+> text (show line)
>         $$ cat (map (\x -> minus <> packedStringLn x) $ readAntiMemo old)
>         $$ cat (map (\x -> plus  <> packedStringLn x) $ readAntiMemo new)
> 
> Note that I changed vcat to cat, since presumably packedStringLn will add
> the trailing newline itself.

It's nicer to use the combinators to put the newlines in as then things
like prefix work. Now I'm wondering if there's a good reason showHunk
doesn't already use prefix, something like

showHunk f line old new =
           blueText "hunk" <+> fn2d f <+> text (show line)
        $$ prefix "-" (vcat $ map packedString $ readAntiMemo old)
        $$ prefix "+" (vcat $ map packedString $ readAntiMemo new)

Anyway, I'm not sure what the point of PSLINE is; don't we just want to
change the packedString calls to (packedString . escape_trailing_spaces)?
Am I missing something?


Thanks
Ian





More information about the darcs-devel mailing list