Skip to content

Commit 21f5217

Browse files
Align all status printing (#2309) (#2342)
* align all status printing * fix tests affected by indenting * remove unnecessary kwarg uses (cherry picked from commit 8a33fb1)
1 parent 537a703 commit 21f5217

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/Operations.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ function is_package_downloaded(ctx, pkg::PackageSpec)
17701770
end
17711771

17721772
function print_status(ctx::Context, old_ctx::Union{Nothing,Context}, header::Symbol,
1773-
uuids::Vector, names::Vector; manifest=true, diff=false)
1773+
uuids::Vector, names::Vector; manifest=true, diff=false, ignore_indent=false)
17741774
not_installed_indicator = sprint((io, args) -> printstyled(io, args...; color=:red), "", context=ctx.io)
17751775
ctx.io = something(ctx.status_io, ctx.io) # for instrumenting tests
17761776
filter = !isempty(uuids) || !isempty(names)
@@ -1779,22 +1779,22 @@ function print_status(ctx::Context, old_ctx::Union{Nothing,Context}, header::Sym
17791779
# filter and return early if possible
17801780
if isempty(xs) && !diff
17811781
printpkgstyle(ctx, header, "$(pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file)) (empty " *
1782-
(manifest ? "manifest" : "project") * ")", true)
1782+
(manifest ? "manifest" : "project") * ")", ignore_indent)
17831783
return nothing
17841784
end
17851785
xs = !diff ? xs : eltype(xs)[(id, old, new) for (id, old, new) in xs if old != new]
17861786
if isempty(xs)
1787-
printpkgstyle(ctx, Symbol("No Changes"), "to $(pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file))", true)
1787+
printpkgstyle(ctx, Symbol("No Changes"), "to $(pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file))", ignore_indent)
17881788
return nothing
17891789
end
17901790
xs = !filter ? xs : eltype(xs)[(id, old, new) for (id, old, new) in xs if (id in uuids || something(new, old).name in names)]
17911791
if isempty(xs)
17921792
printpkgstyle(ctx, Symbol("No Matches"),
1793-
"in $(diff ? "diff for " : "")$(pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file))", true)
1793+
"in $(diff ? "diff for " : "")$(pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file))", ignore_indent)
17941794
return nothing
17951795
end
17961796
# main print
1797-
printpkgstyle(ctx, header, pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file), true)
1797+
printpkgstyle(ctx, header, pathrepr(manifest ? ctx.env.manifest_file : ctx.env.project_file), ignore_indent)
17981798
# Sort stdlibs and _jlls towards the end in status output
17991799
xs = sort!(xs, by = (x -> (is_stdlib(x[1]), endswith(something(x[3], x[2]).name, "_jll"), something(x[3], x[2]).name, x[1])))
18001800
all_packages_downloaded = true
@@ -1810,7 +1810,7 @@ function print_status(ctx::Context, old_ctx::Union{Nothing,Context}, header::Sym
18101810
println(ctx.io)
18111811
end
18121812
if !all_packages_downloaded
1813-
printpkgstyle(ctx, :Info, "packages marked with $not_installed_indicator not downloaded, use `instantiate` to download", true)
1813+
printpkgstyle(ctx, :Info, "packages marked with $not_installed_indicator not downloaded, use `instantiate` to download", ignore_indent)
18141814
end
18151815
return nothing
18161816
end
@@ -1832,21 +1832,20 @@ function git_head_context(ctx, project_dir)
18321832
end
18331833
end
18341834

1835-
function show_update(ctx::Context)
1835+
function show_update(ctx::Context; ignore_indent=false)
18361836
old_env = EnvCache()
18371837
old_env.project = ctx.env.original_project
18381838
old_env.manifest = ctx.env.original_manifest
1839-
status(ctx; header=:Updating, mode=PKGMODE_COMBINED, env_diff=old_env)
1839+
status(ctx; header=:Updating, mode=PKGMODE_COMBINED, env_diff=old_env, ignore_indent=ignore_indent)
18401840
return nothing
18411841
end
18421842

18431843
function status(ctx::Context, pkgs::Vector{PackageSpec}=PackageSpec[];
1844-
header=nothing, mode::PackageMode=PKGMODE_PROJECT, git_diff::Bool=false, env_diff=nothing)
1844+
header=nothing, mode::PackageMode=PKGMODE_PROJECT, git_diff::Bool=false, env_diff=nothing, ignore_indent=false)
18451845
ctx.io == Base.devnull && return
18461846
# if a package, print header
18471847
if header === nothing && ctx.env.pkg !== nothing
1848-
printstyled(ctx.io, "Project "; color=Base.info_color(), bold=true)
1849-
println(ctx.io, ctx.env.pkg.name, " v", ctx.env.pkg.version)
1848+
printpkgstyle(ctx.io, :Project, string(ctx.env.pkg.name, " v", ctx.env.pkg.version); color=Base.info_color())
18501849
end
18511850
# load old ctx
18521851
old_ctx = nothing
@@ -1869,10 +1868,10 @@ function status(ctx::Context, pkgs::Vector{PackageSpec}=PackageSpec[];
18691868
diff = old_ctx !== nothing
18701869
header = something(header, diff ? :Diff : :Status)
18711870
if mode == PKGMODE_PROJECT || mode == PKGMODE_COMBINED
1872-
print_status(ctx, old_ctx, header, filter_uuids, filter_names; manifest=false, diff=diff)
1871+
print_status(ctx, old_ctx, header, filter_uuids, filter_names; manifest=false, diff=diff, ignore_indent=ignore_indent)
18731872
end
18741873
if mode == PKGMODE_MANIFEST || mode == PKGMODE_COMBINED
1875-
print_status(ctx, old_ctx, header, filter_uuids, filter_names; diff=diff)
1874+
print_status(ctx, old_ctx, header, filter_uuids, filter_names; diff=diff, ignore_indent=ignore_indent)
18761875
end
18771876
end
18781877

src/Types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,10 +1370,10 @@ end
13701370
function printpkgstyle(ctx::Context, cmd::Symbol, text::String, ignore_indent::Bool=false)
13711371
printpkgstyle(ctx.io, cmd, text, ignore_indent)
13721372
end
1373-
function printpkgstyle(io::IO, cmd::Symbol, text::String, ignore_indent::Bool=false)
1373+
function printpkgstyle(io::IO, cmd::Symbol, text::String, ignore_indent::Bool=false; color=:green)
13741374
indent = textwidth(string(:Precompiling)) # "Precompiling" is the longest operation
13751375
ignore_indent && (indent = 0)
1376-
printstyled(io, lpad(string(cmd), indent), color=:green, bold=true)
1376+
printstyled(io, lpad(string(cmd), indent), color=color, bold=true)
13771377
println(io, " ", text)
13781378
end
13791379

test/new.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,13 +1936,13 @@ end
19361936
@test occursin(r"Status `.+Project.toml`", readline(io))
19371937
@test occursin(r"\[7876af07\] Example v\d\.\d\.\d", readline(io))
19381938
@test occursin(r"\[d6f4376e\] Markdown", readline(io))
1939-
@test "Info packages marked with → not downloaded, use `instantiate` to download" == readline(io)
1939+
@test "Info packages marked with → not downloaded, use `instantiate` to download" == strip(readline(io))
19401940
Pkg.status(;io=io, mode=Pkg.PKGMODE_MANIFEST)
19411941
@test occursin(r"Status `.+Manifest.toml`", readline(io))
19421942
@test occursin(r"\[7876af07\] Example v\d\.\d\.\d", readline(io))
19431943
@test occursin(r"\[2a0f44e3\] Base64", readline(io))
19441944
@test occursin(r"\[d6f4376e\] Markdown", readline(io))
1945-
@test "Info packages marked with → not downloaded, use `instantiate` to download" == readline(io)
1945+
@test "Info packages marked with → not downloaded, use `instantiate` to download" == strip(readline(io))
19461946
end
19471947
# Manifest Status API
19481948
isolate(loaded_depot=true) do

0 commit comments

Comments
 (0)