Improve printing of patches

This commit is contained in:
Tony Garnock-Jones 2016-07-30 12:27:38 -04:00
parent 129dd23b84
commit 2a2d363c5e
2 changed files with 11 additions and 7 deletions

View File

@ -49,6 +49,7 @@
(require racket/set)
(require racket/match)
(require (only-in racket/string string-trim))
(require "trie.rkt")
(require "tset.rkt")
(require "pretty.rkt")
@ -294,9 +295,9 @@
(define (patch->pretty-string p)
(match-define (patch in out) p)
(format "<<<<<<<< Removed:\n~a======== Added:\n~a>>>>>>>>\n"
(trie->pretty-string out)
(trie->pretty-string in)))
(format "-~a\n+~a\n"
(string-trim #:left? #f (trie->pretty-string out #:indent "-"))
(string-trim #:left? #f (trie->pretty-string in #:indent "+"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -951,10 +951,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Trie [OutputPort] [#:indent Nat] [#:with-parens Boolean] -> Trie
;; Trie [OutputPort] [#:indent (U Nat String)] [#:with-parens Boolean] -> Trie
;; Pretty-prints the given trie on the given port, with
;; second-and-subsequent lines indented by the given amount.
;; Returns the trie.
;; second-and-subsequent lines indented by the given amount (or the
;; given prefix). Returns the trie.
(define (pretty-print-trie m [port (current-output-port)]
#:indent [initial-indent 0]
#:with-parens [with-parens #f])
@ -996,7 +996,10 @@
(when with-parens
(display "{{" port)
(newline port))
(walk (make-string initial-indent #\space) m)
(walk (if (string? initial-indent)
initial-indent
(make-string initial-indent #\space))
m)
(newline port)
(if with-parens
(display "}}" port)