|
1 | 1 | using Colors |
2 | 2 | import ImageShow |
| 3 | +using Base64: Base64EncodePipe |
3 | 4 |
|
4 | 5 | Base.summary(io::IO, t::Tiling) = print(io, t.N, "-order ", typeof(t)) |
5 | 6 |
|
|
29 | 30 | function Base.show(io::IO, ::MIME"text/plain", t::Tiling) |
30 | 31 | summary(io, t) |
31 | 32 | (; N) = t |
32 | | - displaysize(io)[2] ≥ 4N || return print(io, "\n Output too large to fit terminal. Use \ |
33 | | - `using ImageView; imshow(AztecDiamonds.to_img(D))` to display as an image instead.") |
| 33 | + if displaysize(io)[2] < 4N |
| 34 | + printstyled( |
| 35 | + io, "\n Output too large to fit terminal. \ |
| 36 | + Use `using ImageView; imshow(AztecDiamonds.to_img(D))` to display as an image instead."; |
| 37 | + color = :black, |
| 38 | + ) |
| 39 | + return nothing |
| 40 | + end |
34 | 41 | t = adapt(Array, t) |
35 | 42 | foreach(Iterators.product(inds(N)...)) do (j, i) |
36 | 43 | j == 1 - N && println(io) |
@@ -76,3 +83,14 @@ function Base.show(io::IO, ::MIME"image/png", t::Tiling; kw...) |
76 | 83 | img = to_img(adapt(Array, t)) |
77 | 84 | show(io, MIME("image/png"), img; kw...) |
78 | 85 | end |
| 86 | + |
| 87 | +Base.showable(::MIME"juliavscode/html", (; N)::Tiling) = N > 0 |
| 88 | + |
| 89 | +function Base.show(io::IO, ::MIME"juliavscode/html", t::Tiling; kw...) |
| 90 | + img = to_img(adapt(Array, t)) |
| 91 | + print(io, "<img src='data:image/gif;base64,") |
| 92 | + b64_io = IOContext(Base64EncodePipe(io), :full_fidelity => true) |
| 93 | + show(b64_io, MIME("image/png"), img; kw...) |
| 94 | + close(b64_io) |
| 95 | + print(io, "' style='width: 100%; max-height: 500px; object-fit: contain; image-rendering: pixelated' />") |
| 96 | +end |
0 commit comments