[Gambas-user] 2 console questions.
Tobias Boege
taboege at ...626...
Sat Mar 15 01:38:07 CET 2014
On Sat, 15 Mar 2014, ??????? ? wrote:
> Hi! :-)
> Thank you very much for this wonderful project!
>
> I just installed it and giving it a try.
> I have 2 questions, console programming related.
>
> 1) Is there any command Input-like, that allows for a specific number
> of characters input (without pressing Enter)?
> Eg. lets say, I'm presenting the user a Y or N question. What I
> expect, is a single character input (with no need, for pressing
> Enter).
>
> 2) Is there any way for coloring the text (eg. presenting a question
> with red or green letters), other than messing with ncurses?
> Something closer to BASIC tradition, maybe?
> Ncurses is more or less complicated! :-)
>
Ouch! I was already typing the answer: ncurses - then I read your last
paragraph :-) But maybe we can try without:
1) There is nothing to do that. Terminal is line-buffered by default, so you
will always have to wait for Return and then read the entire line using
the Line Input instruction. In the best case, the line will only consist
of "y" or "n" or "Y" or "N".
You can change the behaviour of the terminal but that would either
require messing around with struct termios using libc or using ncurses
which wraps that for you.
2) This is easy once you get used to it. You just have to know about escape
sequences. If you have a proper man-pages install, "$ man console_codes"
is your best friend.
To switch to, say, green foreground, you write in Gambas:
Print "\e[32m";
Print "This is green foreground"
of course, you need to switch that off at some point:
Print "\e[0m";
Print "Default rendition again"
Again, ncurses would wrap that for you.
The Gambas Console (which is built into the IDE to watch a program's stdout
and stderr) is not a full-featured terminal emulator. It won't interpret
those escape sequences, so you need to enable the "Use a terminal emulator"
option in the project options.
Note also that there is already a gb.ncurses component that helps you deal
with ncurses in the Gambas way (more or less). As you said you are new to
Gambas, I thought I should let you know... (attached is a project that shows
how you could have done the stuff with gb.ncurses).
Here[0] is also a tutorial introduction to gb.ncurses which explains the
setup to run those terminal-fancy programs. Have fun with Gambas!
Regards,
Tobi
[0] http://gambaswiki.org/wiki/tutorial/ncursestut
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ncurses-sample-0.0.1.tar.gz
Type: application/octet-stream
Size: 4738 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140315/88371eef/attachment.obj>
More information about the User
mailing list