[Gambas-devel] ncurses component

Benoît Minisini gambas at ...1...
Wed Mar 28 23:04:20 CEST 2012


Le 28/03/2012 22:14, tobi a écrit :
> hi,
>
> i'm getting started writing an ncurses component for gambas which in turn gets me started with
> programming my first gambas component in c. as being redirected from the gambas-user list by
> Benoît, this message is almost the same as there:

I told you to come there just not to mix user questions and development 
questions.

>
> after having to read about those nifty configure scripts, i'm to face the first obstacle.
> this code works:
>
> -----
> ' Gambas module file
>
> Public Sub Main()
>
>    NCurses.On()
>    NCurses.Print("this is text", 10, 10)
>    NCurses.Attributes = NCurses.Bold Or NCurses.Reverse
>    Print " this is a brave test."
>    NCurses.Print("next line", , 11)
>    NCurses.WaitKey()
>    NCurses.Off()
>
> End
> -----
>
> but as the docs about programming components in c/c++ reasonably say, this is rather c-style and
> not suitable for the gambas language. (at the moment, there is one static object NCurses - i want
> to discover the api further before writing any serious classes).

One must study the NCurses API to see if we can make it easier for the 
final user, and/or make it object-oriented (i.e. does the API manipulate 
some kind of objects through pointer to structures?)

>
> the Print() _function_ takes optionally x,y coordinates from which to print the text using ncurses.
> i thought, it would be better to just use the Print instruction to print text instead of this
> function all over again - this is just not aesthetic (but bearable?).
> while the Print _instruction_ works fine so far - tried also with multiple ncurses WINDOWs
> present - it always prints after the current cursor position, no matter what's there. that's the
> same with the ncurses functions, the main and actual problem is that i turned on some attributes
> which are handled by the library, too. the text from the Print instruction doesn't get bold and
> video reversed. consequently, one may never use Print instruction to stdout in ncurses mode and
> this option has departed...
> i had the weirdest ideas of redirecting stdout to a stream object inside the ncurses component,
> reading from that and printing the data with the ncurses functions, but that's way too strange...
>
> any suggestions/ideas about a suitable interface for something that fundamental? or may the above
> code fit? (i appear to not often use the ncurses mvwprintw() in any bigger thing without having
> built a wrapper around it or controlled it via a loop, so this may really fit as is...)
>
> what is your opinion now?
>

You can create a Window class that will represent a ncurses window, and 
put all window related methods and properties in it.

You could have a special Window object that represent the default screen.

A funny thing: the Window class could have methods and properties to 
mimic the old Basic syntax: LOCATE (to move the cursor), CLS (to clear 
the screen), PEN and PAPER (to change the foreground and background 
color, this is the AMSTRAD syntax).

Like the gb.net component with the Socket class, you can make a Window 
object that will inherit Stream. When using PRINT on the Window object, 
your stream write function will be called. Then you will be able to call 
the ncurses function from there and print to the window.

That does not prevent your Window class from having a Print method. It 
just allows the user to use two different ways to do the same thing.

Now I will add a gb.ncurses component directory to the source code with 
nothing in it (except the basic files). Then you will modify them, 
adding what you have already written, and so on, by using subversion. 
For that, I need your sourceforge account name to grant you a write 
access to the repository.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list