Skip to content

Commit 1f62965

Browse files
committed
Make the REPL banner resize to avoid wrapping
We also spritz it up a bit using the new StyledStrings library, namely: - colouring the Help and Pkg key prompts - making the docs link a terminal link, and Pkg a link to the Pkg docs - using box drawing characters for the dividing line - making branch status more colourful - making the official version text more subdued With these change the four banners (from smallest to largest) are: 1. A one-liner, for extreme circumstances (new) 2. The short banner 3. The large banner, with the description stacked vertically (new) 4. The large banner, with the description stacked horizontally
1 parent 9f7cdfd commit 1f62965

File tree

5 files changed

+120
-81
lines changed

5 files changed

+120
-81
lines changed

base/client.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ end
467467
function run_std_repl(REPL::Module, quiet::Bool, banner::Symbol, history_file::Bool)
468468
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
469469
term = REPL.Terminals.TTYTerminal(term_env, stdin, stdout, stderr)
470-
banner == :no || REPL.banner(term, short=banner==:short)
470+
banner == :no || REPL.banner(term, banner)
471471
if term.term_type == "dumb"
472472
repl = REPL.BasicREPL(term)
473473
quiet || @warn "Terminal not fully functional"
@@ -585,12 +585,26 @@ end
585585
function repl_main(_)
586586
opts = Base.JLOptions()
587587
interactiveinput = isa(stdin, Base.TTY)
588-
b = opts.banner
589-
auto = b == -1
590-
banner = b == 0 || (auto && !interactiveinput) ? :no :
591-
b == 1 || (auto && interactiveinput) ? :yes :
592-
:short # b == 2
593-
588+
bval = if opts.banner == -1 # Auto
589+
Int(interactiveinput)
590+
else
591+
opts.banner
592+
end
593+
# All the options produced by `jloptions.c`'s `case opt_banner`.
594+
# 0=off, 1=largest, ..., N=smallest
595+
banner = if bval == 0
596+
:no
597+
elseif bval == 1
598+
:full
599+
elseif bval == 2
600+
:narrow
601+
elseif bval == 3
602+
:short
603+
elseif bval == 4
604+
:tiny
605+
else # For type stability of `banner`
606+
:unreachable
607+
end
594608
quiet = (opts.quiet != 0)
595609
history_file = (opts.historyfile != 0)
596610
return run_main_repl(interactiveinput, quiet, banner, history_file)

src/jloptions.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ static const char opts[] =
224224
" -i, --interactive Interactive mode; REPL runs and\n"
225225
" `isinteractive()` is true.\n"
226226
" -q, --quiet Quiet startup: no banner, suppress REPL warnings\n"
227-
" --banner={yes|no|short|auto*} Enable or disable startup banner\n"
227+
" --banner={yes|no|auto*|<size>} Enable or disable startup banner, or specify a\n"
228+
" preferred <size> (tiny, short, narrow, or full).\n"
228229
" --color={yes|no|auto*} Enable or disable color text\n"
229230
" --history-file={yes*|no} Load or save history\n\n"
230231

@@ -572,16 +573,22 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
572573
jl_options.banner = 0;
573574
break;
574575
case opt_banner: // banner
575-
if (!strcmp(optarg, "yes"))
576-
jl_options.banner = 1;
576+
if (!strcmp(optarg, "auto"))
577+
jl_options.banner = -1;
577578
else if (!strcmp(optarg, "no"))
578579
jl_options.banner = 0;
579-
else if (!strcmp(optarg, "auto"))
580-
jl_options.banner = -1;
581-
else if (!strcmp(optarg, "short"))
580+
else if (!strcmp(optarg, "yes"))
581+
jl_options.banner = 1;
582+
else if (!strcmp(optarg, "full"))
583+
jl_options.banner = 1; // Same as "yes".
584+
else if (!strcmp(optarg, "narrow"))
582585
jl_options.banner = 2;
586+
else if (!strcmp(optarg, "short"))
587+
jl_options.banner = 3;
588+
else if (!strcmp(optarg, "tiny"))
589+
jl_options.banner = 4;
583590
else
584-
jl_errorf("julia: invalid argument to --banner={yes|no|auto|short} (%s)", optarg);
591+
jl_errorf("julia: invalid argument to --banner={yes|no|auto|full|narrow|short|tiny} (%s)", optarg);
585592
break;
586593
case opt_experimental_features:
587594
jl_options.use_experimental_features = JL_OPTIONS_USE_EXPERIMENTAL_FEATURES_YES;

stdlib/REPL/src/REPL.jl

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,11 +1750,21 @@ ends_with_semicolon(code::AbstractString) = ends_with_semicolon(String(code))
17501750
ends_with_semicolon(code::Union{String,SubString{String}}) =
17511751
contains(_rm_strings_and_comments(code), r";\s*$")
17521752

1753-
function banner(io::IO = stdout; short = false)
1754-
if Base.GIT_VERSION_INFO.tagged_commit
1755-
commit_string = Base.TAGGED_RELEASE_BANNER
1753+
"""
1754+
banner(io::IO = stdout, preferred::Symbol = :full)
1755+
1756+
Print the "Julia" informative banner to `io`, using the `preferred` variant
1757+
if reasonable and known.
1758+
1759+
!!! warning
1760+
The particular banner selected by `preferred` is liable to being changed
1761+
without warning. The current variants are: `:tiny`, `:short`, `:narrow`, and `:full`.
1762+
"""
1763+
function banner(io::IO = stdout, preferred::Symbol = :full)
1764+
commit_string = if Base.GIT_VERSION_INFO.tagged_commit
1765+
Base.AnnotatedString(TAGGED_RELEASE_BANNER, :face => :shadow)
17561766
elseif isempty(Base.GIT_VERSION_INFO.commit)
1757-
commit_string = ""
1767+
styled""
17581768
else
17591769
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - Base.GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
17601770
days = max(0, days)
@@ -1763,60 +1773,65 @@ function banner(io::IO = stdout; short = false)
17631773
commit = Base.GIT_VERSION_INFO.commit_short
17641774

17651775
if distance == 0
1766-
commit_string = "Commit $(commit) ($(days) $(unit) old master)"
1776+
styled"""Commit {grey:$commit} \
1777+
({warning:⌛ {italic:$days $unit}} old master)"""
17671778
else
17681779
branch = Base.GIT_VERSION_INFO.branch
1769-
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
1780+
styled"""{emphasis:$branch}/{grey:$commit} \
1781+
({italic:{success:{bold,(slant=normal):↑} $distance commits}, \
1782+
{warning:{(slant=normal):⌛} $days $unit}})"""
17701783
end
17711784
end
17721785

1773-
commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"
1774-
1775-
if get(io, :color, false)::Bool
1776-
c = Base.text_colors
1777-
tx = c[:normal] # text
1778-
jl = c[:normal] # julia
1779-
d1 = c[:bold] * c[:blue] # first dot
1780-
d2 = c[:bold] * c[:red] # second dot
1781-
d3 = c[:bold] * c[:green] # third dot
1782-
d4 = c[:bold] * c[:magenta] # fourth dot
1783-
1784-
if short
1785-
print(io,"""
1786-
$(d3)o$(tx) | Version $(VERSION)$(commit_date)
1787-
$(d2)o$(tx) $(d4)o$(tx) | $(commit_string)
1788-
""")
1789-
else
1790-
print(io,""" $(d3)_$(tx)
1791-
$(d1)_$(tx) $(jl)_$(tx) $(d2)_$(d3)(_)$(d4)_$(tx) | Documentation: https://docs.julialang.org
1792-
$(d1)(_)$(jl) | $(d2)(_)$(tx) $(d4)(_)$(tx) |
1793-
$(jl)_ _ _| |_ __ _$(tx) | Type \"?\" for help, \"]?\" for Pkg help.
1794-
$(jl)| | | | | | |/ _` |$(tx) |
1795-
$(jl)| | |_| | | | (_| |$(tx) | Version $(VERSION)$(commit_date)
1796-
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) | $(commit_string)
1797-
$(jl)|__/$(tx) |
1798-
1799-
""")
1800-
end
1801-
else
1802-
if short
1803-
print(io,"""
1804-
o | Version $(VERSION)$(commit_date)
1805-
o o | $(commit_string)
1806-
""")
1807-
else
1808-
print(io,"""
1809-
_
1810-
_ _ _(_)_ | Documentation: https://docs.julialang.org
1811-
(_) | (_) (_) |
1812-
_ _ _| |_ __ _ | Type \"?\" for help, \"]?\" for Pkg help.
1813-
| | | | | | |/ _` | |
1814-
| | |_| | | | (_| | | Version $(VERSION)$(commit_date)
1815-
_/ |\\__'_|_|_|\\__'_| | $(commit_string)
1816-
|__/ |
1817-
1818-
""")
1819-
end
1786+
commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : styled" {light:($(split(Base.GIT_VERSION_INFO.date_string)[1]))}"
1787+
doclink = styled"{bold:Documentation:} {(underline=grey),link={https://docs.julialang.org}:https://docs.julialang.org}"
1788+
help = styled"Type {repl_prompt_help:?} for help, {repl_prompt_pkg:]?} for {(underline=grey),link={https://pkgdocs.julialang.org/}:Pkg} help."
1789+
1790+
sizenames = (:tiny, :short, :narrow, :full)
1791+
maxsize = something(findfirst(==(preferred), sizenames), length(sizenames))
1792+
size = min(if all(displaysize(io) .>= (8, 70)); 4 # Full size
1793+
elseif all(displaysize(io) .>= (8, 45)); 3 # Narrower
1794+
elseif all(displaysize(io) .>= (3, 50)); 2 # Tiny
1795+
else 1 end,
1796+
max(0, maxsize))
1797+
1798+
if size == 4 # Full size
1799+
print(io, styled"""
1800+
{bold,green:_}
1801+
{bold,blue:_} _ {bold:{red:_}{green:(_)}{magenta:_}} {shadow:│} $doclink
1802+
{bold,blue:(_)} | {bold:{red:(_)} {magenta:(_)}} {shadow:│}
1803+
_ _ _| |_ __ _ {shadow:│} $help
1804+
| | | | | | |/ _` | {shadow:│}
1805+
| | |_| | | | (_| | {shadow:│} Version {bold:$VERSION}$commit_date
1806+
_/ |\\__'_|_|_|\\__'_| {shadow:│} $commit_string
1807+
|__/ {shadow:│}
1808+
\n""")
1809+
elseif size == 3 # Rotated
1810+
print(io, styled"""
1811+
{bold,green:_}
1812+
{bold,blue:_} _ {bold:{red:_}{green:(_)}{magenta:_}}
1813+
{bold,blue:(_)} | {bold:{red:(_)} {magenta:(_)}}
1814+
_ _ _| |_ __ _
1815+
| | | | | | |/ _` |
1816+
| | |_| | | | (_| |
1817+
_/ |\\__'_|_|_|\\__'_|
1818+
|__/
1819+
1820+
$doclink
1821+
$help
1822+
1823+
Version {bold:$VERSION}$commit_date
1824+
$commit_string
1825+
\n""")
1826+
elseif size == 2 # Tiny
1827+
print(io, styled"""
1828+
{bold,green:o} {shadow:│} Version {bold:$VERSION}$commit_date
1829+
{bold:{red:o} {magenta:o}} {shadow:│} $commit_string
1830+
""", ifelse(displaysize(io) > (12, 0), "\n", ""))
1831+
elseif size == 1 && Base.GIT_VERSION_INFO.tagged_commit # Text only
1832+
print(io, styled"""{bold:{blue:∴} {magenta:Julia} $VERSION}$commit_date\n""")
1833+
elseif size == 1 # Text only
1834+
print(io, styled"""{bold:{blue:∴} {magenta:Julia} $VERSION}$commit_date $commit_string\n""")
18201835
end
18211836
end
18221837

stdlib/REPL/test/repl.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,9 +1953,9 @@ let io = IOBuffer()
19531953
seek(io, 0)
19541954
@test countlines(io) == 9
19551955
take!(io)
1956-
@test REPL.banner(io; short=true) === nothing
1956+
@test REPL.banner(io, :tiny) === nothing
19571957
seek(io, 0)
1958-
@test countlines(io) == 2
1958+
@test countlines(io) == 1
19591959
end
19601960

19611961
@testset "Docstrings" begin

test/cmdlineargs.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,21 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
263263

264264
# --quiet, --banner
265265
let p = "print((Base.JLOptions().quiet, Base.JLOptions().banner))"
266-
@test read(`$exename -e $p`, String) == "(0, -1)"
267-
@test read(`$exename -q -e $p`, String) == "(1, 0)"
268-
@test read(`$exename --quiet -e $p`, String) == "(1, 0)"
269-
@test read(`$exename --banner=no -e $p`, String) == "(0, 0)"
270-
@test read(`$exename --banner=yes -e $p`, String) == "(0, 1)"
271-
@test read(`$exename --banner=short -e $p`, String) == "(0, 2)"
272-
@test read(`$exename -q --banner=no -e $p`, String) == "(1, 0)"
273-
@test read(`$exename -q --banner=yes -e $p`, String) == "(1, 1)"
274-
@test read(`$exename -q --banner=short -e $p`, String) == "(1, 2)"
275-
@test read(`$exename --banner=no -q -e $p`, String) == "(1, 0)"
276-
@test read(`$exename --banner=yes -q -e $p`, String) == "(1, 1)"
277-
@test read(`$exename --banner=short -q -e $p`, String) == "(1, 2)"
266+
@test read(`$exename -e $p`, String) == "(0, -1)"
267+
@test read(`$exename -q -e $p`, String) == "(1, 0)"
268+
@test read(`$exename --quiet -e $p`, String) == "(1, 0)"
269+
@test read(`$exename --banner=auto -e $p`, String) == "(0, -1)"
270+
@test read(`$exename --banner=no -e $p`, String) == "(0, 0)"
271+
@test read(`$exename --banner=yes -e $p`, String) == "(0, 1)"
272+
@test read(`$exename --banner=full -e $p`, String) == "(0, 1)"
273+
@test read(`$exename -q --banner=no -e $p`, String) == "(1, 0)"
274+
@test read(`$exename -q --banner=yes -e $p`, String) == "(1, 1)"
275+
@test read(`$exename -q --banner=tiny -e $p`, String) == "(1, 4)"
276+
@test read(`$exename --banner=no -q -e $p`, String) == "(1, 0)"
277+
@test read(`$exename --banner=yes -q -e $p`, String) == "(1, 1)"
278+
@test read(`$exename --banner=narrow -q -e $p`, String) == "(1, 2)"
279+
@test read(`$exename --banner=short -q -e $p`, String) == "(1, 3)"
280+
@test read(`$exename --banner=tiny -q -e $p`, String) == "(1, 4)"
278281
end
279282

280283
# --home

0 commit comments

Comments
 (0)