在python中的curses中获取echo / noecho状态

时间:2016-02-23 20:31:21

标签: python curses

我可以使用Insert sentence: Ellipse Inserted sentence is: Ellipse There are 7 symbols in the string There are 6 different symbols in the string.The symbols are: Elipse Number of vowels 3. echo()在curses中设置回显状态,但是如何才能看到我目前所处的状态?这就是我想要做的事情:

noecho()

我正在寻找要完成的任务# get current echo state if screen.echo_is_on(): my_echo_state=False # echo is currently off curses.echo() # turn echo on else: my_echo_state=True # echo is already on # get input from user input_str = screen.getstr(r, c) # return echo to previous state if my_echo_state==False: curses.noecho()

2 个答案:

答案 0 :(得分:2)

Python curses binding中的echo没有 getter 函数。

  • Python具有与curses C函数对应的方法。
  • C绑定中echo(以及其他一些函数)的状态存储在SCREEN结构中,该结构通常是不透明的。
  • 其他状态信息存储在WINDOW中,且不是不透明的。

原始curses界面有扩展。 NetBSD为WINDOW等引入了 opaque 结构的概念。后来,ncurses采用了这个选项来帮助隐藏/控制线程应用程序的状态信息。为此,ncurses添加了从WINDOW访问数据的功能(参见curs_opaque(3x))。

但是,没有用于访问SCREEN内容的新功能。这些的启用/禁用功能在curs_inopts(3x)

中描述

如果你需要一个 getter ,你可以自己写一个,例如,作为一个隐藏实际调用echonoecho的类。

答案 1 :(得分:1)

我迟到了,但是curses有curses.wrapper设置“cbreak模式,关闭回声,启用终端键盘,如果终端有颜色支持则初始化颜色”然后运行你的功能。当您的函数返回时,它将恢复“熟化模式,打开回声,并禁用终端键盘”。当程序抛出异常时,它还可以正确地恢复终端。一个非常方便的功能。

https://docs.python.org/2/library/curses.html

相关问题