From df995db8f9875bd6ee057c3ad774e61940cdd4a9 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sun, 19 Dec 2021 23:49:21 +0100 Subject: [PATCH] update CI for julia LTS 1.6 --- .github/workflows/ci.yml | 12 ++++++--- src/canvas/imgcanvas.jl | 55 ++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11e6c631..ae689dff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,9 +14,14 @@ jobs: strategy: fail-fast: false matrix: - version: ['1.0', '1', 'nightly'] - os: [ubuntu-latest] - arch: [x64] + version: + - '1.6' # LTS + - '1' # latest stable + - 'nightly' + os: + - ubuntu-latest + arch: + - x64 include: # spare windows/macos CI credits - os: windows-latest version: '1' @@ -24,6 +29,7 @@ jobs: - os: macOS-latest version: '1' arch: x64 + steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 diff --git a/src/canvas/imgcanvas.jl b/src/canvas/imgcanvas.jl index 4d84d23a..96291d70 100644 --- a/src/canvas/imgcanvas.jl +++ b/src/canvas/imgcanvas.jl @@ -1,39 +1,40 @@ struct ImgCanvas <: Canvas - img::AbstractArray{<:Colorant} - ren::Vector{String} - encoded_size::Vector{Int} - sixel::Ref + img::AbstractArray{<:Colorant} + ren::Vector{String} + encoded_size::Vector{Int} + sixel::Ref end -function ImgCanvas(img::AbstractArray{<:Colorant}) - render(ImgCanvas(img, String[], [0, 0], Ref(false))) -end +ImgCanvas(img::AbstractArray{<:Colorant}) = + render(ImgCanvas(img, String[], [0, 0], Ref(false))) @inline nrows(c::ImgCanvas) = c.encoded_size[1] @inline ncols(c::ImgCanvas) = c.encoded_size[2] function render(c::ImgCanvas) - if ImageInTerminal.use_sixel(c.img) - c.sixel[] = true - lines = String[] - h, w = size(c.img) - char_pixels = ImageInTerminal.Sixel.TerminalTools.query_terminal("\e[16t", r"\e\[6;(\d+);(\d+)t", stdout) - char_h, char_w = length(char_pixels) > 1 ? parse.(Int, char_pixels) : (15, 7) - for r ∈ 1:char_h:h - io = IOBuffer() - ImageInTerminal.sixel_encode(io, c.img[r:min(r + char_h - 1, h), :]) - push!(lines, String(take!(io))) + if ImageInTerminal.use_sixel(c.img) + c.sixel[] = true + h, w = size(c.img) + # determine the terminal carret size, in pixels + char_pixels = ImageInTerminal.Sixel.TerminalTools.query_terminal("\e[16t", r"\e\[6;(\d+);(\d+)t", stdout) + char_h, char_w = length(char_pixels) > 1 ? parse.(Int, char_pixels) : (15, 7) + lines = String[] + io = IOBuffer() + for r ∈ 1:char_h:h + ImageInTerminal.sixel_encode(io, c.img[r:min(r + char_h - 1, h), :]) + push!(lines, String(take!(io))) + end + enc_size = length(lines), ceil(Int, w / char_w) + else + io = PipeBuffer() + ImageInTerminal.imshow(io, c.img) + lines = readlines(io) + enc_size = length(lines), length(replace(first(lines), r"\x1B\[[0-9;]*[a-zA-Z]" => "")) end - copyto!(c.encoded_size, [length(lines), ceil(Int, w / char_w)]) - else - io = PipeBuffer() - ImageInTerminal.imshow(io, c.img, ImageInTerminal.colormode[1]) - lines = readlines(io) - copyto!(c.encoded_size, [length(lines), length(replace(first(lines), r"\x1B\[[0-9;]*[a-zA-Z]" => ""))]) - end - resize!(c.ren, nrows(c)) - copyto!(c.ren, lines) - c + copyto!(c.encoded_size, enc_size) + resize!(c.ren, nrows(c)) + copyto!(c.ren, lines) + c end function printrow(io::IO, c::ImgCanvas, row::Int)