comp.lang.ada
 help / color / mirror / Atom feed
* Line and Column size
@ 2004-02-09 18:27 Bill
  2004-02-09 19:08 ` Ludovic Brenta
  0 siblings, 1 reply; 2+ messages in thread
From: Bill @ 2004-02-09 18:27 UTC (permalink / raw)


I'm working on a project for school and I have created a very nice
looking TUI window library in ADA95. I thought as an added extra it
would be nice to be able to scale the TUI window to the size of the
current users terminal window. I have looked into using the $LINES and
$COLUMNS term variables, be they wont work since they need to be
exported. Therefore this would not be a safe method of getting the
lines/columns, since not all systems have the variables exported.
Another thing I have tried is to use the curses library. I wrote a
small C library using curses. It goes as follows:



code:--------------------------------------------------------------------------------
#include <curses.h>

struct scr
{
  int LINES;
  int COLUMNS;
};

struct scr GetScreen(void)
{
  struct scr Scr = {0,0};
  initscr();
  Scr.LINES = LINES;
  Scr.COLUMNS = COLS;
  endwin();
  return Scr;
}
--------------------------------------------------------------------------------


I can import the function fine into ADA95 by doing on of these:

code:--------------------------------------------------------------------------------
  TYPE scrsize IS RECORD
    LINES       : INTEGER := 0;
    COLUMNS : INTEGER := 0;
  END RECORD;

  FUNCTION GetSize Return scrsize IS
    Function GetScreen Return scrsize;
    pragma Import(C,GetScreen,"GetScreen");
  BEGIN -- GetSize
    RETURN GetScreen;
  END GetSize;
--------------------------------------------------------------------------------


Then to compile the code you do a
gcc -c myc_Lib.c
gnatmake main_prog.adb -largs -lcurses myc_lib.o

Now the C code returns the line and column numbers perfectly. However
it seems that when curses runs, it changes the screen, or does
something, because my TUI code no longer displays properly. The
terminal window seems to act wierd after my program exits.
So I was wondering if anyone knew what might be wrong or I'm not doing
that I should be in the C code, or if there is a better way to go
about doing what I'm doing. Maybe there is a library package for ADA95
that already does what I want it to, but I have just not found it yet.
Thanks for the help.

- Bill



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Line and Column size
  2004-02-09 18:27 Line and Column size Bill
@ 2004-02-09 19:08 ` Ludovic Brenta
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Brenta @ 2004-02-09 19:08 UTC (permalink / raw)


wjr17@attbi.com (Bill) writes:
[Calling curses' initscr() to know the terminal width and height]
> Now the C code returns the line and column numbers perfectly. However
> it seems that when curses runs, it changes the screen, or does
> something, because my TUI code no longer displays properly. The
> terminal window seems to act wierd after my program exits.
> So I was wondering if anyone knew what might be wrong or I'm not doing
> that I should be in the C code, or if there is a better way to go
> about doing what I'm doing. Maybe there is a library package for ADA95
> that already does what I want it to, but I have just not found it yet.
> Thanks for the help.

Yes, initscr() changes the screen and resets the cursor and stuff.

Maybe you should consider doing an ioctl yourself; that's what
initscr() does to get the size of the terminal:

at ncurses/tinfo/lib_setup.c:151:
ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size)

Look for documentation about ioctl.

Also, FWIW, the ncurses source tarball comes with an Ada binding.

HTH

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-02-09 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-09 18:27 Line and Column size Bill
2004-02-09 19:08 ` Ludovic Brenta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox