From 6613f8c597a861b717635784234d2e9b2393cfc0 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Tue, 18 Sep 2018 17:50:49 +0200 Subject: [PATCH] REPL: allow tweaking the implicit IOContext of the REPL This adds an `iocontext::Dict{Symbol,Any}` field to `LineEditREPL`, which can be initialized with `atreplinit`, and updated interactively, e.g. `Base.active_repl.iocontext[:compact] = true`. Fixes #20509. --- stdlib/REPL/src/REPL.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index 977c4af6edb92..16fb3e7496f1d 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -128,7 +128,11 @@ end function display(d::REPLDisplay, mime::MIME"text/plain", x) io = outstream(d.repl) get(io, :color, false) && write(io, answer_color(d.repl)) - show(IOContext(io, :limit => true), mime, x) + if isdefined(d.repl, :iocontext) + # this can override the :limit property set initially + io = foldl(IOContext, d.repl.iocontext, init=IOContext(io, :limit => true)) + end + show(io, mime, x) println(io) nothing end @@ -314,12 +318,14 @@ mutable struct LineEditREPL <: AbstractREPL waserror::Bool specialdisplay::Union{Nothing,AbstractDisplay} options::Options + # default IOContext settings at the REPL + iocontext::Dict{Symbol,Any} mistate::Union{MIState,Nothing} interface::ModalInterface backendref::REPLBackendRef LineEditREPL(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,in_help,envcolors) = new(t,true,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell, - in_help,envcolors,false,nothing, Options(), nothing) + in_help,envcolors,false,nothing, Options(), Dict{Symbol,Any}(), nothing) end outstream(r::LineEditREPL) = r.t specialdisplay(r::LineEditREPL) = r.specialdisplay