使用pexpect时如何显式设置终端大小 [英] How to set explicitly the terminal size when using pexpect

查看:170
本文介绍了使用pexpect时如何显式设置终端大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ncurses应用程序,该应用程序会在启动时检查终端大小,如果不合适则立即退出.

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

在Linux中,默认大小为80x24,此应用至少需要25x.修复很简单,我只是在运行ncurses应用之前调整终端仿真窗口的大小(在X中).

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.

我想使用pexpect使ncurses应用程序自动化,但我陷入困境,因为它认为通过pexpect启动时终端大小小于要求的大小,因此它无法运行.有什么方法在启动时通过pexpect显式指定终端大小吗?

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?

推荐答案

在使用pexpect之前,请尝试设置LINES和COLUMNS环境变量.

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

期望将环境传递给子任务,并且某些(全部?)curses程序在开始之前会读取这些环境变量.

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

例如

import os
os.environ['LINES'] = "25"
os.environ['COLUMNS'] = "80"
# run pexpect stuff as before

这篇关于使用pexpect时如何显式设置终端大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆