[RFC] ColorD

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Oct 25 16:23:26 PDT 2012


On Fri, Oct 26, 2012 at 12:27:38AM +0200, Jens Mueller wrote:
> Walter Bright wrote:
[...]
> > A module that only sets the console color is a little too light to
> > be a phobos entry.
> > 
> > A more comprehensive module that included:
> > 
> > 1. getting mouse input
> 
> Anybody an idea how to this on Linux?

You can only do this in terminals that support it. XTerm, I believe, has
escape sequences that you can send to turn on mouse tracking. Those will
show up as special escape sequences on stdin, which will have to be
intercepted and removed from the program's normal input stream. Other
modern terminals probably have their own way of doing mouse tracking.
AFAIK, there isn't any standard for this, so you'll have to stick with
terminal-specific code.

(Which is why I recommended earlier that this module must be modular so
that support for specific terminals can be plugged in easily -- for the
initial stab, something very simple such as vt100 support may be good
enough, as long as it's easy to add support for new terminals.)


> > 2. getting size of the console
> 
> This is easy if you just mean the number of lines and columns.

I think that's good enough. A text-mode app doesn't need to know pixel
sizes. (If it does, it really should be using a real GUI toolkit
instead.)


> > 3. moving the cursor around
> 
> This also assuming you just want something like, move 10 lines up, 3
> lines right etc.

Handling absolute positions (x columns y rows from upper left corner of
terminal) is a must. Pixel positions is not necessary (and probably
impossible -- text terminals AFAIK don't provide that kind of info).


> > 4. drawing boxes in the console window
> 
> Should this be done by moving the cursor and inserting characters such
> that you have a box in the end?

I think the implementation details are unimportant, as long as there's a
way to say "draw a box at (x,y) with dimensions (w,h)" and the module
will do whatever is necessary to accomplish that.


> > 5. setting the contents of the title bar
> 
> The title bar of what?

The terminal window. Many X11 terminals, like xterm and rxvt, support an
escape sequence that lets you set/change what's displayed on the title
bar of the window.

(Personally, though, I don't like this feature; I find it very annoying.
But many people like it, so it should still be supported, I think.)


> > 6. supporting cut/paste
> 
> Don't know how to do this? Anybody a starting point?

I'm not sure what Walter is referring to specifically. Usually cut and
paste is supported directly by the terminal, and the program running in
the terminal doesn't get to control it. It only sees pasted text as a
sudden large chunk of data on stdin. I don't think this is the job of
the console module (Walter, correct me if I'm wrong).


> > 7. getting no-echo raw input
> 
> Tried this but couldn't make it work yet. This is useful for passwords
> prompts, right?

Not just that, but also for fully-interactive programs that want to
capture every keystroke immediately (instead of waiting for the user to
hit Enter). Like games and stuff. Or menu-driven systems where the user
can navigate between menus and items without needing to hit Enter each
time.

For Unix terminals, you need to send certain escape sequences (specific
to the terminal) to enable what is called 'raw' mode or 'cbreak' mode.
(Googling for 'cbreak' should give you useful references.) This will
cause the terminal to immediately transmit keystrokes, instead of
buffering them until the user hits Enter.

Also, make sure that there is a way to turn off this mode after the
program is finished, otherwise the terminal may become unusable when it
returns to the shell prompt. :)


> > 8. setting the size of the cursor
> 
> The size of the cursor? Why should I want to change its size?
[...]

I think Walter is referring to the DOS/Windows-specific feature that
certain BIOS calls allow you to change the starting/ending scanlines of
the cursor. I suppose some people like to see a big flashing white box
for their cursor and others prefer just a flashing underscore, but
personally, I don't see this as a must-have feature. I think some
terminals don't even support such a setting.

In any case, I think this is a low-priority nice-to-have thing. The
important stuff are cursor positioning, box drawing, incremental
updates, cbreak mode, etc..


T

-- 
A linguistics professor was lecturing to his class one day. "In English," he said, "A double negative forms a positive. In some languages, though, such as Russian, a double negative is still a negative. However, there is no language wherein a double positive can form a negative." A voice from the back of the room piped up, "Yeah, yeah."


More information about the Digitalmars-d mailing list