Skip to content

Commit

Permalink
[example] use styled strings with the julia banner
Browse files Browse the repository at this point in the history
  • Loading branch information
tecosaur committed May 16, 2023
1 parent adc8422 commit 1f1607d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 56 deletions.
35 changes: 35 additions & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,41 @@ property = "value"
"""
loadfaces!(facetoml::IO) = loadfaces!(TOML.parse(TOML.Parser(facetoml)))

function banner(io::IO = stdout)
if GIT_VERSION_INFO.tagged_commit
commit_string = StyledStrings(TAGGED_RELEASE_BANNER, :face => :shadow)
elseif isempty(GIT_VERSION_INFO.commit)
commit_string = ""
else
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
days = max(0, days)
unit = days == 1 ? "day" : "days"
distance = GIT_VERSION_INFO.fork_master_distance
commit = GIT_VERSION_INFO.commit_short

if distance == 0
commit_string = S"Commit {(foreground=grey):$commit} ({italic,warning:$days $unit} old master)"
else
branch = GIT_VERSION_INFO.branch
commit_string = S"{emphasis:$branch}/{(foreground=grey):$commit} (fork {italic:{warning:$distance commits}, {warning:$days $unit}})"
end
end

commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"
sep = StyledChar('', :face => Face(foreground=:grey))

print(io, S"""
{bold,(foreground=green):_}
{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}
{bold,(foreground=blue):(_)} | {bold:{(foreground=red):(_)} {(foreground=magenta):(_)}} $sep
_ _ _| |_ __ _ $sep Type {region,julia_help_prompt:?} for help, {region,julia_pkg_prompt:]?} for {(underline=bright_blue),link={https://pkgdocs.julialang.org/}:Pkg} help.
| | | | | | |/ _` | $sep
| | |_| | | | (_| | $sep Version {bold:$VERSION}$commit_date
_/ |\\__'_|_|_|\\__'_| $sep $commit_string
|__/ $sep
\n""")
end

global active_repl

# run the requested sort of evaluation loop on stdio
Expand Down
56 changes: 0 additions & 56 deletions base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,59 +266,3 @@ else
end

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

function banner(io::IO = stdout)
if GIT_VERSION_INFO.tagged_commit
commit_string = TAGGED_RELEASE_BANNER
elseif isempty(GIT_VERSION_INFO.commit)
commit_string = ""
else
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
days = max(0, days)
unit = days == 1 ? "day" : "days"
distance = GIT_VERSION_INFO.fork_master_distance
commit = GIT_VERSION_INFO.commit_short

if distance == 0
commit_string = "Commit $(commit) ($(days) $(unit) old master)"
else
branch = GIT_VERSION_INFO.branch
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
end
end

commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"

if get(io, :color, false)::Bool
c = text_colors
tx = c[:normal] # text
jl = c[:normal] # julia
d1 = c[:bold] * c[:blue] # first dot
d2 = c[:bold] * c[:red] # second dot
d3 = c[:bold] * c[:green] # third dot
d4 = c[:bold] * c[:magenta] # fourth dot

print(io,""" $(d3)_$(tx)
$(d1)_$(tx) $(jl)_$(tx) $(d2)_$(d3)(_)$(d4)_$(tx) | Documentation: https://docs.julialang.org
$(d1)(_)$(jl) | $(d2)(_)$(tx) $(d4)(_)$(tx) |
$(jl)_ _ _| |_ __ _$(tx) | Type \"?\" for help, \"]?\" for Pkg help.
$(jl)| | | | | | |/ _` |$(tx) |
$(jl)| | |_| | | | (_| |$(tx) | Version $(VERSION)$(commit_date)
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) | $(commit_string)
$(jl)|__/$(tx) |
""")
else
print(io,"""
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type \"?\" for help, \"]?\" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version $(VERSION)$(commit_date)
_/ |\\__'_|_|_|\\__'_| | $(commit_string)
|__/ |
""")
end
end

0 comments on commit 1f1607d

Please sign in to comment.