[Gambas-devel] ncurses component

tobi tobias at ...692...
Wed Mar 28 23:21:30 CEST 2012


On Wed, 28 Mar 2012, Benoît Minisini wrote:
> 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.

yes, i had an odd feeling asking that question there, too...

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


i'm already probing with that very Window class, but had a slightly different approach just because i
don't know of the old basic syntaxes (the funning thing i thought of was mirroring parts of the
gb.qt4/gb.gtk Windows to ncurses), i'll take a look on the basic syntaxes soon, it's kind of general
knowledge... maybe as soon as i'll create an account on sourceforge... (the most probably tomorrow, sorry)
i tried to figure out something like the inheritance of a Stream but i lacked knowledge of internal
stream behaviour, i.e. if i could overwrite whatever is used to process incoming data.

regards,
tobi





More information about the Devel mailing list