@@ -910,29 +910,72 @@ not likely to be implemented in interpreter:
910910
911911(make-builtin '_print julia-print)
912912
913+ (define (detect-color )
914+ (let ((tput (shell-command " tput setaf 9 >&/dev/null" )))
915+ (if (= tput 0 )
916+ #t
917+ (if (= tput 1 )
918+ #f
919+ (let ((Tenv (with-exception-catcher
920+ (lambda (e ) #f)
921+ (lambda () (getenv " TERM" )))))
922+ (or (equal? Tenv " xterm" )
923+ (equal? Tenv " xterm-color" )))))))
924+
925+ (define COLOR? (detect-color))
926+
927+ (define banner
928+ (if COLOR?
929+ " \0 33[1m \0 33[32m_\0 33[37m
930+ \0 33[36m_\0 33[37m _ \0 33[31m_\0 33[32m(_)\0 33[35m_\0 33[37m |
931+ \0 33[36m(_)\0 33[37m | \0 33[31m(_) \0 33[35m(_)\0 33[37m | pre-release version
932+ _ _ _| |_ __ _ 2 |
933+ | | | | | | |/ _` | |
934+ | | |_| | | | (_| | | \3 02\2 512009 contributors
935+ _/ |\\ __'_|_|_|\\ __'_| |
936+ |__/ |\0 33[0m
937+
938+ "
939+
940+ " _
941+ _ _ _(_)_ |
942+ (_) | (_) (_) | pre-release version
943+ _ _ _| |_ __ _ 2 |
944+ | | | | | | |/ _` | |
945+ | | |_| | | | (_| | | \3 02\2 512009 contributors
946+ _/ |\\ __'_|_|_|\\ __'_| |
947+ |__/ |
948+
949+ "
950+ ))
951+
913952(define (julia-repl )
914953 (j-load " start.j" )
915954 (j-load " array.j" )
916955 (j-load " examples.j" )
917-
918- (display " julia> " )
919- (let ((line (read-line)))
920- (if (eof-object? line)
921- (newline)
922- (begin
923- (with-exception-catcher
924- (lambda (e )
925- ; (raise e)
926- (display (error-exception-message e))
927- (for-each (lambda (x )
928- (display " " ) (display x))
929- (error-exception-parameters e))
930- (newline)
931- (newline)
932- (julia-repl))
933- (lambda ()
934- (j-toplevel-eval
935- `(call print (quote ,(j-toplevel-eval (julia-parse line)) )))
936- (newline)
937- (newline)
938- (julia-repl)))))))
956+ (display banner)
957+
958+ (let prompt ()
959+ (display " julia> " )
960+ (let ((line (read-line)))
961+ (if (eof-object? line)
962+ (newline)
963+ (begin
964+ (with-exception-catcher
965+ (lambda (e )
966+ ; (raise e)
967+ (display (error-exception-message e))
968+ (for-each (lambda (x )
969+ (display " " ) (display x))
970+ (error-exception-parameters e))
971+ (newline)
972+ (newline)
973+ (prompt))
974+ (lambda ()
975+ (if COLOR? (display " \0 33[1m\0 33[36m" ))
976+ (j-toplevel-eval
977+ `(call print (quote ,(j-toplevel-eval (julia-parse line)) )))
978+ (if COLOR? (display " \0 33[0m" ))
979+ (newline)
980+ (newline)
981+ (prompt))))))))
0 commit comments