Re: Text mode screen size max. compatibility

2010-07-23 Thread A. Wright


On Fri, 23 Jul 2010, Polytropon wrote:


Is there a way to easily determine the terminal output size at
program startup so the program can be preconfigured for certain
screen sizes, and even refuse to run if it's less than 80x25?


The curses library will do this.  The variables LINES and COLS
will tell you what you want.

#include curses.h
main()
{
initscr();
printw(LINES = %d, COLS=%d -- press a key to quit\n, LINES, 
COLS);
refresh();
getch();
endwin();
exit(0);
}


A.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Text mode screen size max. compatibility

2010-07-23 Thread Polytropon
On Fri, 23 Jul 2010 15:44:27 -0300 (ADT), A. Wright and...@qemg.org wrote:
 
 On Fri, 23 Jul 2010, Polytropon wrote:
 
  Is there a way to easily determine the terminal output size at
  program startup so the program can be preconfigured for certain
  screen sizes, and even refuse to run if it's less than 80x25?
 
 The curses library will do this.  The variables LINES and COLS
 will tell you what you want.

Cool - I planned to use (n)curses anyway. But one question remains:
Is there an interrupt line (or something functionally similar,
a flag or whatever) that will give the chance for a notification
if LINES or COLS has recently changed, e. g. through a window
size modification?



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Text mode screen size max. compatibility

2010-07-23 Thread Dan Nelson
In the last episode (Jul 23), Polytropon said:
 On Fri, 23 Jul 2010 15:44:27 -0300 (ADT), A. Wright and...@qemg.org wrote:
  
  On Fri, 23 Jul 2010, Polytropon wrote:
   Is there a way to easily determine the terminal output size at program
   startup so the program can be preconfigured for certain screen sizes,
   and even refuse to run if it's less than 80x25?
  
  The curses library will do this.  The variables LINES and COLS will
  tell you what you want.
 
 Cool - I planned to use (n)curses anyway. But one question remains: Is
 there an interrupt line (or something functionally similar, a flag or
 whatever) that will give the chance for a notification if LINES or COLS
 has recently changed, e.  g.  through a window size modification?

If you haven't trapped the SIGWINCH signal (which is sent on terminal size
changes) yourself, ncurses will install its own handler.  It will queue a
virtual KEY_RESIZE keypress that you can check for in your input loop.  You
can then redraw your display to fit the new window size.

-- 
Dan Nelson
dnel...@allantgroup.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Text mode screen size max. compatibility

2010-07-23 Thread Chuck Swiger
Yes--

On Jul 23, 2010, at 12:08 PM, Polytropon wrote:
 Cool - I planned to use (n)curses anyway. But one question remains:
 Is there an interrupt line (or something functionally similar,
 a flag or whatever) that will give the chance for a notification
 if LINES or COLS has recently changed, e. g. through a window
 size modification?

Yes, ncurses supports this:

   The ncurses library includes facilities for responding to window resiz-
   ing events, e.g., when running in an xterm.  See the resizeterm(3X) and
   wresize(3X)  manual pages for details.  In addition, the library may be
   configured with a SIGWINCH handler.

Regards,
-- 
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Text mode screen size max. compatibility

2010-07-23 Thread Polytropon
Chuck, Dan, Andrew,

this is exactly what I was looking for. The manpages of resozeterm
and the mentioning of KEY_RESIZE in getch()'s input queue gives a
good solution to call a specific function when in any input loop.
The needed information about the new screen dimensions can then
easily be obtained, and screen features can be rearranged and re-
painted. Ncurses really rocks. :-)

Thank you!


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org