From 31b7a1247261f4872125e5169ce8f65702abf63f Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 2 May 2023 00:51:28 +0800 Subject: [PATCH] [example] Use styled strings with the julia banner --- base/client.jl | 41 ++++++++++++++++++++++++++++++++++++ base/version.jl | 56 ------------------------------------------------- 2 files changed, 41 insertions(+), 56 deletions(-) diff --git a/base/client.jl b/base/client.jl index 8029990ecdb4ca..1183734c359349 100644 --- a/base/client.jl +++ b/base/client.jl @@ -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 diff --git a/base/version.jl b/base/version.jl index 67377c86a84933..65be08e34dc8cc 100644 --- a/base/version.jl +++ b/base/version.jl @@ -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