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 18, 2023
1 parent 65b393f commit 31b7a12
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 56 deletions.
41 changes: 41 additions & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,47 @@ 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 {grey:$commit} \
({warning:⌛ {italic:$days $unit}} old master)"""
else
branch = GIT_VERSION_INFO.branch
commit_string =
S"""{emphasis:$branch}/{grey:$commit} \
({italic:{success:{bold,(italic=false):↑} $distance commits}, \
{warning:{(italic=false):⌛} $days $unit}})"""
end
end

commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : S" {(weight=light):($(split(Base.GIT_VERSION_INFO.date_string)[1]))}"
doclink = S"{bold:Documentation:} {(underline=grey),link={https://docs.julialang.org}:https://docs.julialang.org}"
help = S"Type {region,julia_help_prompt:?} for help, {region,julia_pkg_prompt:]?} for {(underline=grey),link={https://pkgdocs.julialang.org/}:Pkg} help."

print(io, S"""
{bold,green:_}
{bold,blue:_} _ {bold:{red:_}{green:(_)}{magenta:_}} {shadow:│} $doclink
{bold,blue:(_)} | {bold:{red:(_)} {magenta:(_)}} {shadow:│}
_ _ _| |_ __ _ {shadow:│} $help
| | | | | | |/ _` | {shadow:│}
| | |_| | | | (_| | {shadow:│} Version {bold:$VERSION}$commit_date
_/ |\\__'_|_|_|\\__'_| {shadow:│} $commit_string
|__/ {shadow:│}
\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 31b7a12

Please sign in to comment.