@@ -34,7 +34,7 @@ import ..LineEdit:
34
34
35
35
abstract AbstractREPL
36
36
37
- answer_color (:: AbstractREPL ) = " "
37
+ answer_color_symbol (:: AbstractREPL ) = :plain
38
38
39
39
type REPLBackend
40
40
repl_channel:: Channel
@@ -109,18 +109,18 @@ end
109
109
== (a:: REPLDisplay , b:: REPLDisplay ) = a. repl === b. repl
110
110
111
111
function display (d:: REPLDisplay , :: MIME"text/plain" , x)
112
- io = outstream (d. repl)
113
- Base . have_color && write (io, answer_color (d . repl) )
114
- writemime (io, MIME ( " text/plain " ), x )
115
- println (io)
112
+ Base . with_output_color ( answer_color_symbol (d . repl), outstream (d. repl)) do io
113
+ writemime (io, MIME ( " text/plain " ), x )
114
+ println (io )
115
+ end
116
116
end
117
117
display (d:: REPLDisplay , x) = display (d, MIME (" text/plain" ), x)
118
118
119
- function print_response (repl:: AbstractREPL , val:: ANY , bt, show_value:: Bool , have_color :: Bool )
119
+ function print_response (repl:: AbstractREPL , val:: ANY , bt, show_value:: Bool )
120
120
repl. waserror = bt != = nothing
121
- print_response (outstream (repl), val, bt, show_value, have_color, specialdisplay (repl))
121
+ print_response (outstream (repl), val, bt, show_value, specialdisplay (repl))
122
122
end
123
- function print_response (errio:: IO , val:: ANY , bt, show_value:: Bool , have_color :: Bool , specialdisplay= nothing )
123
+ function print_response (errio:: IO , val:: ANY , bt, show_value:: Bool , specialdisplay= nothing )
124
124
while true
125
125
try
126
126
if bt != = nothing
@@ -215,7 +215,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
215
215
put! (repl_channel, (ast, 1 ))
216
216
val, bt = take! (response_channel)
217
217
if ! ends_with_semicolon (line)
218
- print_response (repl, val, bt, true , false )
218
+ print_response (repl, val, bt, true )
219
219
end
220
220
end
221
221
write (repl. terminal, ' \n ' )
@@ -233,7 +233,7 @@ type LineEditREPL <: AbstractREPL
233
233
hascolor:: Bool
234
234
prompt_color:: AbstractString
235
235
input_color:: AbstractString
236
- answer_color :: AbstractString
236
+ answer_color_symbol :: Symbol
237
237
shell_color:: AbstractString
238
238
help_color:: AbstractString
239
239
history_file:: Bool
@@ -248,16 +248,16 @@ type LineEditREPL <: AbstractREPL
248
248
new (t,true ,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
249
249
in_help,envcolors,false ,nothing )
250
250
end
251
- outstream (r:: LineEditREPL ) = r. t
251
+ outstream (r:: LineEditREPL ) = r. hascolor ? IOContext (r . t, :ansi => true ) : r . t
252
252
specialdisplay (r:: LineEditREPL ) = r. specialdisplay
253
253
specialdisplay (r:: AbstractREPL ) = nothing
254
254
terminal (r:: LineEditREPL ) = r. t
255
255
256
256
LineEditREPL (t:: TextTerminal , envcolors = false ) = LineEditREPL (t,
257
257
true ,
258
- julia_green ,
258
+ Base . text_colors[ :green ] ,
259
259
Base. input_color (),
260
- Base. answer_color (),
260
+ Base. answer_color_symbol (),
261
261
Base. text_colors[:red ],
262
262
Base. text_colors[:yellow ],
263
263
false , false , false , envcolors)
@@ -579,8 +579,6 @@ function history_reset_state(hist::REPLHistoryProvider)
579
579
end
580
580
LineEdit. reset_state (hist:: REPLHistoryProvider ) = history_reset_state (hist)
581
581
582
- const julia_green = " \0 33[1m\0 33[32m"
583
-
584
582
function return_callback (s)
585
583
ast = Base. syntax_deprecation_warnings (false ) do
586
584
Base. parse_input_line (bytestring (LineEdit. buffer (s)))
@@ -621,7 +619,7 @@ function respond(f, repl, main; pass_empty = false)
621
619
reset (repl)
622
620
val, bt = send_to_backend (f (line), backend (repl))
623
621
if ! ends_with_semicolon (line) || bt != = nothing
624
- print_response (repl, val, bt, true , Base . have_color )
622
+ print_response (repl, val, bt, true )
625
623
end
626
624
end
627
625
prepare_next (repl)
@@ -748,7 +746,7 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
748
746
finalizer (replc, replc-> close (f))
749
747
hist_from_file (hp, f)
750
748
catch e
751
- print_response (repl, e, catch_backtrace (), true , Base . have_color )
749
+ print_response (repl, e, catch_backtrace (), true )
752
750
println (outstream (repl))
753
751
info (" Disabling history file for this session." )
754
752
repl. history_file = false
@@ -865,30 +863,23 @@ function run_frontend(repl::LineEditREPL, backend)
865
863
dopushdisplay && popdisplay (d)
866
864
end
867
865
868
- if isdefined (Base, :banner_color )
869
- banner (io, t) = banner (io, hascolor (t))
870
- banner (io, x:: Bool ) = print (io, x ? Base. banner_color : Base. banner_plain)
871
- else
872
- banner (io,t) = Base. banner (io)
873
- end
874
-
875
866
# # StreamREPL ##
876
867
877
868
type StreamREPL <: AbstractREPL
878
869
stream:: IO
879
870
prompt_color:: AbstractString
880
871
input_color:: AbstractString
881
- answer_color :: AbstractString
872
+ answer_color_symbol :: Symbol
882
873
waserror:: Bool
883
874
StreamREPL (stream,pc,ic,ac) = new (stream,pc,ic,ac,false )
884
875
end
885
876
886
877
outstream (s:: StreamREPL ) = s. stream
887
878
888
- StreamREPL (stream:: IO ) = StreamREPL (stream, julia_green , Base. text_colors[:white ], Base. answer_color ())
879
+ StreamREPL (stream:: IO ) = StreamREPL (stream, Base . text_colors[ :green ] , Base. text_colors[:white ], Base. answer_color_symbol ())
889
880
890
- answer_color (r:: LineEditREPL ) = r. envcolors ? Base. answer_color () : r. answer_color
891
- answer_color (r:: StreamREPL ) = r. answer_color
881
+ answer_color_symbol (r:: LineEditREPL ) = r. envcolors ? Base. answer_color_symbol () : r. answer_color_symbol
882
+ answer_color_symbol (r:: StreamREPL ) = r. answer_color_symbol
892
883
input_color (r:: LineEditREPL ) = r. envcolors ? Base. input_color () : r. input_color
893
884
input_color (r:: StreamREPL ) = r. input_color
894
885
@@ -917,14 +908,14 @@ end
917
908
918
909
function run_frontend (repl:: StreamREPL , backend:: REPLBackendRef )
919
910
have_color = Base. have_color
920
- banner (repl. stream, have_color )
911
+ Base . banner (repl. stream)
921
912
d = REPLDisplay (repl)
922
913
dopushdisplay = ! in (d,Base. Multimedia. displays)
923
914
dopushdisplay && pushdisplay (d)
924
915
repl_channel, response_channel = backend. repl_channel, backend. response_channel
925
916
while repl. stream. open
926
917
if have_color
927
- print (repl. stream,repl. prompt_color)
918
+ print (repl. stream, repl. prompt_color)
928
919
end
929
920
print (repl. stream, " julia> " )
930
921
if have_color
@@ -939,7 +930,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
939
930
put! (repl_channel, (ast, 1 ))
940
931
val, bt = take! (response_channel)
941
932
if ! ends_with_semicolon (line)
942
- print_response (repl, val, bt, true , have_color )
933
+ print_response (repl, val, bt, true )
943
934
end
944
935
end
945
936
end
0 commit comments