Search code examples
htmlcurlansi-colorshttpie

Rendering colors to command line from html?


I've tried using HTTPie and Curl, but neither appear to support the following scenario.

curl somesite.com/somefile.html
<span style="color: blue;">I am blue!</span>

I'm in control of the site, so I can use any markup I'd like, but I was hoping there was something that did something like the above, which is to say take downloaded HTML output, and render it in ANSI colors.

UPDATE:

This is a demo, I'll be running from a Mac, against a node.js end point.

In the demo, I'd like to execute a loop:

while true; do curl http://somesite.com; sleep 1; done

After running this for ~5 seconds, I'll change a setting on the server, that will change this output. So, something like this:

I am blue!
I am blue!
I am blue! (Change occurs)
I am green!
I am green!
I am green!

And so on. I'd like to make that output (inside a Mac console) to change to the color that it says here. I've tried passing through the ANSI color codes, but it doesn't render.


Solution

  • Looks like the answer was (thanks to Dekel) that you basically have to hand it to xargs - curl doesn't do it itself.

    Worse, Mac xargs is different than Linux.

    Here's how I did it:

    curl localhost | xargs -0 -I {} printf "{}";