Subject: Getting screen size into the env?

From: "Aaron Davies" <[email-masked]>
Date: Thu, 7 Aug 2008 13:38:43 +0800

How do I get the screen size env vars set properly? Screen appears to
be populating TERMCAP for me (correctly), as it's not defined when
outside of screen, but does exist inside.

$ echo $TERMCAP|tr : \\n|egrep li\|co
li#62
co#158
$ env|grep 62\|158
$ echo $?
1

I'm running screen under cygwin, using the latest version of cygwin,
the cygwin distro of screen, and the latest version of puttycyg as my
terminal.
-- 
Aaron Davies
[email-masked]

_______________________________________________
screen-users mailing list
[email-masked]
http://lists.gnu.org/mailman/listinfo/screen-users

---

From: Micah Cowan <[email-masked]>
Date: Wed, 06 Aug 2008 23:14:56 -0700

> outside of screen, but does exist inside.

There's nothing that ever sets env vars to the screen size.

However, if you use bash, it will set _shell_ variables, COLUMNS and
LINES, automatically. This isn't something that screen does, but bash.
Bash does _not_ export these by default, however; you'll need to do

 $ export COLUMNS LINES

to get them into the environment. Of course, if you're not running bash,
you may not have them at all; in which case you may need to parse them
out of the screen-supplied TERMCAP (which, unlike the bash vars, can't
be kept up-to-date when the window size changes).

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/

---

From: "Aaron Davies" <[email-masked]>
Date: Thu, 7 Aug 2008 14:43:22 +0800

> be kept up-to-date when the window size changes).

Hmm, OK. I am running bash, at least according to /etc/passwd, though
$SHELL seems to be "sh". In any case, zsh seems to do it correctly on
my setup, and I prefer zsh anyway.
-- 
Aaron Davies
[email-masked]

---

From: "Thomas Adam" <[email-masked]>
Date: Thu, 7 Aug 2008 08:10:56 +0100

> Bash does _not_ export these by default, however; you'll need to do

Rather unportably between Unixes:

eval $(resize)

-- Thomas Adam

---

From: Mark Eichin <[email-masked]>
Date: Thu, 07 Aug 2008 12:18:53 -0400

> Rather unportably between Unixes:

resize requires having a terminal type that actually does xterm-style
answerback, which as at best a "maybe".

What you *really* want is the output of stty:
$ stty -a |grep rows
speed 38400 baud; rows 56; columns 144; line = 0;

because it's a property of the tty, and changed there - putting the
values in the environment is an old and not-really-workable hack.

---

From: Juergen Weigert <[email-masked]>
Date: Mon, 11 Aug 2008 20:53:44 +0200

> >> Bash does _not_ export these by default, however; you'll need to do

This may work, if the screen does not get resized while it is running.
I have my screen session inside an xterm, and resize frequently.
environment variables would still reflect the old value after a resize.

> answerback, which as at best a "maybe".

When run from within screen, we guarantee you that xterm-style
answerback is honored. Screen is an xterm-compatible device.

> values in the environment is an old and not-really-workable hack.

The best thing to do, is to keep them all in sync:

 - Measure the real dimension like resize does, 
 - Then check what the PTY thinks, and run stty to set cols and rows,
   in case a SIGWINCH got lost.
 - Then check shell variables COLUMNS and LINES, and fire SIGWINCH to the
   shell, if they do not match. The shell will fetch them from the PTY
   then.

-- 
 o \  Juergen Weigert      unix-software __/ _=======.=======_     
<V> | [email-masked]         creator    __/        _---|____________\/    
 \  |            0179/2069677      __/          (____/            /\
(/) | ____________________________/              _/ \_ vim:set sw=2 wm=8

---

From: Michael Parson <[email-masked]>
Date: Tue, 12 Aug 2008 15:12:37 -0500 (CDT)

> answerback is honored. Screen is an xterm-compatible device.

I used to use the eval $(resize) method a lot, but at some point, the
shell I use (bash 3.2.33, atm) has an option for checking the window
size before executing any command:

shopt -s checkwinsize

I'm not sure what version introduced this feature, I only discovered it
when I re-read the man-page after one of the 3.x releases.

-- 
Michael Parson
[email-masked]