Sunday, November 9, 2014

Pigshell Pretty

In my last post I wanted to show how to write images to stdout from a builtin in pigshell. THINGS are sent down the pigshell pipeline and when they get to the end they magically appear as images, videos and other things with most un-terminal window like behaviour. That is, unless I use an 0.001 point font and the rendering code is an ascii artist's wet dream.

But there ain't so such thing as magic. THINGS must surely have .toHTML() functions or face being rendered as text. Or mime types. Or something like that. I had a nosey through the code and it turns out that the terminal checks whether THING is one of a number of types of objects it knows how to render. So in particular if I have an instanceof HTMLDivElement or HTMLIFrameElement it should render beautifully. Let's check in the shell.

First I will need a way of putting HTML inside divs:

pig$ echo '<span style="background-color:red;">pop</span>' | jf '(function(x){ans = document.createElement("div");ans.innerHTML=x;return ans;})(x)'



Now let's make a "subshell":


On that basis making a builtin that spits out HTML should be pretty easy.

No comments:

Post a Comment