Skip to content

Commit d3cd670

Browse files
authored
Merge pull request #68 from disberd/prettytables_v3
update code to also support PrettyTables v3
2 parents 8534deb + 41de439 commit d3cd670

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ EzXML = "1"
2525
LibGit2 = "1.10"
2626
OrderedCollections = "1"
2727
Pkg = "1.10"
28-
PrettyTables = "0.12, 1.0, 2"
28+
PrettyTables = "0.12, 1.0, 2, 3.0.11"
2929
julia = "1.10"

src/LocalCoverage.jl

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module LocalCoverage
33
import CoverageTools
44
using Coverage: process_folder, process_file
55
using DocStringExtensions: SIGNATURES, FIELDS
6-
using PrettyTables: pretty_table, Highlighter
6+
using PrettyTables: PrettyTables, pretty_table
77
import DefaultApplication
88
import LibGit2
99
import Pkg
@@ -119,6 +119,13 @@ function Base.show(io::IO, summary::PackageCoverage)
119119
else
120120
rows = map(row -> Base.structdiff(row, NamedTuple{(:gaps,)}), rows)
121121
end
122+
# PrettyTables 3.0 changed Highlighter to TextHighlighter, so we have to select the correct constructor based on the PrettyTables version
123+
Highlighter = @static if pkgversion(PrettyTables) < v"3.0.0"
124+
PrettyTables.Highlighter
125+
else
126+
PrettyTables.TextHighlighter
127+
end
128+
122129
highlighters = (
123130
Highlighter(
124131
(data, i, j) -> j == percentage_column && row_coverage[i] <= 50,
@@ -131,19 +138,40 @@ function Base.show(io::IO, summary::PackageCoverage)
131138
foreground = :green),
132139
)
133140

134-
pretty_table(
135-
io,
136-
rows;
137-
title = "Coverage of $(package_dir)",
138-
header,
139-
alignment,
140-
crop = :none,
141-
linebreaks = true,
142-
columns_width,
143-
autowrap = true,
144-
highlighters,
145-
body_hlines = [length(rows) - 1],
146-
)
141+
# Kwargs of `pretty_table` itself also changed in PrettyTables 3.0, so we have to branch here as well
142+
@static if pkgversion(PrettyTables) < v"3.0.0"
143+
pretty_table(
144+
io,
145+
rows;
146+
title = "Coverage of $(package_dir)",
147+
header,
148+
alignment,
149+
crop = :none,
150+
linebreaks = true,
151+
columns_width,
152+
autowrap = true,
153+
highlighters,
154+
body_hlines = [length(rows) - 1],
155+
)
156+
else
157+
pretty_table(
158+
io,
159+
rows;
160+
title = "Coverage of $(package_dir)",
161+
column_labels = [header],
162+
alignment,
163+
# The crop kwarg is not present anymore, split into the next two ones
164+
fit_table_in_display_horizontally = false,
165+
fit_table_in_display_vertically = false,
166+
line_breaks = true,
167+
fixed_data_column_widths = columns_width,
168+
auto_wrap = true,
169+
highlighters = collect(highlighters), # v3 expects a vector instead of a Tuple
170+
table_format = PrettyTables.TextTableFormat(;
171+
horizontal_lines_at_data_rows = [length(rows) - 1],
172+
),
173+
)
174+
end
147175
end
148176

149177
"""

0 commit comments

Comments
 (0)