11abstract type ImageEncoder end
22struct BigBlocks <: ImageEncoder
3- size:: NTuple{2, Int}
3+ size:: NTuple{2,Int}
44end
55struct SmallBlocks <: ImageEncoder
6- size:: NTuple{2, Int}
6+ size:: NTuple{2,Int}
77end
88
9- const RESET = Crayon (reset = true )
9+ const RESET = Crayon (; reset = true )
1010const alpha_chars = (' ⋅' , ' ░' , ' ▒' , ' ▓' , ' █' )
1111
1212function _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(
190190end
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)
0 commit comments