Skip to content

Commit adedd1d

Browse files
committed
Move the banner function from versions.jl to REPL
1 parent f71228d commit adedd1d

File tree

7 files changed

+87
-86
lines changed

7 files changed

+87
-86
lines changed

base/client.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_f
424424
invokelatest(REPL_MODULE_REF[]) do REPL
425425
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
426426
term = REPL.Terminals.TTYTerminal(term_env, stdin, stdout, stderr)
427-
banner == :no || Base.banner(term, short=banner==:short)
427+
banner == :no || REPL.banner(term, short=banner==:short)
428428
if term.term_type == "dumb"
429429
repl = REPL.BasicREPL(term)
430430
quiet || @warn "Terminal not fully functional"
@@ -444,7 +444,6 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_f
444444
if !fallback_repl && interactive && !quiet
445445
@warn "REPL provider not available: using basic fallback" LOAD_PATH=join(Base.LOAD_PATH, Sys.iswindows() ? ';' : ':')
446446
end
447-
banner == :no || Base.banner(short=banner==:short)
448447
let input = stdin
449448
if isa(input, File) || isa(input, IOStream)
450449
# for files, we can slurp in the whole thing at once

base/version.jl

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -267,72 +267,3 @@ end
267267

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

270-
function banner(io::IO = stdout; short = false)
271-
if GIT_VERSION_INFO.tagged_commit
272-
commit_string = TAGGED_RELEASE_BANNER
273-
elseif isempty(GIT_VERSION_INFO.commit)
274-
commit_string = ""
275-
else
276-
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
277-
days = max(0, days)
278-
unit = days == 1 ? "day" : "days"
279-
distance = GIT_VERSION_INFO.fork_master_distance
280-
commit = GIT_VERSION_INFO.commit_short
281-
282-
if distance == 0
283-
commit_string = "Commit $(commit) ($(days) $(unit) old master)"
284-
else
285-
branch = GIT_VERSION_INFO.branch
286-
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
287-
end
288-
end
289-
290-
commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"
291-
292-
if get(io, :color, false)::Bool
293-
c = text_colors
294-
tx = c[:normal] # text
295-
jl = c[:normal] # julia
296-
d1 = c[:bold] * c[:blue] # first dot
297-
d2 = c[:bold] * c[:red] # second dot
298-
d3 = c[:bold] * c[:green] # third dot
299-
d4 = c[:bold] * c[:magenta] # fourth dot
300-
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
318-
else
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
337-
end
338-
end

doc/src/manual/getting-started.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ known as a read-eval-print loop or "REPL") by double-clicking the Julia executab
1010
`julia` from the command line:
1111

1212
```@eval
13+
using REPL
1314
io = IOBuffer()
14-
Base.banner(io)
15+
REPL.banner(io)
1516
banner = String(take!(io))
1617
import Markdown
1718
Markdown.parse("```\n\$ julia\n\n$(banner)\njulia> 1 + 2\n3\n\njulia> ans\n3\n```")

stdlib/REPL/docs/src/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ shell modes. The REPL can be started by simply calling `julia` with no arguments
77
on the executable:
88

99
```@eval
10+
using REPL
1011
io = IOBuffer()
11-
Base.banner(io)
12+
REPL.banner(io)
1213
banner = String(take!(io))
1314
import Markdown
1415
Markdown.parse("```\n\$ julia\n\n$(banner)\njulia>\n```")

stdlib/REPL/src/REPL.jl

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,10 +1422,80 @@ ends_with_semicolon(code::AbstractString) = ends_with_semicolon(String(code))
14221422
ends_with_semicolon(code::Union{String,SubString{String}}) =
14231423
contains(_rm_strings_and_comments(code), r";\s*$")
14241424

1425+
function banner(io::IO = stdout; short = false)
1426+
if Base.GIT_VERSION_INFO.tagged_commit
1427+
commit_string = Base.TAGGED_RELEASE_BANNER
1428+
elseif isempty(Base.GIT_VERSION_INFO.commit)
1429+
commit_string = ""
1430+
else
1431+
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - Base.GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
1432+
days = max(0, days)
1433+
unit = days == 1 ? "day" : "days"
1434+
distance = Base.GIT_VERSION_INFO.fork_master_distance
1435+
commit = Base.GIT_VERSION_INFO.commit_short
1436+
1437+
if distance == 0
1438+
commit_string = "Commit $(commit) ($(days) $(unit) old master)"
1439+
else
1440+
branch = Base.GIT_VERSION_INFO.branch
1441+
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
1442+
end
1443+
end
1444+
1445+
commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"
1446+
1447+
if get(io, :color, false)::Bool
1448+
c = Base.text_colors
1449+
tx = c[:normal] # text
1450+
jl = c[:normal] # julia
1451+
d1 = c[:bold] * c[:blue] # first dot
1452+
d2 = c[:bold] * c[:red] # second dot
1453+
d3 = c[:bold] * c[:green] # third dot
1454+
d4 = c[:bold] * c[:magenta] # fourth dot
1455+
1456+
if short
1457+
print(io,"""
1458+
$(d3)o$(tx) | Version $(VERSION)$(commit_date)
1459+
$(d2)o$(tx) $(d4)o$(tx) | $(commit_string)
1460+
""")
1461+
else
1462+
print(io,""" $(d3)_$(tx)
1463+
$(d1)_$(tx) $(jl)_$(tx) $(d2)_$(d3)(_)$(d4)_$(tx) | Documentation: https://docs.julialang.org
1464+
$(d1)(_)$(jl) | $(d2)(_)$(tx) $(d4)(_)$(tx) |
1465+
$(jl)_ _ _| |_ __ _$(tx) | Type \"?\" for help, \"]?\" for Pkg help.
1466+
$(jl)| | | | | | |/ _` |$(tx) |
1467+
$(jl)| | |_| | | | (_| |$(tx) | Version $(VERSION)$(commit_date)
1468+
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) | $(commit_string)
1469+
$(jl)|__/$(tx) |
1470+
1471+
""")
1472+
end
1473+
else
1474+
if short
1475+
print(io,"""
1476+
o | Version $(VERSION)$(commit_date)
1477+
o o | $(commit_string)
1478+
""")
1479+
else
1480+
print(io,"""
1481+
_
1482+
_ _ _(_)_ | Documentation: https://docs.julialang.org
1483+
(_) | (_) (_) |
1484+
_ _ _| |_ __ _ | Type \"?\" for help, \"]?\" for Pkg help.
1485+
| | | | | | |/ _` | |
1486+
| | |_| | | | (_| | | Version $(VERSION)$(commit_date)
1487+
_/ |\\__'_|_|_|\\__'_| | $(commit_string)
1488+
|__/ |
1489+
1490+
""")
1491+
end
1492+
end
1493+
end
1494+
14251495
function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
14261496
repl.frontend_task = current_task()
14271497
have_color = hascolor(repl)
1428-
Base.banner(repl.stream)
1498+
banner(repl.stream)
14291499
d = REPLDisplay(repl)
14301500
dopushdisplay = !in(d,Base.Multimedia.displays)
14311501
dopushdisplay && pushdisplay(d)

stdlib/REPL/test/repl.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ include(joinpath(BASE_TEST_PATH, "testenv.jl"))
1818
include("FakeTerminals.jl")
1919
import .FakeTerminals.FakeTerminal
2020

21-
2221
function kill_timer(delay)
2322
# Give ourselves a generous timer here, just to prevent
2423
# this causing e.g. a CI hang when there's something unexpected in the output.
@@ -1726,3 +1725,14 @@ fake_repl(options=REPL.Options(confirm_exit=false,hascolor=true,hint_tab_complet
17261725
Base.wait(repltask)
17271726
@test !occursin("vailable", String(readavailable(stdout_read)))
17281727
end
1728+
1729+
# banner
1730+
let io = IOBuffer()
1731+
@test REPL.banner(io) === nothing
1732+
seek(io, 0)
1733+
@test countlines(io) == 9
1734+
take!(io)
1735+
@test REPL.banner(io; short=true) === nothing
1736+
seek(io, 0)
1737+
@test countlines(io) == 2
1738+
end

test/version.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,6 @@ for major=0:3, minor=0:3, patch=0:3
219219
end
220220
end
221221

222-
# banner
223-
import Base.banner
224-
io = IOBuffer()
225-
@test banner(io) === nothing
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
232-
233222
# julia_version.h version test
234223
@test VERSION.major == ccall(:jl_ver_major, Cint, ())
235224
@test VERSION.minor == ccall(:jl_ver_minor, Cint, ())

0 commit comments

Comments
 (0)