Skip to content

Commit 6a735fd

Browse files
committed
support ImageInTerminal 0.5
1 parent 852eba7 commit 6a735fd

File tree

13 files changed

+132
-102
lines changed

13 files changed

+132
-102
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
4141
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
4242
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
4343
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
44+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
4445
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
4546
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
4647

4748
[targets]
48-
test = ["CSVFiles", "DataFrames", "ImageMagick", "ImageTransformations", "GR", "Plots", "TestImages", "ImageIO", "BSON"]
49+
test = ["BSON", "CSVFiles", "DataFrames", "GR", "ImageIO", "ImageMagick", "ImageTransformations", "Logging", "Plots", "TestImages"]

src/fileio.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ function _convert(
5656
size = (20,40), kw...)
5757

5858
# encode image into string
59-
strs = @withcolor ImageInTerminal.encodeimg(
60-
ImageInTerminal.SmallBlocks(),
61-
ImageInTerminal.TermColor256(),
59+
strs = @withcolor ImageInTerminal.ascii_show(
6260
img,
63-
size...)[1]
61+
ImageInTerminal.TermColor8bit(),
62+
:small,
63+
size
64+
)
6465
return join(strs,'\n')
6566
end
6667

src/render.jl

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,56 @@ struct BeforeAfterLimited <: BeforeAfter end
99
struct BeforeAfterFull <: BeforeAfter end
1010
struct BeforeAfterImage <: BeforeAfter end
1111

12-
render_item(::RenderMode, item) = println(item)
12+
color_buffer(args...) =
13+
IOContext(PipeBuffer(), :color=>Base.get_have_color(), args...)
14+
15+
function render_item(::RenderMode, item)
16+
io = color_buffer()
17+
print(io, item)
18+
read(io, String)
19+
end
1320
function render_item(::BeforeAfterLimited, item)
14-
show(IOContext(stdout, :limit=>true, :displaysize=>(20,80)), "text/plain", item)
15-
println()
21+
io = color_buffer(
22+
:limit=>true,
23+
:displaysize=>(20,80)
24+
)
25+
show(io, "text/plain", item)
26+
read(io, String)
1627
end
1728
function render_item(::BeforeAfterImage, item)
18-
str_item = @withcolor ImageInTerminal.encodeimg(ImageInTerminal.SmallBlocks(), ImageInTerminal.TermColor256(), item, 20, 40)[1]
19-
println("eltype: ", eltype(item))
20-
println("size: ", map(length, axes(item)))
21-
println("thumbnail:")
22-
println.(str_item)
29+
io = color_buffer()
30+
println(io, "eltype: ", eltype(item))
31+
println(io, "size: ", map(length, axes(item)))
32+
println(io, "thumbnail:")
33+
strs = @withcolor ImageInTerminal.ascii_show(
34+
item,
35+
ImageInTerminal.TermColor8bit(),
36+
:small,
37+
(20, 40)
38+
)
39+
print(io, join(strs, '\n'))
40+
read(io, String)
2341
end
2442

2543
## 2 arg form render for comparing
26-
function render(mode::BeforeAfter, reference, actual)
27-
println("- REFERENCE -------------------")
28-
render_item(mode, reference)
29-
println("-------------------------------")
30-
println("- ACTUAL ----------------------")
31-
render_item(mode, actual)
32-
println("-------------------------------")
33-
end
34-
function render(::Diff, reference, actual)
35-
println("- DIFF ------------------------")
36-
@withcolor println(deepdiff(reference, actual))
37-
println("-------------------------------")
38-
end
44+
render(mode::BeforeAfter, reference, actual) = """
45+
- REFERENCE -------------------
46+
$(render_item(mode, reference))
47+
-------------------------------
48+
- ACTUAL ----------------------
49+
$(render_item(mode, actual))
50+
-------------------------------"""
51+
52+
render(mode::Diff, reference, actual) = """
53+
- DIFF ------------------------
54+
$(@withcolor(render_item(mode, deepdiff(reference, actual))))
55+
-------------------------------"""
3956

4057
## 1 arg form render for new content
41-
function render(mode::RenderMode, actual)
42-
println("- NEW CONTENT -----------------")
43-
render_item(mode, actual)
44-
println("-------------------------------")
45-
end
58+
render(mode::RenderMode, actual) = """
59+
- NEW CONTENT -----------------
60+
$(render_item(mode, actual))
61+
-------------------------------"""
4662

4763
"""
4864
default_rendermode(::DataFormat, actual)

src/test_reference.jl

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,11 @@ function test_reference(
132132
if !isfile(reference_path) # when reference file doesn't exists
133133
mkpath(reference_dir)
134134
savefile(reference_file, actual)
135-
@info(
136-
"Reference file for \"$reference_filename\" did not exist. It has been created",
137-
new_reference=reference_path,
138-
)
135+
@info """Reference file for \"$reference_filename\" did not exist. It has been created:
136+
$(render(rendermode, actual))
137+
""" new_reference = reference_path
139138

140-
# TODO: move encoding out from render
141-
render(rendermode, actual)
142-
143-
@info("Please run the tests again for any changes to take effect")
139+
@info "Please run the tests again for any changes to take effect"
144140
return nothing # skip current test case
145141
end
146142

@@ -161,13 +157,10 @@ function test_reference(
161157
savefile(actual_file, actual)
162158

163159
# Report to user.
164-
@info(
165-
"Reference Test for \"$reference_filename\" failed.",
166-
reference=reference_path,
167-
actual=actual_path,
168-
)
169-
render(rendermode, reference, actual)
170-
160+
@info """Reference Test for \"$reference_filename\" failed:
161+
$(render(rendermode, reference, actual))
162+
""" reference = reference_path actual = actual_path
163+
171164
if !isinteractive() && !force_update()
172165
error("""
173166
To update the reference images either run the tests interactively with 'include(\"test/runtests.jl\")',
@@ -178,7 +171,7 @@ function test_reference(
178171

179172
if force_update() || input_bool("Replace reference with actual result?")
180173
mv(actual_path, reference_path; force=true) # overwrite old file it
181-
@info("Please run the tests again for any changes to take effect")
174+
@info "Please run the tests again for any changes to take effect"
182175
else
183176
@test false
184177
end

test/references/camera.png

26 Bytes
Loading

test/references/camera.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
▀▀▀▀▀▀▀▀▀
2-
▀▀▀▀▀▀▀▀▀
3-
▀▀▀▀▀▀▀▀▀
4-
▀▀▀▀▀▀▀▀▀
5-
▀▀▀▀▀▀▀▀▀
1+
▀▀▀▀▀▀▀▀▀
2+
▀▀▀▀▀▀▀▀▀
3+
▀▀▀▀▀▀▀▀▀
4+
▀▀▀▀▀▀▀▀▀
5+
▀▀▀▀▀▀▀▀▀

test/references/heatmap.png

-12.2 KB
Binary file not shown.

test/references/lena.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)