Skip to content

Commit 0d9723b

Browse files
committed
rework for ReferenceTests
1 parent b1d0b58 commit 0d9723b

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

.JuliaFormatter.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
style = "blue"
22
short_to_long_function_def = false
3+
long_to_short_function_def = true
34
trailing_comma = "nothing"
45
always_use_return = false
56
import_to_using = false

Project.toml

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ version = "0.5.0"
66
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
77
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
88
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
9-
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
10-
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
119
Sixel = "45858cf5-a6b0-47a3-bbea-62219f50df47"
1210
XTermColors = "c8c2cc18-de81-4e68-b407-38a3a0c0491f"
1311

1412
[compat]
1513
ColorTypes = "0.9 - 0.11"
1614
Crayons = "^4.1"
1715
FileIO = "^1.6"
18-
ImageBase = "0.1"
19-
ImageCore = "0.9"
2016
Sixel = "0.1"
21-
XTermColors = "0.1"
17+
XTermColors = "0.2"
2218
julia = "1.6"
2319

2420
[extras]
2521
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
22+
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
2623
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
2724
ImageQualityIndexes = "2996bd0c-7a13-11e9-2da2-2f5ce47296a9"
2825
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
@@ -34,4 +31,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3431
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
3532

3633
[targets]
37-
test = ["CoordinateTransformations", "ImageIO", "ImageQualityIndexes", "ImageTransformations", "OffsetArrays", "ReferenceTests", "Rotations", "SparseArrays", "Test", "TestImages"]
34+
test = ["CoordinateTransformations", "ImageBase", "ImageIO", "ImageQualityIndexes", "ImageTransformations", "OffsetArrays", "ReferenceTests", "Rotations", "SparseArrays", "Test", "TestImages"]

src/ImageInTerminal.jl

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
module ImageInTerminal
22

33
using XTermColors
4-
using ImageCore
54
using ColorTypes
65
using Crayons
76
using FileIO
87

98
import XTermColors: TermColorDepth, TermColor8bit, TermColor24bit
10-
import ImageBase: restrict
119
import Sixel
1210

1311
# -------------------------------------------------------------------
@@ -57,8 +55,8 @@ function choose_sixel(img::AbstractArray)
5755
# Small images really do not need sixel encoding.
5856
# `60` is a randomly chosen value (10 sixel); it's not the best because
5957
# 60x60 image will be very small in terminal after sixel encoding.
60-
any(size(img) .<= 12) && return false
61-
all(size(img) .<= 60) && return false
58+
any(size(img) . 12) && return false
59+
all(size(img) . 60) && return false
6260
return true
6361
end
6462
end
@@ -110,24 +108,19 @@ Supported encoding:
110108
"""
111109

112110
function imshow(io::IO, img::AbstractArray{<:Colorant}, maxsize::Tuple=displaysize(io))
113-
buf = PipeBuffer()
114-
io_color = get(io, :color, false)
115-
iobuf = IOContext(buf, :color => io_color)
111+
buf = IOContext(PipeBuffer(), :color => get(io, :color, false))
116112
if choose_sixel(img)
117-
sixel_encode(iobuf, img)
113+
sixel_encode(buf, img)
118114
else
119115
if ndims(img) > 2
120116
Base.show_nd(
121-
iobuf,
122-
img,
123-
(iobuf, x) -> ascii_display(iobuf, x, COLORMODE[], maxsize),
124-
true
117+
buf, img, (buf, x) -> ascii_show(buf, x, COLORMODE[], :auto, maxsize), true
125118
)
126119
else
127-
ascii_display(iobuf, img, COLORMODE[], maxsize)
120+
ascii_show(buf, img, COLORMODE[], :auto, maxsize)
128121
end
129122
end
130-
write(io, read(iobuf, String))
123+
write(io, read(buf, String))
131124
end
132125

133126
imshow(img::AbstractArray{<:Colorant}, args...) = imshow(stdout, img, args...)
+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
▀▀▀▀▀▀▀▀▀▀
2-
▀▀▀▀▀▀▀▀▀▀
3-
▀▀▀▀▀▀▀▀▀▀
4-
▀▀▀▀▀▀▀▀▀▀
5-
▀▀▀▀▀▀▀▀▀▀
1+
████████████████████
2+
████████████████████
3+
████████████████████
4+
████████████████████
5+
████████████████████
6+
████████████████████
7+
████████████████████
8+
████████████████████
9+
████████████████████
10+
████████████████████

test/reference/mandril_small_8bit.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
▀▀▀▀▀▀▀▀▀▀
2-
▀▀▀▀▀▀▀▀▀▀
3-
▀▀▀▀▀▀▀▀▀▀
4-
▀▀▀▀▀▀▀▀▀▀
5-
▀▀▀▀▀▀▀▀▀▀
1+
████████████████████
2+
████████████████████
3+
████████████████████
4+
████████████████████
5+
████████████████████
6+
████████████████████
7+
████████████████████
8+
████████████████████
9+
████████████████████
10+
████████████████████

0 commit comments

Comments
 (0)