curses.tigetflag
curses.tigetnum
curses.tigetstr
Example:
phd@phd 1 >> python
Python 2.1.1 (#1, Aug 8 2001, 19:17:29)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import curses
>>> curses.setupterm()
>>> curses.tigetstr("khome")
'\x1b[1~'
I don't know which attributes describe width/height of a terminal.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ p...@phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
Not a good sign. Perhaps I'm missing something. Or am I really the
only person in Python's long and glorious history who has wanted to find
out the width of his terminal?
Greg
--
Greg Ward - software developer gw...@mems-exchange.org
MEMS Exchange http://www.mems-exchange.org
Ahh, thank you.
> I don't know which attributes describe width/height of a terminal.
For the record:
curses.tigetnum("cols")
curses.tigetnum("lines")
Now thank YOU :) I think I'll easily find neccessary information on it.
I didn't know about tiget* functions before your question. But I thought
"well, there is no direct termcap/info interfaces, may be curses?" and
found all neccessary things in docs :) I ran an example, got a traceback
with the mesage "at least run setupterm()" - and voila! :)
> On 17 October 2001, Oleg Broytmann said:
> > curses.tigetflag
> > curses.tigetnum
> > curses.tigetstr
>
> Ahh, thank you.
>
> > I don't know which attributes describe width/height of a terminal.
>
> For the record:
> curses.tigetnum("cols")
> curses.tigetnum("lines")
>
Here's what I do:
def getheightwidth():
""" getwidth() -> (int, int)
Return the height and width of the console in characters """
try:
return int(os.environ["LINES"]), int(os.environ["COLUMNS"])
except KeyError:
height, width = struct.unpack(
"hhhh", ioctl(0, TIOCGWINSZ ,"\000"*8))[0:2]
if not height: return 25, 80
return height, width
Where TIOCGWINSZ lives is an interesting game across Python versions.
It's in termios now.
I should probably look at terminfo too, but that would be the last
check.
I think ncurses' own order of checking goes:
env vars
ioctl
terminfo
25x80
but I haven't looked at this for a while.
HTH,
M.
--
48. The best book on programming for the layman is "Alice in
Wonderland"; but that's because it's the best book on
anything for the layman.
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html