本文整理汇总了Python中_curses.initscr方法的典型用法代码示例。如果您正苦于以下问题:Python _curses.initscr方法的具体用法?Python _curses.initscr怎么用?Python _curses.initscr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_curses
的用法示例。
在下文中一共展示了_curses.initscr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initscr
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import initscr [as 别名]
def initscr():
import _curses, curses
# we call setupterm() here because it raises an error
# instead of calling exit() in error cases.
setupterm(term=_os.environ.get("TERM", "unknown"),
fd=_sys.__stdout__.fileno())
stdscr = _curses.initscr()
for key, value in _curses.__dict__.items():
if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
setattr(curses, key, value)
return stdscr
# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called.
示例2: wrapper
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import initscr [as 别名]
def wrapper(func, *args, **kwds):
"""Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
as its first argument, followed by any other arguments passed to
wrapper().
"""
try:
# Initialize curses
stdscr = initscr()
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
noecho()
cbreak()
# In keypad mode, escape sequences for special keys
# (like the cursor keys) will be interpreted and
# a special value like curses.KEY_LEFT will be returned
stdscr.keypad(1)
# Start color, too. Harmless if the terminal doesn't have
# color; user can test with has_color() later on. The try/catch
# works around a minor bit of over-conscientiousness in the curses
# module -- the error return from C start_color() is ignorable.
try:
start_color()
except:
pass
return func(stdscr, *args, **kwds)
finally:
# Set everything back to normal
if 'stdscr' in locals():
stdscr.keypad(0)
echo()
nocbreak()
endwin()
示例3: test0_curses
# 需要导入模块: import _curses [as 别名]
# 或者: from _curses import initscr [as 别名]
def test0_curses(): # {{{2
import os
if not os.environ.get("TERM", ""):
os.environ["TERM"] = "vt100"
os.environ["TERMINFO"] = ("/data/data/com.googlecode.pythonforandroid"
"/files/python/share/terminfo")
try:
import _curses
except:
return False
_curses.initscr()
_curses.endwin()
return True