Skip to content

Commit 1721ca7

Browse files
committed
reorganize tests - hard Sixel dependency - format check
1 parent 3f62dd1 commit 1721ca7

16 files changed

+226
-178
lines changed

.JuliaFormatter.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
style = "blue"
2+
short_to_long_function_def = false
3+
always_use_return = false
4+
import_to_using = false
5+
align_struct_field = true
6+
align_conditional = true
7+
align_assignment = true
8+
align_pair_arrow = true

.github/workflows/format-check.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'release-'
8+
tags: '*'
9+
pull_request:
10+
11+
jobs:
12+
check:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
julia-version: ['1']
17+
julia-arch: [x64]
18+
os: [ubuntu-latest]
19+
steps:
20+
- uses: julia-actions/setup-julia@latest
21+
with:
22+
version: ${{ matrix.julia-version }}
23+
24+
- uses: actions/checkout@v3
25+
- name: Install JuliaFormatter and format
26+
run: |
27+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
28+
julia -e 'using JuliaFormatter; format(["src", "test"], verbose=true)'
29+
- name: Format check
30+
run: |
31+
julia -e '
32+
out = Cmd(`git diff --name-only`) |> read |> String
33+
if out == ""
34+
exit(0)
35+
else
36+
@error "Some files have not been formatted !!!"
37+
write(stdout, out)
38+
exit(1)
39+
end'

AsciiPixel/src/ascii.jl

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
abstract type ImageEncoder end
22
struct BigBlocks <: ImageEncoder
3-
size::NTuple{2, Int}
3+
size::NTuple{2,Int}
44
end
55
struct SmallBlocks <: ImageEncoder
6-
size::NTuple{2, Int}
6+
size::NTuple{2,Int}
77
end
88

9-
const RESET = Crayon(reset = true)
9+
const RESET = Crayon(; reset=true)
1010
const alpha_chars = ('', '', '', '', '')
1111

1212
function _charof(alpha)
@@ -91,22 +91,22 @@ function ascii_encode(
9191
::SmallBlocks,
9292
colordepth::TermColorDepth,
9393
img::AbstractMatrix{<:Colorant};
94-
trail_nl::Bool = false,
95-
ret::Bool = false
94+
trail_nl::Bool=false,
95+
ret::Bool=false,
9696
)
9797
yinds, xinds = axes(img)
9898
for y in first(yinds):2:last(yinds)
9999
_printc(io, RESET)
100100
for x in xinds
101101
fgcol = _colorant2ansi(img[y, x], colordepth)
102-
bgcol = if y+1 <= last(yinds)
103-
_colorant2ansi(img[y+1, x], colordepth)
102+
bgcol = if y + 1 <= last(yinds)
103+
_colorant2ansi(img[y + 1, x], colordepth)
104104
else
105105
# if reached it means that the last character row
106106
# has only the upper pixel defined.
107107
nothing
108108
end
109-
_printc(io, Crayon(foreground=fgcol, background=bgcol), "")
109+
_printc(io, Crayon(; foreground=fgcol, background=bgcol), "")
110110
end
111111
_printc(io, RESET)
112112
(trail_nl || y < last(yinds)) && println(io)
@@ -119,8 +119,8 @@ function ascii_encode(
119119
::BigBlocks,
120120
colordepth::TermColorDepth,
121121
img::AbstractMatrix{<:Colorant};
122-
trail_nl::Bool = false,
123-
ret::Bool = false,
122+
trail_nl::Bool=false,
123+
ret::Bool=false,
124124
)
125125
yinds, xinds = axes(img)
126126
for y in yinds
@@ -129,7 +129,7 @@ function ascii_encode(
129129
color = img[y, x]
130130
fgcol = _colorant2ansi(color, colordepth)
131131
chr = _charof(alpha(color))
132-
_printc(io, Crayon(foreground = fgcol), chr, chr)
132+
_printc(io, Crayon(; foreground=fgcol), chr, chr)
133133
end
134134
_printc(io, RESET)
135135
(trail_nl || y < last(yinds)) && println(io)
@@ -142,15 +142,15 @@ function ascii_encode(
142142
::SmallBlocks,
143143
colordepth::TermColorDepth,
144144
img::AbstractVector{<:Colorant};
145-
trail_nl::Bool = false,
146-
ret::Bool = false
145+
trail_nl::Bool=false,
146+
ret::Bool=false,
147147
)
148148
_printc(io, RESET)
149149
for i in axes(img, 1)
150150
color = img[i]
151151
fgcol = _colorant2ansi(color, colordepth)
152152
chr = _charof(alpha(color))
153-
_printc(io, Crayon(foreground = fgcol), chr)
153+
_printc(io, Crayon(; foreground=fgcol), chr)
154154
end
155155
_printc(io, RESET)
156156
trail_nl && println(io)
@@ -162,26 +162,26 @@ function ascii_encode(
162162
enc::BigBlocks,
163163
colordepth::TermColorDepth,
164164
img::AbstractVector{<:Colorant};
165-
trail_nl::Bool = false,
166-
ret::Bool = false
165+
trail_nl::Bool=false,
166+
ret::Bool=false,
167167
)
168168
w = length(img)
169169
n = enc.size[2] ÷ 3 == w ? w : enc.size[2] ÷ 6
170170
# left or full
171171
_printc(io, RESET)
172-
for i in (0:n-1) .+ firstindex(img)
172+
for i in (0:(n - 1)) .+ firstindex(img)
173173
color = img[i]
174174
fgcol = _colorant2ansi(color, colordepth)
175175
chr = _charof(alpha(color))
176-
_printc(io, Crayon(foreground = fgcol), chr, chr, " ")
176+
_printc(io, Crayon(; foreground=fgcol), chr, chr, " ")
177177
end
178178
if n < w # right part
179179
_printc(io, RESET, "")
180-
for i in (-n+1:0) .+ lastindex(img)
180+
for i in ((-n + 1):0) .+ lastindex(img)
181181
color = img[i]
182182
fgcol = _colorant2ansi(color, colordepth)
183183
chr = _charof(alpha(color))
184-
_printc(io, Crayon(foreground = fgcol), chr, chr, " ")
184+
_printc(io, Crayon(; foreground=fgcol), chr, chr, " ")
185185
end
186186
end
187187
_printc(io, RESET)
@@ -190,11 +190,9 @@ function ascii_encode(
190190
end
191191

192192
# use a `PipeBuffer` as io and returns encoded data reading lines of this buffer (using `readlines(io)`)
193-
ascii_encode(enc::SmallBlocks, args...) =
194-
ascii_encode(PipeBuffer(), enc, args...; ret=true)
193+
ascii_encode(enc::SmallBlocks, args...) = ascii_encode(PipeBuffer(), enc, args...; ret=true)
195194

196-
ascii_encode(enc::BigBlocks, args...) =
197-
ascii_encode(PipeBuffer(), enc, args...; ret=true)
195+
ascii_encode(enc::BigBlocks, args...) = ascii_encode(PipeBuffer(), enc, args...; ret=true)
198196

199197
"""
200198
ascii_display([stream], img, [depth::TermColorDepth], [maxsize])
@@ -214,8 +212,8 @@ function ascii_display(
214212
io::IO,
215213
img::AbstractMatrix{<:Colorant},
216214
colordepth::TermColorDepth,
217-
maxsize::Tuple = displaysize(io);
218-
kwargs...
215+
maxsize::Tuple=displaysize(io);
216+
kwargs...,
219217
)
220218
io_h, io_w = maxsize
221219
img_h, img_w = map(length, axes(img))
@@ -229,8 +227,8 @@ function ascii_display(
229227
io::IO,
230228
img::AbstractVector{<:Colorant},
231229
colordepth::TermColorDepth,
232-
maxsize::Tuple = displaysize(io);
233-
kwargs...
230+
maxsize::Tuple=displaysize(io);
231+
kwargs...,
234232
)
235233
io_h, io_w = maxsize
236234
img_w = length(img)

AsciiPixel/src/colorant2ansi.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
abstract type TermColorDepth end
2-
struct TermColor8bit <: TermColorDepth end
2+
struct TermColor8bit <: TermColorDepth end
33
struct TermColor24bit <: TermColorDepth end
44

55
"""
@@ -36,23 +36,24 @@ _colorant2ansi(gr::TransparentColor, colordepth::TermColorDepth) =
3636
# 8bit (256) colors
3737
function _colorant2ansi(col::AbstractRGB, ::TermColor8bit)
3838
r, g, b = clamp01nan(red(col)), clamp01nan(green(col)), clamp01nan(blue(col))
39-
r24, g24, b24 = map(c->round(Int, 23c), (r, g, b))
39+
r24, g24, b24 = map(c -> round(Int, 23c), (r, g, b))
4040
if r24 == g24 == b24
4141
# Use grayscales because of higher resolution
4242
# This way even grayscale RGB images look good.
4343
232 + r24
4444
else
45-
r6, g6, b6 = map(c->round(Int, 5c), (r, g, b))
45+
r6, g6, b6 = map(c -> round(Int, 5c), (r, g, b))
4646
16 + 36r6 + 6g6 + b6
4747
end
4848
end
4949

50-
_colorant2ansi(gr::Color{<:Any,1}, ::TermColor8bit) = round(Int, 232 + 23clamp01nan(real(gr)))
50+
_colorant2ansi(gr::Color{<:Any,1}, ::TermColor8bit) =
51+
round(Int, 232 + 23clamp01nan(real(gr)))
5152

5253
# 24 bit colors
5354
function _colorant2ansi(col::AbstractRGB, ::TermColor24bit)
5455
r, g, b = clamp01nan(red(col)), clamp01nan(green(col)), clamp01nan(blue(col))
55-
map(c->round(Int, 255c), (r, g, b))
56+
map(c -> round(Int, 255c), (r, g, b))
5657
end
5758

5859
function _colorant2ansi(gr::Color{<:Any,1}, ::TermColor24bit)

AsciiPixel/test/common.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# common test statements for ImageInTerminal and AsciiPixel
22

33
# define some test images
4-
gray_square = colorview(Gray, N0f8[0. .3; .7 1])
5-
gray_square_alpha = colorview(GrayA, N0f8[0. .3; .7 1], N0f8[1 .7; .3 0])
6-
gray_line = colorview(Gray, N0f8[0., .3, .7, 1])
7-
gray_line_alpha = colorview(GrayA, N0f8[0., .3, .7, 1], N0f8[1, .7, .3, 0])
8-
rgb_line = colorview(RGB, range(0, stop=1, length=20), zeroarray, range(1, stop=0, length=20))
4+
gray_square = colorview(Gray, N0f8[0.0 0.3; 0.7 1])
5+
gray_square_alpha = colorview(GrayA, N0f8[0.0 0.3; 0.7 1], N0f8[1 0.7; 0.3 0])
6+
gray_line = colorview(Gray, N0f8[0.0, 0.3, 0.7, 1])
7+
gray_line_alpha = colorview(GrayA, N0f8[0.0, 0.3, 0.7, 1], N0f8[1, 0.7, 0.3, 0])
8+
rgb_line = colorview(
9+
RGB, range(0; stop=1, length=20), zeroarray, range(1; stop=0, length=20)
10+
)
911
rgb_line_4d = repeat(repeat(rgb_line', 1, 1, 1, 1), 1, 1, 2, 2)
1012

1113
camera_man = testimage("camera") # .tif

AsciiPixel/test/runtests.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ function check_encoded(res::Vector{String}, expected::Vector{String})
1515
@test all(res .== expected)
1616
end
1717

18-
for t in (
19-
"tst_colorant2ansi.jl",
20-
"tst_ascii.jl",
21-
)
18+
for t in ("tst_colorant2ansi.jl", "tst_ascii.jl")
2219
@testset "$t" begin
2320
include(t)
2421
end

0 commit comments

Comments
 (0)