@@ -34,7 +34,7 @@ import ..LineEdit:
3434
3535abstract AbstractREPL
3636
37- answer_color (:: AbstractREPL ) = " "
37+ answer_color_symbol (:: AbstractREPL ) = :plain
3838
3939type REPLBackend
4040 repl_channel:: Channel
@@ -109,18 +109,18 @@ end
109109== (a:: REPLDisplay , b:: REPLDisplay ) = a. repl === b. repl
110110
111111function 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
116116end
117117display (d:: REPLDisplay , x) = display (d, MIME (" text/plain" ), x)
118118
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 )
120120 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))
122122end
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 )
124124 while true
125125 try
126126 if bt != = nothing
@@ -215,7 +215,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
215215 put! (repl_channel, (ast, 1 ))
216216 val, bt = take! (response_channel)
217217 if ! ends_with_semicolon (line)
218- print_response (repl, val, bt, true , false )
218+ print_response (repl, val, bt, true )
219219 end
220220 end
221221 write (repl. terminal, ' \n ' )
@@ -233,7 +233,7 @@ type LineEditREPL <: AbstractREPL
233233 hascolor:: Bool
234234 prompt_color:: AbstractString
235235 input_color:: AbstractString
236- answer_color :: AbstractString
236+ answer_color_symbol :: Symbol
237237 shell_color:: AbstractString
238238 help_color:: AbstractString
239239 history_file:: Bool
@@ -248,16 +248,16 @@ type LineEditREPL <: AbstractREPL
248248 new (t,true ,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
249249 in_help,envcolors,false ,nothing )
250250end
251- outstream (r:: LineEditREPL ) = r. t
251+ outstream (r:: LineEditREPL ) = r. hascolor ? IOContext (r . t, :ansi => true ) : r . t
252252specialdisplay (r:: LineEditREPL ) = r. specialdisplay
253253specialdisplay (r:: AbstractREPL ) = nothing
254254terminal (r:: LineEditREPL ) = r. t
255255
256256LineEditREPL (t:: TextTerminal , envcolors = false ) = LineEditREPL (t,
257257 true ,
258- julia_green ,
258+ Base . text_colors[ :green ] ,
259259 Base. input_color (),
260- Base. answer_color (),
260+ Base. answer_color_symbol (),
261261 Base. text_colors[:red ],
262262 Base. text_colors[:yellow ],
263263 false , false , false , envcolors)
@@ -579,8 +579,6 @@ function history_reset_state(hist::REPLHistoryProvider)
579579end
580580LineEdit. reset_state (hist:: REPLHistoryProvider ) = history_reset_state (hist)
581581
582- const julia_green = " \0 33[1m\0 33[32m"
583-
584582function return_callback (s)
585583 ast = Base. syntax_deprecation_warnings (false ) do
586584 Base. parse_input_line (bytestring (LineEdit. buffer (s)))
@@ -621,7 +619,7 @@ function respond(f, repl, main; pass_empty = false)
621619 reset (repl)
622620 val, bt = send_to_backend (f (line), backend (repl))
623621 if ! ends_with_semicolon (line) || bt != = nothing
624- print_response (repl, val, bt, true , Base . have_color )
622+ print_response (repl, val, bt, true )
625623 end
626624 end
627625 prepare_next (repl)
@@ -748,7 +746,7 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
748746 finalizer (replc, replc-> close (f))
749747 hist_from_file (hp, f)
750748 catch e
751- print_response (repl, e, catch_backtrace (), true , Base . have_color )
749+ print_response (repl, e, catch_backtrace (), true )
752750 println (outstream (repl))
753751 info (" Disabling history file for this session." )
754752 repl. history_file = false
@@ -865,30 +863,23 @@ function run_frontend(repl::LineEditREPL, backend)
865863 dopushdisplay && popdisplay (d)
866864end
867865
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-
875866# # StreamREPL ##
876867
877868type StreamREPL <: AbstractREPL
878869 stream:: IO
879870 prompt_color:: AbstractString
880871 input_color:: AbstractString
881- answer_color :: AbstractString
872+ answer_color_symbol :: Symbol
882873 waserror:: Bool
883874 StreamREPL (stream,pc,ic,ac) = new (stream,pc,ic,ac,false )
884875end
885876
886877outstream (s:: StreamREPL ) = s. stream
887878
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 ())
889880
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
892883input_color (r:: LineEditREPL ) = r. envcolors ? Base. input_color () : r. input_color
893884input_color (r:: StreamREPL ) = r. input_color
894885
@@ -917,14 +908,14 @@ end
917908
918909function run_frontend (repl:: StreamREPL , backend:: REPLBackendRef )
919910 have_color = Base. have_color
920- banner (repl. stream, have_color )
911+ Base . banner (repl. stream)
921912 d = REPLDisplay (repl)
922913 dopushdisplay = ! in (d,Base. Multimedia. displays)
923914 dopushdisplay && pushdisplay (d)
924915 repl_channel, response_channel = backend. repl_channel, backend. response_channel
925916 while repl. stream. open
926917 if have_color
927- print (repl. stream,repl. prompt_color)
918+ print (repl. stream, repl. prompt_color)
928919 end
929920 print (repl. stream, " julia> " )
930921 if have_color
@@ -939,7 +930,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
939930 put! (repl_channel, (ast, 1 ))
940931 val, bt = take! (response_channel)
941932 if ! ends_with_semicolon (line)
942- print_response (repl, val, bt, true , have_color )
933+ print_response (repl, val, bt, true )
943934 end
944935 end
945936 end
0 commit comments