From b928463da343a1acb4a9ee3e7baa56d2f548a872 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 ++++++--- Project.toml | 2 +- src/UnicodePlots.jl | 2 +- src/canvas/imgcanvas.jl | 54 ++++++++++++++++++++-------------------- 4 files changed, 38 insertions(+), 32 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/Project.toml b/Project.toml index 1490ea78..ee8fadad 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] -ColorTypes = "0.11" +ColorTypes = "0.9 - 0.11" Crayons = "4.0" Requires = "1" StatsBase = "0.32, 0.33" diff --git a/src/UnicodePlots.jl b/src/UnicodePlots.jl index a6124675..623390cb 100644 --- a/src/UnicodePlots.jl +++ b/src/UnicodePlots.jl @@ -87,7 +87,7 @@ include("interface/boxplot.jl") image(args...; kwargs...) = @warn "not implemented, did you forget 'using ImageInTerminal' ?" function __init__() - @require ImageInTerminal="d8c32880-2388-543b-8c61-d9f865259254" begin + @require ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" begin image(img::AbstractArray{<:Colorant}; kwargs...) = Plot(ImgCanvas(img); kwargs...) end end diff --git a/src/canvas/imgcanvas.jl b/src/canvas/imgcanvas.jl index 4d84d23a..671510a5 100644 --- a/src/canvas/imgcanvas.jl +++ b/src/canvas/imgcanvas.jl @@ -1,39 +1,39 @@ 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 (c.sixel[] = ImageInTerminal.use_sixel(c.img)) + 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)