nabijaczleweli / termimage

Display images in your terminal, kind of
MIT License
209 stars 4 forks source link

Support truecolor #5

Closed joshtriplett closed 8 years ago

joshtriplett commented 8 years ago

Some terminals support truecolor escape sequences. ansi_term supports those; with them, you can render the exact pixel color from the image. (http://invisible-island.net/xterm/ctlseqs/ctlseqs.html documents the escape sequences, though I'd suggest using ansi_term rather than writing them directly.)

nabijaczleweli commented 8 years ago

Good shit :+1:

nabijaczleweli commented 8 years ago

Is there a capability query for this or can we use it at all times and assume everything supports it?

joshtriplett commented 8 years ago

Not every terminal supports it, no. And unfortunately, termcap and terminfo don't provide a capability to detect this support. A wide range of terminals support it, but not all terminals.

Perhaps you could add an option to support it, and attempt to autodetect when you can enable that option based on TERM and other environment variables? Not pleasant, though.

nabijaczleweli commented 8 years ago

If we'd be going the $TERM route, which terminals support it?

joshtriplett commented 8 years ago

@nabijaczleweli After doing some further searching, it turns out that an unofficial terminfo capability "tc" exists to identify terminals with truecolor support. See http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002260.html . Unfortunately, very few terminals actually list that capability.

See https://gist.github.com/XVilka/8346728 for a list of terminals supporting truecolor. Unfortunately, you can't easily identify all of them by TERM, since some use the same TERM string; many terminals identify themselves as TERM=xterm. I think you can assume truecolor if you see VTEVERSION set (to any value), or TERM set to xterm-256color, vte, vte-, konsole, konsole-_ , and probably many others. This seems like an unfortunate whitelist to have to maintain. :(

nabijaczleweli commented 8 years ago

@joshtriplett Could you verify the current HEAD (by modifying main.rs#28 to write_ansi_256()) works?

joshtriplett commented 8 years ago

That doesn't work; it looks like you forgot the 'm' at the end, and the text to set the background color of.

I'd highly recommend not writing ANSI sequences by hand, and instead using the ansi_term crate.

(Also, it looks like you called the function write_ansi_265. And in any case, 256 wouldn't be accurate either; you probably want something like truecolor or 24bit.)

nabijaczleweli commented 8 years ago

Retry, please?

joshtriplett commented 8 years ago

That works.