[comp.sys.sgi] IRIS Keyboard & etc.

blue@cam.nist.gov (Jim Blue) (03/03/90)

Background: I am an experienced programmer and Unix user. I recently
got my Personal Iris, and have been porting my own editor, since (IMHO)
vi is brain-damaged.

I have been active at RTFM, all 31 volumes (though most of them don't apply)
but haven't found how to get the number of lines and columns inside a wsh.
(getsize() gives the size in pixels, but not in lines and columns.) Since vi,
among other programs knows how to do this, it must be possible.

Appendix A.2 of the "Using the GL/DGL Interface" in the "4Sight Programmer's
Guide lists the string supposedly returned by each key. I find that some
work and some don't. For example, F1 really does return "ESC [ 001 q" (without
the quotes and spaces), but F4 returns some garbage left over from an
old "ls" command. After powering the machine down and up, F4 returns some
other stuff (I don't know what).

Alt C with the right Alt key returns the correct value, but not with the
left Alt key.


Is there more wisdom hidden in the FM, or must one be telepathic?

Jim Blue
National Institute of Standards and Technology
disclaimer: The US Government doesn't know what I'm doing, and vice versa.

rpw3@rigden.wpd.sgi.com (Rob Warnock) (03/06/90)

In article <2715@fs1.cam.nist.gov> blue@cam.nist.gov (Jim Blue) writes:
+---------------
| I have been active at RTFM, all 31 volumes (though most of them don't apply)
| but haven't found how to get the number of lines and columns inside a wsh.
| (getsize() gives the size in pixels, but not in lines and columns.) Since vi,
| among other programs knows how to do this, it must be possible.
+---------------

Well, I don't know about "vi", but when porting a "lines&columns" app
to an Iris recently, I found the more-or-less-standard Berkeley kernel
screen size stuff [fragments attached below] to work just fine. That
is, TIOCGWINSZ to get the size, and SIGWINCH to know when it changes.
Resizing by dragging on a corner "does the right thing". So "wsh" must
be telling the kernel.

-Rob

-----
Rob Warnock, MS-9U/510		rpw3@sgi.com		rpw3@pei.com
Silicon Graphics, Inc.		(415)335-1673		Protocol Engines, Inc.
2011 N. Shoreline Blvd.
Mountain View, CA  94039-7311

============== attachment: code fragments ==================================

#ifdef TIOCGWINSZ             /* try to get window size from kernel */
struct winsize winsize;
#ifdef SIGWINCH               /* and if changing dynamically, track it
int   onwinch();
#endif
#endif

==============

	...somewhere in main()...
#ifdef SIGWINCH
	signal(SIGWINCH, onwinch());
#endif

==============

	...wherever it is (in main()?) you try to find out screen size...
#ifdef TIOCGWINSZ
	if (ioctl(0, TIOCGWINSZ, &winsize) >= 0
		&& winsize.ws_row > 0            /* avoid common stty screwup */
		&& winsize.ws_col > 0 ) {
		MaxRow = winsize.ws_row - 1;	/* make 0-based */
		MaxCol = winsize.ws_col - 1;
	} else
#endif
        {	/* just use termcap size */
                MaxRow = tgetnum ("li") - 1;
                MaxCol = tgetnum ("co") - 1;
        }
	...do whatever calculations are needed based on the screen size...

==============

#ifdef SIGWINCH
onwinch()
{
	/*
	 * screen size changed -- do the right things
	 */
        if (ioctl(0, TIOCGWINSZ, &winsize) >= 0
         && winsize.ws_row > 0          /* avoid common stty screwup */
         && winsize.ws_col > 0 ) {
                MaxRow = winsize.ws_row - 1;
                MaxCol = winsize.ws_col - 1;
        } else {
                MaxRow = tgetnum ("li") - 1;
                MaxCol = tgetnum ("co") - 1;
        }
	...do whatever calculations for values that have to change because
	   the screen size changed, then...
	redraw();			/* clear and draw from scratch */
        signal(SIGWINCH, onwinch);	/* re-enable signal */
}
#endif

msc@ramoth.esd.sgi.com (Mark Callow) (03/07/90)

--
From the TARDIS of Mark Callow
msc@ramoth.sgi.com, ...{ames,decwrl}!sgi!msc
"There is much virtue in a window.  It is to a human being as a frame is to
a painting, as a proscenium to a play.  It strongly defines its content."
In article <2715@fs1.cam.nist.gov>, blue@cam.nist.gov (Jim Blue) writes:
> I have been active at RTFM, all 31 volumes (though most of them don't apply)
> but haven't found how to get the number of lines and columns inside a wsh.
> (getsize() gives the size in pixels, but not in lines and columns.) Since vi,
> among other programs knows how to do this, it must be possible.
> 
Use the bsd ioctl.

#include <sys/termio.h>

	ioctl(fd, TIOCGWINSZ &winsiz)

or let curses/terminfo handle it for you.

It appears we didn't add this to our termio man page.  Sorry about that.

> Appendix A.2 of the "Using the GL/DGL Interface" in the "4Sight Programmer's
> Guide lists the string supposedly returned by each key. I find that some
> work and some don't. For example, F1 really does return "ESC [ 001 q"
(without
> the quotes and spaces), but F4 returns some garbage left over from an
> old "ls" command. After powering the machine down and up, F4 returns some
> other stuff (I don't know what).
wsh sets up some default bindings on the function keys.  See wsh(1) and
bindkey(1) for details.

> 
> Alt C with the right Alt key returns the correct value, but not with the
> left Alt key.
The left alt key is really a COMPOSE key.

	-Mark