From 8f2e4ba17b704965f3a35d1d0a312dec31800862 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 2 Sep 2012 20:19:36 +0200 Subject: racket: displaying images also during evaluations --- scheme/racket/geiser/user.rkt | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'scheme/racket/geiser/user.rkt') diff --git a/scheme/racket/geiser/user.rkt b/scheme/racket/geiser/user.rkt index 2eb0cb5..e9540b0 100644 --- a/scheme/racket/geiser/user.rkt +++ b/scheme/racket/geiser/user.rkt @@ -14,12 +14,10 @@ (provide init-geiser-repl run-geiser-server start-geiser) (require (for-syntax racket/base) - file/convertible mzlib/thread - racket/file - racket/pretty racket/tcp geiser + geiser/images geiser/enter geiser/eval geiser/modules) @@ -91,41 +89,14 @@ (printf "racket@~a> " (namespace->module-name (current-namespace) (last-entered))))) -(define image-cache - (let ([ensure-dir (lambda (dir) - (if (path-string? dir) - (begin (make-directory* dir) - (if (path? dir) (path->string dir) dir)) - (path->string (find-system-path 'temp-dir))))]) - (make-parameter (ensure-dir #f) ensure-dir))) - (define (geiser-prompt-read prompt) (make-repl-reader (geiser-read prompt))) -(define (geiser-save-tmpimage imgbytes) - ;; Save imgbytes to a new temporary file and return the filename - (define filename (make-temporary-file "geiser-img-~a.png" #f (image-cache))) - (with-output-to-file filename #:exists 'truncate - (lambda () (display imgbytes))) - filename) - -(define (geiser-maybe-print-image value) - (cond - [(and (convertible? value) - (convert value 'png-bytes)) - => (lambda (pngbytes) - ;; (The above could be problematic if a future version of racket - ;; suddenly decides it can "convert" strings to picts) - (printf "#\n" (geiser-save-tmpimage pngbytes)))] - [else - (unless (void? value) - (pretty-print value))])) - (define (init-geiser-repl) (compile-enforce-module-constants #f) (current-load/use-compiled geiser-loader) (current-prompt-read (geiser-prompt-read geiser-prompt)) - (current-print geiser-maybe-print-image)) + (current-print maybe-print-image)) (define (run-geiser-repl in out enforce-module-constants) (parameterize [(compile-enforce-module-constants enforce-module-constants) @@ -134,7 +105,7 @@ (current-error-port out) (current-load/use-compiled geiser-loader) (current-prompt-read (geiser-prompt-read geiser-prompt)) - (current-print geiser-maybe-print-image)] + (current-print maybe-print-image)] (read-eval-print-loop))) (define server-channel (make-channel)) -- cgit v1.2.3