python curses中的刷新错误 [英] Bug with refresh in python curses

查看:88
本文介绍了python curses中的刷新错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用curses编写程序,有时会发生以下情况:如果我将程序保持打开状态并且使用其他终端选项卡一段时间,那么当我再次使用该程序时,似乎已经刷新了某些内容,并且消失了...我无法显示图片或屏幕截图,因为我还不太清楚何时以及如何发生...是否有办法防止或解决此问题?

I'm writing a program in curses and sometimes happens that if I leave the program opened and I use other terminal tabs for a while, when I go using the program again it seems like it has refreshed something and something has disappeared... I cannot show pics or screenshots because I haven't understood yet well when and how it happens... Is there a way to prevent or fix this?

推荐答案

screen.getchstdscr读取,并且如果刷新(由于屏幕上的任何更改),将覆盖boxes.您可以将其更改为box.getch,就像我在

screen.getch reads from stdscr, and if it refreshes (due to any change on the screen), will overwrite boxes. You could change that to box.getch, as I did in scroll page by page or line by line using python curses

getch 的手册页说

The manual page for getch says

如果该窗口不是填充板,并且自上次调用 wrefresh 以来已被移动或修改,则将在读取另一个字符之前调用 wrefresh .

If the window is not a pad, and it has been moved or modified since the last call to wrefresh, wrefresh will be called before another character is read.

在您使用的示例程序中

screen.keypad( 1 )

仅适用于从标准屏幕读取.如果您从box窗口中读取,则应在其上设置键盘标志:

which only applies to reading from the standard screen. If you read from the box window, you should set the keypad flag on that:

box.keypad( 1 )

keypad 的手册页说

The manual page for keypad says

键盘的默认值为FALSE

The default value for keypad is FALSE

,即每个窗口的默认设置.

具有多个窗口的curses程序可以选择在不同的时间从不同的窗口读取.每个屏幕只有一个输入缓冲区,但是刷新当前窗口的副作用使管理窗口更新变得更加简单. (对于复杂的窗口堆叠顺序,您可以使用 panel 库而不是依赖于这种副作用.

A curses program with multiple windows can choose to read from different windows at different times. There is only one input buffer for each screen, but the side-effect of refreshing the current window makes it simpler to manage updates to the windows. (For complicated window stacking order, you would use the panel library rather than rely upon this side-effect).

这篇关于python curses中的刷新错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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