Skip to content

Commit c62f4ea

Browse files
LilithHafnerc42f
andauthored
Add command line option for short banner (#50726)
``` o | Version 1.10.0-beta1 (2023-07-25) o o | Official https://julialang.org/ release ``` --------- Co-authored-by: Claire Foster <[email protected]>
1 parent 2a8eca3 commit c62f4ea

File tree

5 files changed

+68
-43
lines changed

5 files changed

+68
-43
lines changed

base/client.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ function exec_options(opts)
325325
end
326326
end
327327
if repl || is_interactive::Bool
328-
if interactiveinput
329-
banner = (opts.banner != 0) # --banner!=no
330-
else
331-
banner = (opts.banner == 1) # --banner=yes
332-
end
328+
b = opts.banner
329+
auto = b == -1
330+
banner = b == 0 || (auto && !interactiveinput) ? :no :
331+
b == 1 || (auto && interactiveinput) ? :yes :
332+
:short # b == 2
333333
run_main_repl(interactiveinput, quiet, banner, history_file, color_set)
334334
end
335335
nothing
@@ -409,14 +409,14 @@ end
409409
global active_repl
410410

411411
# run the requested sort of evaluation loop on stdio
412-
function run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
412+
function run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
413413
load_InteractiveUtils()
414414

415415
if interactive && isassigned(REPL_MODULE_REF)
416416
invokelatest(REPL_MODULE_REF[]) do REPL
417417
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
418418
term = REPL.Terminals.TTYTerminal(term_env, stdin, stdout, stderr)
419-
banner && Base.banner(term)
419+
banner == :no || Base.banner(term, short=banner==:short)
420420
if term.term_type == "dumb"
421421
repl = REPL.BasicREPL(term)
422422
quiet || @warn "Terminal not fully functional"
@@ -436,7 +436,7 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_fil
436436
if interactive && !quiet
437437
@warn "REPL provider not available: using basic fallback"
438438
end
439-
banner && Base.banner()
439+
banner == :no || Base.banner(short=banner==:short)
440440
let input = stdin
441441
if isa(input, File) || isa(input, IOStream)
442442
# for files, we can slurp in the whole thing at once

base/version.jl

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ end
267267

268268
libllvm_path() = ccall(:jl_get_libllvm, Any, ())
269269

270-
function banner(io::IO = stdout)
270+
function banner(io::IO = stdout; short = false)
271271
if GIT_VERSION_INFO.tagged_commit
272272
commit_string = TAGGED_RELEASE_BANNER
273273
elseif isempty(GIT_VERSION_INFO.commit)
@@ -298,27 +298,41 @@ function banner(io::IO = stdout)
298298
d3 = c[:bold] * c[:green] # third dot
299299
d4 = c[:bold] * c[:magenta] # fourth dot
300300

301-
print(io,""" $(d3)_$(tx)
302-
$(d1)_$(tx) $(jl)_$(tx) $(d2)_$(d3)(_)$(d4)_$(tx) | Documentation: https://docs.julialang.org
303-
$(d1)(_)$(jl) | $(d2)(_)$(tx) $(d4)(_)$(tx) |
304-
$(jl)_ _ _| |_ __ _$(tx) | Type \"?\" for help, \"]?\" for Pkg help.
305-
$(jl)| | | | | | |/ _` |$(tx) |
306-
$(jl)| | |_| | | | (_| |$(tx) | Version $(VERSION)$(commit_date)
307-
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) | $(commit_string)
308-
$(jl)|__/$(tx) |
309-
310-
""")
301+
if short
302+
print(io,"""
303+
$(d3)o$(tx) | Version $(VERSION)$(commit_date)
304+
$(d2)o$(tx) $(d4)o$(tx) | $(commit_string)
305+
""")
306+
else
307+
print(io,""" $(d3)_$(tx)
308+
$(d1)_$(tx) $(jl)_$(tx) $(d2)_$(d3)(_)$(d4)_$(tx) | Documentation: https://docs.julialang.org
309+
$(d1)(_)$(jl) | $(d2)(_)$(tx) $(d4)(_)$(tx) |
310+
$(jl)_ _ _| |_ __ _$(tx) | Type \"?\" for help, \"]?\" for Pkg help.
311+
$(jl)| | | | | | |/ _` |$(tx) |
312+
$(jl)| | |_| | | | (_| |$(tx) | Version $(VERSION)$(commit_date)
313+
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) | $(commit_string)
314+
$(jl)|__/$(tx) |
315+
316+
""")
317+
end
311318
else
312-
print(io,"""
313-
_
314-
_ _ _(_)_ | Documentation: https://docs.julialang.org
315-
(_) | (_) (_) |
316-
_ _ _| |_ __ _ | Type \"?\" for help, \"]?\" for Pkg help.
317-
| | | | | | |/ _` | |
318-
| | |_| | | | (_| | | Version $(VERSION)$(commit_date)
319-
_/ |\\__'_|_|_|\\__'_| | $(commit_string)
320-
|__/ |
321-
322-
""")
319+
if short
320+
print(io,"""
321+
o | Version $(VERSION)$(commit_date)
322+
o o | $(commit_string)
323+
""")
324+
else
325+
print(io,"""
326+
_
327+
_ _ _(_)_ | Documentation: https://docs.julialang.org
328+
(_) | (_) (_) |
329+
_ _ _| |_ __ _ | Type \"?\" for help, \"]?\" for Pkg help.
330+
| | | | | | |/ _` | |
331+
| | |_| | | | (_| | | Version $(VERSION)$(commit_date)
332+
_/ |\\__'_|_|_|\\__'_| | $(commit_string)
333+
|__/ |
334+
335+
""")
336+
end
323337
end
324338
end

src/jloptions.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ static const char opts[] =
140140
// interactive options
141141
" -i, --interactive Interactive mode; REPL runs and `isinteractive()` is true\n"
142142
" -q, --quiet Quiet startup: no banner, suppress REPL warnings\n"
143-
" --banner={yes|no|auto*} Enable or disable startup banner\n"
143+
" --banner={yes|no|short|auto*}\n"
144+
" Enable or disable startup banner\n"
144145
" --color={yes|no|auto*} Enable or disable color text\n"
145146
" --history-file={yes*|no} Load or save history\n\n"
146147

@@ -444,8 +445,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
444445
jl_options.banner = 0;
445446
else if (!strcmp(optarg, "auto"))
446447
jl_options.banner = -1;
448+
else if (!strcmp(optarg, "short"))
449+
jl_options.banner = 2;
447450
else
448-
jl_errorf("julia: invalid argument to --banner={yes|no|auto} (%s)", optarg);
451+
jl_errorf("julia: invalid argument to --banner={yes|no|auto|short} (%s)", optarg);
449452
break;
450453
case opt_sysimage_native_code:
451454
if (!strcmp(optarg,"yes"))

test/cmdlineargs.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,19 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
226226
end
227227

228228
# --quiet, --banner
229-
let t(q,b) = "Base.JLOptions().quiet == $q && Base.JLOptions().banner == $b"
230-
@test success(`$exename -e $(t(0, -1))`)
231-
@test success(`$exename -q -e $(t(1, 0))`)
232-
@test success(`$exename --quiet -e $(t(1, 0))`)
233-
@test success(`$exename --banner=no -e $(t(0, 0))`)
234-
@test success(`$exename --banner=yes -e $(t(0, 1))`)
235-
@test success(`$exename -q --banner=no -e $(t(1, 0))`)
236-
@test success(`$exename -q --banner=yes -e $(t(1, 1))`)
237-
@test success(`$exename --banner=no -q -e $(t(1, 0))`)
238-
@test success(`$exename --banner=yes -q -e $(t(1, 1))`)
229+
let p = "print((Base.JLOptions().quiet, Base.JLOptions().banner))"
230+
@test read(`$exename -e $p`, String) == "(0, -1)"
231+
@test read(`$exename -q -e $p`, String) == "(1, 0)"
232+
@test read(`$exename --quiet -e $p`, String) == "(1, 0)"
233+
@test read(`$exename --banner=no -e $p`, String) == "(0, 0)"
234+
@test read(`$exename --banner=yes -e $p`, String) == "(0, 1)"
235+
@test read(`$exename --banner=short -e $p`, String) == "(0, 2)"
236+
@test read(`$exename -q --banner=no -e $p`, String) == "(1, 0)"
237+
@test read(`$exename -q --banner=yes -e $p`, String) == "(1, 1)"
238+
@test read(`$exename -q --banner=short -e $p`, String) == "(1, 2)"
239+
@test read(`$exename --banner=no -q -e $p`, String) == "(1, 0)"
240+
@test read(`$exename --banner=yes -q -e $p`, String) == "(1, 1)"
241+
@test read(`$exename --banner=short -q -e $p`, String) == "(1, 2)"
239242
end
240243

241244
# --home

test/version.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ end
223223
import Base.banner
224224
io = IOBuffer()
225225
@test banner(io) === nothing
226-
@test length(String(take!(io))) > 50
226+
seek(io, 0)
227+
@test countlines(io) == 9
228+
take!(io)
229+
@test banner(io; short=true) === nothing
230+
seek(io, 0)
231+
@test countlines(io) == 2
227232

228233
# julia_version.h version test
229234
@test VERSION.major == ccall(:jl_ver_major, Cint, ())

0 commit comments

Comments
 (0)