Skip to content

Commit 1f1607d

Browse files
committed
[example] use styled strings with the julia banner
1 parent adc8422 commit 1f1607d

File tree

2 files changed

+35
-56
lines changed

2 files changed

+35
-56
lines changed

base/client.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,41 @@ property = "value"
409409
"""
410410
loadfaces!(facetoml::IO) = loadfaces!(TOML.parse(TOML.Parser(facetoml)))
411411

412+
function banner(io::IO = stdout)
413+
if GIT_VERSION_INFO.tagged_commit
414+
commit_string = StyledStrings(TAGGED_RELEASE_BANNER, :face => :shadow)
415+
elseif isempty(GIT_VERSION_INFO.commit)
416+
commit_string = ""
417+
else
418+
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
419+
days = max(0, days)
420+
unit = days == 1 ? "day" : "days"
421+
distance = GIT_VERSION_INFO.fork_master_distance
422+
commit = GIT_VERSION_INFO.commit_short
423+
424+
if distance == 0
425+
commit_string = S"Commit {(foreground=grey):$commit} ({italic,warning:$days $unit} old master)"
426+
else
427+
branch = GIT_VERSION_INFO.branch
428+
commit_string = S"{emphasis:$branch}/{(foreground=grey):$commit} (fork {italic:{warning:$distance commits}, {warning:$days $unit}})"
429+
end
430+
end
431+
432+
commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"
433+
sep = StyledChar('', :face => Face(foreground=:grey))
434+
435+
print(io, S"""
436+
{bold,(foreground=green):_}
437+
{bold,(foreground=blue):_} _ {bold:{(foreground=red):_}{(foreground=green):(_)}{(foreground=magenta):_}} $sep {bold:Documentation:} {(underline=bright_blue),link={https://docs.julialang.org}:https://docs.julialang.org}
438+
{bold,(foreground=blue):(_)} | {bold:{(foreground=red):(_)} {(foreground=magenta):(_)}} $sep
439+
_ _ _| |_ __ _ $sep Type {region,julia_help_prompt:?} for help, {region,julia_pkg_prompt:]?} for {(underline=bright_blue),link={https://pkgdocs.julialang.org/}:Pkg} help.
440+
| | | | | | |/ _` | $sep
441+
| | |_| | | | (_| | $sep Version {bold:$VERSION}$commit_date
442+
_/ |\\__'_|_|_|\\__'_| $sep $commit_string
443+
|__/ $sep
444+
\n""")
445+
end
446+
412447
global active_repl
413448

414449
# run the requested sort of evaluation loop on stdio

base/version.jl

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -266,59 +266,3 @@ else
266266
end
267267

268268
libllvm_path() = ccall(:jl_get_libllvm, Any, ())
269-
270-
function banner(io::IO = stdout)
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-
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-
""")
311-
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-
""")
323-
end
324-
end

0 commit comments

Comments
 (0)