Skip to content

Commit

Permalink
JL_ANSWER_COLOR => JULIA_ANSWER_COLOR; JL_POST_BOOT gone [close #2076]
Browse files Browse the repository at this point in the history
JL_PRIVATE_LIBDIR remains and I wasn't sure what to do about that. It
seems to be unused at this point -- or at least I couldn't find any
usages of it.

This commit also changes the way one controls the answer color during
a repl session: there is now a Main.ANSWER_COLOR variable that you can
modify to change the answer color on the fly. The environment variable
JULIA_ANSWER_COLOR is only checked upon repl startup and not after.
  • Loading branch information
StefanKarpinski committed Jan 18, 2013
1 parent e520030 commit effd690
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
63 changes: 35 additions & 28 deletions base/client.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
## client.jl - frontend handling command line options, environment setup,
## and REPL

have_color = false # default can be altered

const color_normal = "\033[0m"

text_colors = {:black => "\033[1m\033[30m",
:red => "\033[1m\033[31m",
:green => "\033[1m\033[32m",
:yellow => "\033[1m\033[33m",
:blue => "\033[1m\033[34m",
:magenta => "\033[1m\033[35m",
:cyan => "\033[1m\033[36m",
:white => "\033[1m\033[37m",
:normal => color_normal}

function answer_color()
c = symbol(get(ENV, "JL_ANSWER_COLOR", ""))
return get(text_colors, c, "\033[1m\033[34m")
end
const text_colors = {
:black => "\033[1m\033[30m",
:red => "\033[1m\033[31m",
:green => "\033[1m\033[32m",
:yellow => "\033[1m\033[33m",
:blue => "\033[1m\033[34m",
:magenta => "\033[1m\033[35m",
:cyan => "\033[1m\033[36m",
:white => "\033[1m\033[37m",
:normal => "\033[0m",
}

have_color = false
color_answer = text_colors[:blue]
color_normal = text_colors[:normal]

banner() = print(have_color ? banner_color : banner_plain)


exit(n) = ccall(:jl_exit, Void, (Int32,), n)
exit() = exit(0)
quit() = exit()
Expand Down Expand Up @@ -83,7 +79,12 @@ function eval_user_input(ast::ANY, show_value)
global ans = value
if !is(value,nothing) && show_value
if have_color
print(answer_color())
color = color_answer
try
key = symbol(lowercase(string(Main.ANSWER_COLOR)))
color = get(text_colors,key,color_answer)
end
print(color)
end
try repl_show(value)
catch err
Expand Down Expand Up @@ -183,9 +184,6 @@ function process_options(args::Array{Any,1})
repl = true
startup = true
color_set = false
if has(ENV, "JL_POST_BOOT")
eval(Main,parse_input_line(ENV["JL_POST_BOOT"]))
end
i = 1
while i <= length(args)
if args[i]=="-q" || args[i]=="--quiet"
Expand Down Expand Up @@ -320,19 +318,28 @@ function _start()
(quiet,repl,startup,color_set) = process_options(ARGS)

if repl
if startup
try_include(strcat(ENV["HOME"],"/.juliarc.jl"))
end
startup && try_include(joinpath(ENV["HOME"],".juliarc.jl"))

if !color_set
@unix_only global have_color = (begins_with(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`))
@windows_only global have_color = true
end

global is_interactive = true
if !quiet
banner()
quiet || banner()

@unix_only answer_color = "blue"
@windows_only answer_color = "normal"
if has(ENV,"JULIA_ANSWER_COLOR")
answer_color = ENV["JULIA_ANSWER_COLOR"]
elseif has(ENV,"JL_ANSWER_COLOR")
warn("JL_ANSWER_COLOR is deprecated, use JULIA_ANSWER_COLOR instead.")
answer_color = ENV["JL_ANSWER_COLOR"]
end
eval(Main,:(ANSWER_COLOR = $answer_color))
global color_answer
color_answer = get(text_colors,symbol(answer_color),color_answer)

run_repl()
end
catch err
Expand Down
1 change: 1 addition & 0 deletions base/expr.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## symbols ##

symbol(s::Symbol) = s
symbol(s::ASCIIString) = symbol(s.data)
symbol(s::UTF8String) = symbol(s.data)
symbol(a::Array{Uint8,1}) =
Expand Down
1 change: 0 additions & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ compile_hint(hash, (Int,))
compile_hint(isequal, (Symbol, Symbol))
compile_hint(isequal, (Bool, Bool))
compile_hint(WaitFor, (Symbol, RemoteRef))
compile_hint(answer_color, ())
compile_hint(get, (EnvHash, ASCIIString, ASCIIString))
compile_hint(notify_empty, (WorkItem,))
compile_hint(rr2id, (RemoteRef,))
Expand Down

0 comments on commit effd690

Please sign in to comment.