Skip to content

Commit f1662b0

Browse files
committed
avoiding reloading start files on every prompt
adding color banner. I just have a weakness for stuff like that.
1 parent 7c605fe commit f1662b0

File tree

2 files changed

+67
-22
lines changed

2 files changed

+67
-22
lines changed

julia-interpreter.scm

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
"\033[1m \033[32m_\033[37m
930+
\033[36m_\033[37m _ \033[31m_\033[32m(_)\033[35m_\033[37m |
931+
\033[36m(_)\033[37m | \033[31m(_) \033[35m(_)\033[37m | pre-release version
932+
_ _ _| |_ __ _ 2 |
933+
| | | | | | |/ _` | |
934+
| | |_| | | | (_| | | \302\2512009 contributors
935+
_/ |\\__'_|_|_|\\__'_| |
936+
|__/ |\033[0m
937+
938+
"
939+
940+
" _
941+
_ _ _(_)_ |
942+
(_) | (_) (_) | pre-release version
943+
_ _ _| |_ __ _ 2 |
944+
| | | | | | |/ _` | |
945+
| | |_| | | | (_| | | \302\2512009 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 "\033[1m\033[36m"))
976+
(j-toplevel-eval
977+
`(call print (quote ,(j-toplevel-eval (julia-parse line)))))
978+
(if COLOR? (display "\033[0m"))
979+
(newline)
980+
(newline)
981+
(prompt))))))))

start.j

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ function ref(t:Type, params...)
22
return instantiate_type(t, params)
33
end
44

5+
typealias Nullable Union[T,()]
6+
57
function print(x:Any)
68
# default print function, call builtin
79
_print(x)

0 commit comments

Comments
 (0)