[Gambas-user] text interface apps

Doriano Blengino doriano.blengino at ...1909...
Wed Aug 12 19:49:04 CEST 2009


Tomas Eroles i Forner ha scritto:
> Hello all!
> I would like to know if it's possible, working with text apps, write 
> texts in the screen at any position.
>
> An example: I learned programming with dBase III, and we used the command:
>
> @2,5 SAY "Hello, what is your name?: " GET w_name
>
> to write on the coordinates 2,5 on the screen the phrase Hello, what is...
>
> Is it possible to do in GAMBAS?
>
> Thanks in advance
>   
There are kinds of program better suited to what you are describing, 
than to today's GUI interface...

Anyway... text screens in linux/unix are much different from the classic 
PC ones. They can have more (or sometimes less) row and columns, they 
can be local or (in theory) stupid terminals attached to serial lines, 
with stupid capabilities.

Turns out that writing in a precise position on a video, or erasing 
something, or setting a color, varies greatly from one case to another, 
but always is done by printing "ESC sequences". For example, many 
terminals clear the screen if you send them a ESC [ 2 J. Try this in a 
terminal:

    echo -e "\e[2J"

Similar escape sequences can do many more funny things. Something like 
ESC [ row;col H position the cursor:

    echo -e "\e[2;20H"

Now come on on our problem. Gambas doesn't have natively a support for 
this kind of things. So you can:

    1. use directly ESC sequences in your program. Simple sequences will 
work very often.
    2. use libraries like ncurses or slang. They will work always, but 
you will have to declare all the functions you need from those libraries 
(external declaration). This is long and tedious.
    3. make a set of subroutine which emulates a text screen on a normal 
form, using labels for example. This is funny.
    4. May be some QT or GTK component exists to do point number 3

It depends if you really want to use text mode, and at which degree of 
completeness. For example, using an emulated text mode in a GUI 
signifies it will not work with "real" text mode terminals (if someone 
still has them. I do, BTW...).

Choosing to not using libraries will make your program hardly portable, 
but I think that erasing screen and positioning cursor will work most of 
the times on linux console, xterm, rxvt, konsole, and many real terminals.

This is enough about a reply. If you want to know more, I am at your 
disposal :-)

Regards,
Doriano






More information about the User mailing list