2015-05-11 22:25:21 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
|
|
|
(provide gen:prospect-pretty-printable
|
|
|
|
prospect-pretty-print
|
|
|
|
|
2015-12-11 03:34:50 +00:00
|
|
|
prospect-pretty-print->string
|
|
|
|
|
2015-05-23 15:41:43 +00:00
|
|
|
exn->string ;; required from exn-util.rkt
|
2015-05-11 22:25:21 +00:00
|
|
|
string-indent
|
|
|
|
indented-port-output)
|
|
|
|
|
|
|
|
(require racket/generic)
|
|
|
|
(require racket/pretty)
|
|
|
|
(require (only-in racket/string string-join string-split))
|
2015-05-23 15:41:43 +00:00
|
|
|
(require "exn-util.rkt")
|
2015-12-11 02:21:24 +00:00
|
|
|
(require "route.rkt")
|
2015-05-11 22:25:21 +00:00
|
|
|
|
|
|
|
(define-generics prospect-pretty-printable
|
|
|
|
(prospect-pretty-print prospect-pretty-printable [port])
|
2015-12-11 02:21:24 +00:00
|
|
|
#:defaults ([(lambda (x) (and (not (eq? x #f)) (matcher? x)))
|
|
|
|
(define (prospect-pretty-print m [p (current-output-port)])
|
|
|
|
(pretty-print-matcher m p))]
|
|
|
|
[(lambda (x) #t)
|
2015-05-11 22:25:21 +00:00
|
|
|
(define (prospect-pretty-print v [p (current-output-port)])
|
|
|
|
(pretty-write v p))]))
|
|
|
|
|
2015-12-11 03:34:50 +00:00
|
|
|
(define (prospect-pretty-print->string v)
|
|
|
|
(define p (open-output-string))
|
|
|
|
(prospect-pretty-print v p)
|
|
|
|
(get-output-string p))
|
|
|
|
|
2015-05-11 22:25:21 +00:00
|
|
|
(define (string-indent amount s)
|
|
|
|
(define pad (make-string amount #\space))
|
|
|
|
(string-join (for/list [(line (string-split s "\n"))] (string-append pad line)) "\n"))
|
|
|
|
|
2015-12-11 02:21:24 +00:00
|
|
|
(define (indented-port-output amount f #:first-line? [first-line? #t])
|
2015-05-11 22:25:21 +00:00
|
|
|
(define p (open-output-string))
|
|
|
|
(f p)
|
2015-12-11 02:21:24 +00:00
|
|
|
(define fully-indented (string-indent amount (get-output-string p)))
|
|
|
|
(if first-line?
|
|
|
|
fully-indented
|
|
|
|
(substring fully-indented amount)))
|