本文整理匯總了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