[RFC] ColorD

Jens Mueller jens.k.mueller at gmx.de
Fri Oct 26 01:06:38 PDT 2012


H. S. Teoh wrote:
> 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.)

So there exists no portable library abstracting mouse input?
If that's the case then being modular is the only option. How would you
design it? I don't plan to implement this. But leaving the door open for
others should be possible.

[snip]
> > > 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).

Okay. But this is no problem to build on top. I forget to mention that
there is one sequence that move the cursor a specific line/column.

> > > 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.

That means this can also be built on top of cursor moving.

> > > 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.)

I have to look up that. I find it strange because the Linux console does
not have a title bar. But if that is accessible using tinfo I will add
this. I find it strange, too. I think changing the title of a window is
more like a GUI thing.

> > > 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. :)

Thanks for the pointers.
So these are then two things. First noecho and the other one is raw
input.

> > > 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..

Can you say something about incremental updates? Any pointers?

Jens


More information about the Digitalmars-d mailing list