diff --git a/base/REPL.jl b/base/REPL.jl index 6829ade7ae890..d2dc73da5b10c 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -125,10 +125,10 @@ module REPL end end - using Terminals - using Readline + using Base.Terminals + using Base.Readline - import Readline: char_move_left, char_move_word_left, CompletionProvider, completeLine + import Base.Readline: char_move_left, char_move_word_left, CompletionProvider, completeLine type ReadlineREPL <: AbstractREPL t::TextTerminal @@ -153,7 +153,7 @@ module REPL r::ReadlineREPL end - using REPLCompletions + using Base.REPLCompletions function completeLine(c::REPLCompletionProvider,s) partial = bytestring(s.input_buffer.data[1:position(s.input_buffer)]) @@ -168,7 +168,7 @@ module REPL return (ret, partial[range]) end - import Readline: HistoryProvider, add_history, history_prev, history_next, history_search + import Base.Readline: HistoryProvider, add_history, history_prev, history_next, history_search type REPLHistoryProvider <: HistoryProvider history::Array{String,1} @@ -329,7 +329,6 @@ module REPL Readline.reset_state(hist::REPLHistoryProvider) = history_reset_state(hist) const julia_green = "\033[1m\033[32m" - const color_normal = Base.color_normal function return_callback(repl,s) if position(s.input_buffer) != 0 && eof(s.input_buffer) && @@ -383,7 +382,7 @@ module REPL end end - import Terminals: raw! + import Base.Terminals: raw! function reset(d::REPLDisplay) raw!(d.repl.t,false) @@ -473,7 +472,7 @@ module REPL (hkp,hkeymap) = Readline.setup_search_keymap(hp) - # Canoniczlize user keymap input + # Canonicalize user keymap input if isa(extra_repl_keymap,Dict) extra_repl_keymap = [extra_repl_keymap] end @@ -569,7 +568,6 @@ module REPL repl_channel = RemoteRef() response_channel = RemoteRef() start_repl_backend(repl_channel, response_channel) - banner(t,t) run_frontend(ReadlineREPL(t),repl_channel,response_channel) end @@ -639,7 +637,7 @@ module REPL if !isempty(line) ast = Base.parse_input_line(line) if have_color - print(repl.stream,color_normal) + print(repl.stream, Base.color_normal) end put!(repl_channel, (ast,1)) (val, bt) = take!(response_channel) diff --git a/base/Readline.jl b/base/Readline.jl index cdc72b198feac..92bf62546bc72 100644 --- a/base/Readline.jl +++ b/base/Readline.jl @@ -1,8 +1,8 @@ - module Readline - using Terminals +module Readline + using Base.Terminals - import Terminals: raw!, width, height, cmove, Rect, Size, getX, - getY, clear_line, beep + import Base.Terminals: raw!, width, height, cmove, Rect, Size, getX, + getY, clear_line, beep import Base: ensureroom, peek @@ -1134,4 +1134,4 @@ raw!(terminal,false) && Terminals.Unix.disable_bracketed_paste(terminal) end end -end \ No newline at end of file +end diff --git a/base/Terminals.jl b/base/Terminals.jl index 1e67acb8c12cd..b6a6f2daa3462 100644 --- a/base/Terminals.jl +++ b/base/Terminals.jl @@ -1,7 +1,7 @@ module Terminals import Base.size, Base.write, Base.flush abstract TextTerminal <: Base.IO - export TextTerminal, NCurses, writepos, cmove, pos, getX, getY, hascolor + export TextTerminal, writepos, cmove, pos, getX, getY, hascolor # Stuff that really should be in a Geometry package immutable Rect @@ -16,7 +16,6 @@ module Terminals height end - # INTERFACE size(::TextTerminal) = error("Unimplemented") writepos(t::TextTerminal,x,y,s::Array{Uint8,1}) = error("Unimplemented") @@ -83,7 +82,7 @@ module Terminals module Attributes # This is just to get started and will have to be revised - import Terminals.TextAttribute, Terminals.TextTerminal + import ..Terminals: TextAttribute, TextTerminal export Standout, Underline, Reverse, Blink, Dim, Bold, AltCharset, Invisible, Protect, Left, Right, Top, Vertical, Horizontal, Low @@ -129,10 +128,9 @@ module Terminals end module Colors - import Terminals.TextAttribute, Terminals.TextTerminal, Terminals.Attributes.attr_simplify - using Color + import ..Terminals: TextAttribute, TextTerminal - export TerminalColor, TextColor, BackgroundColor, ForegroundColor, approximate, + export TerminalColor, TextColor, BackgroundColor, ForegroundColor, lookup_color, terminal_color, maxcolors, maxcolorpairs, palette, numcolors # Represents a color actually displayable by the current terminal @@ -145,13 +143,6 @@ module Terminals c::TerminalColor end - function approximate(t::TextTerminal, c::ColorValue) - x = keys(palette(t)) - lookup_color(t,x[indmin(map(x->colordiff(c,x),x))]) - end - - attr_simplify(t::TextTerminal, c::ColorValue) = TextColor(lookup_color(t,c)) - # Terminals should implement this lookup_color(t::TextTerminal) = error("Unimplemented") maxcolors(t::TextTerminal) = error("Unimplemented") @@ -161,10 +152,10 @@ module Terminals end module Unix - importall Terminals + importall ..Terminals - import Terminals: width, height, cmove, Rect, Size, getX, - getY, raw!, clear, clear_line, beep, hascolor + import ..Terminals: width, height, cmove, Rect, Size, getX, + getY, raw!, clear, clear_line, beep, hascolor import Base: size, read, write, flush, TTY, writemime, readuntil, start_reading, stop_reading export UnixTerminal @@ -218,4 +209,4 @@ module Terminals end importall .Unix export UnixTerminal -end \ No newline at end of file +end diff --git a/base/client.jl b/base/client.jl index 15e80c88d78c3..fa79b07a6fff5 100644 --- a/base/client.jl +++ b/base/client.jl @@ -145,65 +145,6 @@ end _repl_start = Condition() -function run_repl() - global const repl_channel = RemoteRef() - - ccall(:jl_init_repl, Void, (Cint,), _use_history) - - # install Ctrl-C interrupt handler (InterruptException) - ccall(:jl_install_sigint_handler, Void, ()) - buf = Array(Uint8) - global _repl_enough_stdin = true - input = @async begin - try - while true - if _repl_enough_stdin - wait(_repl_start) - end - try - if eof(STDIN) # if TTY, can throw InterruptException, must be in try/catch block - return - end - read!(STDIN, buf) - ccall(:jl_read_buffer,Void,(Ptr{Void},Cssize_t),buf,length(buf)) - catch ex - if isa(ex,InterruptException) - println(STDOUT, "^C") - ccall(:jl_reset_input,Void,()) - repl_callback(nothing, 0) - else - rethrow(ex) - end - end - end - finally - put!(repl_channel,(nothing,-1)) - end - end - - while !istaskdone(input) - if have_color - prompt_string = "\01\033[1m\033[32m\02julia> \01\033[0m"*input_color()*"\02" - else - prompt_string = "julia> " - end - ccall(:repl_callback_enable, Void, (Ptr{Uint8},), prompt_string) - global _repl_enough_stdin = false - notify(_repl_start) - start_reading(STDIN) - (ast, show_value) = take!(repl_channel) - if show_value == -1 - # exit flag - break - end - eval_user_input(ast, show_value!=0) - end - - if have_color - print(color_normal) - end -end - function parse_input_line(s::String) # s = bytestring(s) # (expr, pos) = parse(s, 1) @@ -373,6 +314,9 @@ function early_init() start_gc_msgs_task() end +import .Terminals +import .REPL + function _start() early_init() @@ -382,17 +326,15 @@ function _start() (quiet,repl,startup,color_set,history) = process_options(copy(ARGS)) global _use_history = history + local term if repl + term = Terminals.UnixTerminal(get(ENV,"TERM",""),STDIN,STDOUT,STDERR) if !isa(STDIN,TTY) global is_interactive = !isa(STDIN,Union(File,IOStream)) color_set || (global have_color = false) else global is_interactive = true - if !color_set - @windows_only global have_color = true - @unix_only global have_color = - (beginswith(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`)) - end + color_set || (global have_color = Terminals.hascolor(term)) end end @@ -415,8 +357,9 @@ function _start() end quit() end - quiet || banner() - run_repl() + quiet || REPL.banner(term,term) + ccall(:jl_install_sigint_handler, Void, ()) + REPL.run_repl(term) end catch err display_error(err,catch_backtrace()) diff --git a/base/precompile.jl b/base/precompile.jl index c83700dd2fcc5..c341e65a67307 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -8,7 +8,6 @@ precompile(isempty, (Array{Any,1},)) precompile(getindex, (Dict{Any,Any}, Int32)) precompile(_start, ()) precompile(process_options, (Array{Any,1},)) -precompile(run_repl, ()) precompile(any, (Function, Array{Any,1})) precompile(Dict{Any,Any}, (Int,)) precompile(Set, ()) diff --git a/base/repl.jl b/base/replutil.jl similarity index 100% rename from base/repl.jl rename to base/replutil.jl diff --git a/base/sysimg.jl b/base/sysimg.jl index 33c990b58dbbb..471ad54d9dd4e 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -132,9 +132,7 @@ include("multi.jl") # Polling (requires multi.jl) include("poll.jl") -# front end & code loading -include("repl.jl") -include("client.jl") +# code loading include("loading.jl") begin @@ -185,6 +183,14 @@ using .I18n using .Help push!(I18n.CALLBACKS, Help.clear_cache) +# frontend +include("Terminals.jl") +include("Readline.jl") +include("REPLCompletions.jl") +include("REPL.jl") +include("replutil.jl") +include("client.jl") + # sparse matrices and linear algebra include("sparse.jl") importall .SparseMatrix diff --git a/test/Makefile b/test/Makefile index 9ca4f50a859d0..1ddaeae43bcb0 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,11 +2,12 @@ JULIAHOME = $(abspath ..) include ../Make.inc TESTS = all core keywordargs numbers strings unicode collections hashing \ - remote iobuffer arrayops linalg blas fft dsp sparse bitarray random \ + remote iobuffer arrayops linalg blas fft dsp sparse bitarray random \ math functional bigint sorting statistics spawn parallel arpack file \ git pkg resolve suitesparse complex version pollfd mpfr broadcast \ socket floatapprox priorityqueue readdlm regex float16 combinatorics \ - sysinfo rounding ranges mod2pi euler show linalg1 linalg2 + sysinfo rounding ranges mod2pi euler show linalg1 linalg2 readline \ + replcompletions default: all diff --git a/test/readline.jl b/test/readline.jl index 24ed6928cb504..849aba478d02d 100644 --- a/test/readline.jl +++ b/test/readline.jl @@ -1,4 +1,4 @@ -using Base.Test +using Base.Readline a_foo = 0 @@ -43,4 +43,4 @@ run_test(test2_func,IOBuffer("aaabb")) run_test(test3_func,IOBuffer("aab")) @test a_bar == 2 -@test b_bar == 1 \ No newline at end of file +@test b_bar == 1 diff --git a/test/replcompletions.jl b/test/replcompletions.jl index 0f7461e84ae93..a3692de07a57a 100644 --- a/test/replcompletions.jl +++ b/test/replcompletions.jl @@ -1,5 +1,4 @@ -using REPLCompletions -using Base.Test +using Base.REPLCompletions module CompletionFoo module CompletionFoo2 @@ -42,30 +41,31 @@ c,r = test_complete(s) @test r == 20:20 @test s[r] == "f" -# Test completion of packages -mkp(p) = ((@assert !isdir(p)); mkdir(p)) -mkp(Pkg.dir("MyAwesomePackage")) -mkp(Pkg.dir("CompletionFooPackage")) - -s = "using MyAwesome" -c,r = test_complete(s) -@test in("MyAwesomePackage",c) -@test s[r] == "MyAwesome" - -s = "using Completion" -c,r = test_complete(s) -@test in("CompletionFoo",c) #The module -@test in("CompletionFooPackage",c) #The package -@test s[r] == "Completion" - -s = "using CompletionFoo.Completion" -c,r = test_complete(s) -@test in("CompletionFoo2",c) -@test s[r] == "Completion" - -rmdir(Pkg.dir("MyAwesomePackage")) -rmdir(Pkg.dir("CompletionFooPackage")) - +## Test completion of packages +#mkp(p) = ((@assert !isdir(p)); mkdir(p)) +#temp_pkg_dir() do +# mkp(Pkg.dir("MyAwesomePackage")) +# mkp(Pkg.dir("CompletionFooPackage")) +# +# s = "using MyAwesome" +# c,r = test_complete(s) +# @test in("MyAwesomePackage",c) +# @test s[r] == "MyAwesome" +# +# s = "using Completion" +# c,r = test_complete(s) +# @test in("CompletionFoo",c) #The module +# @test in("CompletionFooPackage",c) #The package +# @test s[r] == "Completion" +# +# s = "using CompletionFoo.Completion" +# c,r = test_complete(s) +# @test in("CompletionFoo2",c) +# @test s[r] == "Completion" +# +# rmdir(Pkg.dir("MyAwesomePackage")) +# rmdir(Pkg.dir("CompletionFooPackage")) +#end @unix_only begin #Assume that we can rely on the existence and accessibility of /tmp diff --git a/test/runtests.jl b/test/runtests.jl index 1462b6cb508b6..4584c1b691a07 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,8 @@ testnames = [ "priorityqueue", "arpack", "file", "suitesparse", "version", "resolve", "pollfd", "mpfr", "broadcast", "complex", "socket", "floatapprox", "readdlm", "regex", "float16", "combinatorics", - "sysinfo", "rounding", "ranges", "mod2pi", "euler", "show" + "sysinfo", "rounding", "ranges", "mod2pi", "euler", "show", + "readline", "replcompletions" ] @unix_only push!(testnames, "unicode")