Questions about windows support
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Feb 22 22:41:33 PST 2012
On Thu, Feb 23, 2012 at 06:02:30PM +1300, James Miller wrote:
[...]
> And I've been playing with trying to write my own terminal emulator. I
> actually kinda have one working, in C. I just need to wrap all the C
> code in functions and do all the interesting stuff in D.
[...]
> But I have plans for it, including some cool graphical stuff. I'm
> using clutter to render everything, so I can do all sorts of things
> with it, but to start with, I'd like to be able to display pictures
> inline, so you can do `cat my_pic.jpg` and rather throwing masses of
> garbage at you, it renders the picture, I might have to write my own
> cat to do so however...
[...]
Now *that* is an excellent idea!
Perhaps there's a way of detecting JPEG or PNG output, say some kind of
magic number detection ala /usr/bin/file. Buffer the first few bytes at
output at the start of new lines, and if it looks like a JPEG file,
buffer the rest of the output instead of displaying it immediately, and
if after reading more input it does appear to be a valid JPEG file, then
display it as an image. Otherwise flush the buffer and display it as
text.
To prevent problems with false positives causing output not to appear,
you could use a timer: if the data type can't be determined within, say,
1/20 of a second, then skip the detection and display the output as
text. Presumably if you do cat my_pic.jpg more than just the first few
bytes will come out in the first 1/20 of a second, so it will pretty
much reliably detect image data.
Or you can do it the easy way by having a dedicated escape sequence that
switches to image mode, and write a wrapper for cat that outputs this
sequence when it detects image data in its output. The danger though is
that you might get stuck in image mode if cat crashes before the image
data is completely spooled, in that case it'll be like the ole DOS days
when you got stuck in VGA mode when it has dropped back to the DOS
prompt, and typing only produces line noise on the screen. :P
T
--
This is a tpyo.
More information about the Digitalmars-d
mailing list