Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set explicitly the terminal size when using pexpect

I have a ncurses app that checks terminal size at startup and exits immediately if it doesn't fit.

In Linux, the default size is 80x24, this app requires at least 25. The fix is easy, I'm just resizing the terminal emulation window (in X) before running the ncurses app.

I would like to automate the ncurses app with pexpect, but I'm getting stuck because it considers the terminal size smaller than required when launched through pexpect, so it doesn't run. Any way to specify the terminal size with pexpect explicitly at startup?

like image 679
JS_is_bad Avatar asked Oct 04 '09 09:10

JS_is_bad


2 Answers

You can also use :

import pexpect
child = pexpect.spawn(cmd)
child.setwinsize(400,400)
like image 135
rags Avatar answered Nov 16 '22 00:11

rags


Try setting the LINES and COLUMNS environment variables before you use pexpect.

Pexpect will pass on the environment to the subtask, and some (all?) curses programs read these environment variables before starting.

eg

import os
os.environ['LINES'] = "25"
os.environ['COLUMNS'] = "80"
# run pexpect stuff as before
like image 25
Nick Craig-Wood Avatar answered Nov 16 '22 02:11

Nick Craig-Wood