Keno / TerminalExtensions.jl

A package that makes Julia take advantage of cool terminal emulator features.
Other
42 stars 11 forks source link

v1 Missing show for media MIME? #38

Open JonathanAnderson opened 6 years ago

JonathanAnderson commented 6 years ago

I'm trying to get this to work for me in v1 since I used to love using this tool. I havent been able to get it to work, so i've put together what I think a MWE is and I'm running into a missing show method for a Base64EncodePipe. I

I've put this tiny png image into an buffer and try to display it directly as follows

~/root/usr/install/julia/julia 2>stderr.log
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> using TerminalExtensions

julia> x = UInt8[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
           0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00,
           0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x01, 0x47,
           0x59, 0x00, 0x00, 0x00, 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x01,
           0x86, 0xa0, 0x31, 0xe8, 0x96, 0x5f, 0x00, 0x00, 0x00, 0x5b, 0x49,
           0x44, 0x41, 0x54, 0x78, 0x9c, 0x2d, 0xcc, 0xb1, 0x09, 0x03, 0x30,
           0x0c, 0x05, 0xd1, 0xeb, 0xd2, 0x04, 0xb2, 0x4a, 0x20, 0x0b, 0x7a,
           0x34, 0x6f, 0x90, 0x15, 0x3c, 0x82, 0xc1, 0x8d, 0x0a, 0x61, 0x45,
           0x07, 0x51, 0xf1, 0xe0, 0x8a, 0x2f, 0xaa, 0xea, 0xd2, 0xa4, 0x84,
           0x6c, 0xce, 0xa9, 0x25, 0x53, 0x06, 0xe7, 0x53, 0x34, 0x57, 0x12,
           0xe2, 0x11, 0xb2, 0x21, 0xbf, 0x4b, 0x26, 0x3d, 0x1b, 0x42, 0x73,
           0x25, 0x25, 0x5e, 0x8b, 0xda, 0xb2, 0x9e, 0x6f, 0x6a, 0xca, 0x30,
           0x69, 0x2e, 0x9d, 0x29, 0x61, 0x6e, 0xe9, 0x6f, 0x30, 0x65, 0xf0,
           0xbf, 0x1f, 0x10, 0x87, 0x49, 0x2f, 0xd0, 0x2f, 0x14, 0xc9, 0x00,
           0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82];

julia> display(TerminalExtensions.iTerm2.InlineDisplay(), MIME("image/png"), x)
ERROR: MethodError: no method matching show(::Base64.Base64EncodePipe, ::MIME{Symbol("image/png")}, ::Array{UInt8,1})
Closest candidates are:
  show(::IO, ::MIME{Symbol("text/plain")}, ::AbstractArray) at arrayshow.jl:316
  show(::IO, ::MIME{Symbol("text/plain")}, ::Any) at sysimg.jl:194
  show(::IO, ::MIME{Symbol("text/csv")}, ::Any) at /home/janders/root/usr/install/julia/usr/share/julia/stdlib/v1.0/DelimitedFiles/src/DelimitedFiles.jl:828
  ...
Stacktrace:
 [1] display(::TerminalExtensions.iTerm2.InlineDisplay, ::MIME{Symbol("image/png")}, ::Array{UInt8,1}) at /home/janders/.julia/packages/TerminalExtensions/Uyyx3/src/TerminalExtensions.jl:98
 [2] top-level scope at none:0

so I define Base.show and added an IO field to the InlineDisplay so I could send output to stderr and pipe that to hd to see what was going on and this is what I got.

julia> Base.show(io::IO, ::MIME"image/png", x) = show(io, x)

julia> display(TerminalExtensions.iTerm2.InlineDisplay(stderr), MIME("image/png"), x)
1

julia> flush(stderr)

hd stderr.log

hd stderr
000000 1b 5d 31 33 33 37 3b 46 69 6c 65 3d 6e 61 6d 65  >.]1337;File=name<
000010 3d 61 57 31 68 5a 32 55 3d 3b 69 6e 6c 69 6e 65  >=aW1hZ2U=;inline<
000020 3d 31 3a 56 55 6c 75 64 44 68 62 4d 48 67 34 4f  >=1:VUludDhbMHg4O<
000030 53 77 67 4d 48 67 31 4d 43 77 67 4d 48 67 30 5a  >SwgMHg1MCwgMHg0Z<
000040 53 77 67 4d 48 67 30 4e 79 77 67 4d 48 67 77 5a  >SwgMHg0NywgMHgwZ<
000050 43 77 67 4d 48 67 77 59 53 77 67 4d 48 67 78 59  >CwgMHgwYSwgMHgxY<
000060 53 77 67 4d 48 67 77 59 53 77 67 4d 48 67 77 4d  >SwgMHgwYSwgMHgwM<
000070 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >CwgMHgwMCwgMHgwM<
000080 43 77 67 4d 48 67 77 5a 43 77 67 4d 48 67 30 4f  >CwgMHgwZCwgMHg0O<
000090 53 77 67 4d 48 67 30 4f 43 77 67 4d 48 67 30 4e  >SwgMHg0OCwgMHg0N<
0000a0 43 77 67 4d 48 67 31 4d 69 77 67 4d 48 67 77 4d  >CwgMHg1MiwgMHgwM<
0000b0 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >CwgMHgwMCwgMHgwM<
0000c0 43 77 67 4d 48 67 79 4d 43 77 67 4d 48 67 77 4d  >CwgMHgyMCwgMHgwM<
0000d0 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >CwgMHgwMCwgMHgwM<
0000e0 43 77 67 4d 48 67 79 4d 43 77 67 4d 48 67 77 4d  >CwgMHgyMCwgMHgwM<
0000f0 53 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >SwgMHgwMCwgMHgwM<
000100 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >CwgMHgwMCwgMHgwM<
000110 43 77 67 4d 48 67 31 59 69 77 67 4d 48 67 77 4d  >CwgMHg1YiwgMHgwM<
000120 53 77 67 4d 48 67 30 4e 79 77 67 4d 48 67 31 4f  >SwgMHg0NywgMHg1O<
000130 53 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >SwgMHgwMCwgMHgwM<
000140 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4e  >CwgMHgwMCwgMHgwN<
000150 43 77 67 4d 48 67 32 4e 79 77 67 4d 48 67 30 4d  >CwgMHg2NywgMHg0M<
000160 53 77 67 4d 48 67 30 5a 43 77 67 4d 48 67 30 4d  >SwgMHg0ZCwgMHg0M<
000170 53 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >SwgMHgwMCwgMHgwM<
000180 53 77 67 4d 48 67 34 4e 69 77 67 4d 48 68 68 4d  >SwgMHg4NiwgMHhhM<
000190 43 77 67 4d 48 67 7a 4d 53 77 67 4d 48 68 6c 4f  >CwgMHgzMSwgMHhlO<
0001a0 43 77 67 4d 48 67 35 4e 69 77 67 4d 48 67 31 5a  >CwgMHg5NiwgMHg1Z<
0001b0 69 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >iwgMHgwMCwgMHgwM<
0001c0 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 31 59  >CwgMHgwMCwgMHg1Y<
0001d0 69 77 67 4d 48 67 30 4f 53 77 67 4d 48 67 30 4e  >iwgMHg0OSwgMHg0N<
0001e0 43 77 67 4d 48 67 30 4d 53 77 67 4d 48 67 31 4e  >CwgMHg0MSwgMHg1N<
0001f0 43 77 67 4d 48 67 33 4f 43 77 67 4d 48 67 35 59  >CwgMHg3OCwgMHg5Y<
000200 79 77 67 4d 48 67 79 5a 43 77 67 4d 48 68 6a 59  >ywgMHgyZCwgMHhjY<
000210 79 77 67 4d 48 68 69 4d 53 77 67 4d 48 67 77 4f  >ywgMHhiMSwgMHgwO<
000220 53 77 67 4d 48 67 77 4d 79 77 67 4d 48 67 7a 4d  >SwgMHgwMywgMHgzM<
000230 43 77 67 4d 48 67 77 59 79 77 67 4d 48 67 77 4e  >CwgMHgwYywgMHgwN<
000240 53 77 67 4d 48 68 6b 4d 53 77 67 4d 48 68 6c 59  >SwgMHhkMSwgMHhlY<
000250 69 77 67 4d 48 68 6b 4d 69 77 67 4d 48 67 77 4e  >iwgMHhkMiwgMHgwN<
000260 43 77 67 4d 48 68 69 4d 69 77 67 4d 48 67 30 59  >CwgMHhiMiwgMHg0Y<
000270 53 77 67 4d 48 67 79 4d 43 77 67 4d 48 67 77 59  >SwgMHgyMCwgMHgwY<
000280 69 77 67 4d 48 67 33 59 53 77 67 4d 48 67 7a 4e  >iwgMHg3YSwgMHgzN<
000290 43 77 67 4d 48 67 32 5a 69 77 67 4d 48 67 35 4d  >CwgMHg2ZiwgMHg5M<
0002a0 43 77 67 4d 48 67 78 4e 53 77 67 4d 48 67 7a 59  >CwgMHgxNSwgMHgzY<
0002b0 79 77 67 4d 48 67 34 4d 69 77 67 4d 48 68 6a 4d  >ywgMHg4MiwgMHhjM<
0002c0 53 77 67 4d 48 67 34 5a 43 77 67 4d 48 67 77 59  >SwgMHg4ZCwgMHgwY<
0002d0 53 77 67 4d 48 67 32 4d 53 77 67 4d 48 67 30 4e  >SwgMHg2MSwgMHg0N<
0002e0 53 77 67 4d 48 67 77 4e 79 77 67 4d 48 67 31 4d  >SwgMHgwNywgMHg1M<
0002f0 53 77 67 4d 48 68 6d 4d 53 77 67 4d 48 68 6c 4d  >SwgMHhmMSwgMHhlM<
000300 43 77 67 4d 48 67 34 59 53 77 67 4d 48 67 79 5a  >CwgMHg4YSwgMHgyZ<
000310 69 77 67 4d 48 68 68 59 53 77 67 4d 48 68 6c 59  >iwgMHhhYSwgMHhlY<
000320 53 77 67 4d 48 68 6b 4d 69 77 67 4d 48 68 68 4e  >SwgMHhkMiwgMHhhN<
000330 43 77 67 4d 48 67 34 4e 43 77 67 4d 48 67 32 59  >CwgMHg4NCwgMHg2Y<
000340 79 77 67 4d 48 68 6a 5a 53 77 67 4d 48 68 68 4f  >ywgMHhjZSwgMHhhO<
000350 53 77 67 4d 48 67 79 4e 53 77 67 4d 48 67 31 4d  >SwgMHgyNSwgMHg1M<
000360 79 77 67 4d 48 67 77 4e 69 77 67 4d 48 68 6c 4e  >ywgMHgwNiwgMHhlN<
000370 79 77 67 4d 48 67 31 4d 79 77 67 4d 48 67 7a 4e  >ywgMHg1MywgMHgzN<
000380 43 77 67 4d 48 67 31 4e 79 77 67 4d 48 67 78 4d  >CwgMHg1NywgMHgxM<
000390 69 77 67 4d 48 68 6c 4d 69 77 67 4d 48 67 78 4d  >iwgMHhlMiwgMHgxM<
0003a0 53 77 67 4d 48 68 69 4d 69 77 67 4d 48 67 79 4d  >SwgMHhiMiwgMHgyM<
0003b0 53 77 67 4d 48 68 69 5a 69 77 67 4d 48 67 30 59  >SwgMHhiZiwgMHg0Y<
0003c0 69 77 67 4d 48 67 79 4e 69 77 67 4d 48 67 7a 5a  >iwgMHgyNiwgMHgzZ<
0003d0 43 77 67 4d 48 67 78 59 69 77 67 4d 48 67 30 4d  >CwgMHgxYiwgMHg0M<
0003e0 69 77 67 4d 48 67 33 4d 79 77 67 4d 48 67 79 4e  >iwgMHg3MywgMHgyN<
0003f0 53 77 67 4d 48 67 79 4e 53 77 67 4d 48 67 31 5a  >SwgMHgyNSwgMHg1Z<
000400 53 77 67 4d 48 67 34 59 69 77 67 4d 48 68 6b 59  >SwgMHg4YiwgMHhkY<
000410 53 77 67 4d 48 68 69 4d 69 77 67 4d 48 67 35 5a  >SwgMHhiMiwgMHg5Z<
000420 53 77 67 4d 48 67 32 5a 69 77 67 4d 48 67 32 59  >SwgMHg2ZiwgMHg2Y<
000430 53 77 67 4d 48 68 6a 59 53 77 67 4d 48 67 7a 4d  >SwgMHhjYSwgMHgzM<
000440 43 77 67 4d 48 67 32 4f 53 77 67 4d 48 67 79 5a  >CwgMHg2OSwgMHgyZ<
000450 53 77 67 4d 48 67 35 5a 43 77 67 4d 48 67 79 4f  >SwgMHg5ZCwgMHgyO<
000460 53 77 67 4d 48 67 32 4d 53 77 67 4d 48 67 32 5a  >SwgMHg2MSwgMHg2Z<
000470 53 77 67 4d 48 68 6c 4f 53 77 67 4d 48 67 32 5a  >SwgMHhlOSwgMHg2Z<
000480 69 77 67 4d 48 67 7a 4d 43 77 67 4d 48 67 32 4e  >iwgMHgzMCwgMHg2N<
000490 53 77 67 4d 48 68 6d 4d 43 77 67 4d 48 68 69 5a  >SwgMHhmMCwgMHhiZ<
0004a0 69 77 67 4d 48 67 78 5a 69 77 67 4d 48 67 78 4d  >iwgMHgxZiwgMHgxM<
0004b0 43 77 67 4d 48 67 34 4e 79 77 67 4d 48 67 30 4f  >CwgMHg4NywgMHg0O<
0004c0 53 77 67 4d 48 67 79 5a 69 77 67 4d 48 68 6b 4d  >SwgMHgyZiwgMHhkM<
0004d0 43 77 67 4d 48 67 79 5a 69 77 67 4d 48 67 78 4e  >CwgMHgyZiwgMHgxN<
0004e0 43 77 67 4d 48 68 6a 4f 53 77 67 4d 48 67 77 4d  >CwgMHhjOSwgMHgwM<
0004f0 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 77 4d  >CwgMHgwMCwgMHgwM<
000500 43 77 67 4d 48 67 77 4d 43 77 67 4d 48 67 30 4f  >CwgMHgwMCwgMHg0O<
000510 53 77 67 4d 48 67 30 4e 53 77 67 4d 48 67 30 5a  >SwgMHg0NSwgMHg0Z<
000520 53 77 67 4d 48 67 30 4e 43 77 67 4d 48 68 68 5a  >SwgMHg0NCwgMHhhZ<
000530 53 77 67 4d 48 67 30 4d 69 77 67 4d 48 67 32 4d  >SwgMHg0MiwgMHg2M<
000540 43 77 67 4d 48 67 34 07                          >CwgMHg4.<
000548

When I manually base64encoded the buffer, it didnt look like this either.

Is this user error or is something broken here?

JonathanAnderson commented 6 years ago

I was expecting something more like this

julia> base64encode(x)
"iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQAAAABbAUdZAAAABGdBTUEAAYagMeiWXwAAAFtJREFUeJwtzLEJAzAMBdHr0gSySiALejRvkBU8gsGNCmFFB1Hx4IovqurSpIRszqklUwbnUzRXEuIRsiG/SyY9G0JzJSVei9qynm9qyjBpLp0pYW7pbzBl8L8fEIdJL9AvFMkAAAAASUVORK5CYII="
JonathanAnderson commented 6 years ago

If I change TerminalExtensions.jl:95 from

show(Base64.Base64EncodePipe(buf),m,x)

to

write(Base64.Base64EncodePipe(buf),x)

Then TerminalExtensions works for me again.

But I'm not sure what the expected behaviour of show for a MIME type is supposed to be..