def __enter__(self):
# Default delay when pressing ESC is too long, at 1000ms
os.environ["ESCDELAY"] = "25"
self.pairs = Pairs()
# Make curses use unicode
locale.setlocale(locale.LC_ALL, "")
self.screen = curses.initscr()
curses.noecho()
# Using raw instead of cbreak() gives us access to CTRL+C and others
curses.raw()
self.screen.keypad(True)
if not self.blocking_events:
self.screen.timeout(33)
curses.start_color()
curses.use_default_colors()
self.hide_cursor()
return self
python类raw()的实例源码
def __init__(self, this_plant, this_data):
'''Initialization'''
self.initialized = False
self.screen = curses.initscr()
curses.noecho()
curses.raw()
curses.start_color()
try:
curses.curs_set(0)
except curses.error:
# Not all terminals support this functionality.
# When the error is ignored the screen will look a little uglier, but that's not terrible
# So in order to keep botany as accesible as possible to everyone, it should be safe to ignore the error.
pass
self.screen.keypad(1)
self.plant = this_plant
self.user_data = this_data
self.plant_string = self.plant.parse_plant()
self.plant_ticks = str(self.plant.ticks)
self.exit = False
self.infotoggle = 0
self.maxy, self.maxx = self.screen.getmaxyx()
# Highlighted and Normal line definitions
self.define_colors()
self.highlighted = curses.color_pair(1)
self.normal = curses.A_NORMAL
# Threaded screen update for live changes
screen_thread = threading.Thread(target=self.update_plant_live, args=())
screen_thread.daemon = True
screen_thread.start()
self.screen.clear()
self.show(["water","look","garden","instructions"], title=' botany ', subtitle='options')
def screen_curses_init():
#
# number of milliseconds to wait after reading an escape character, to
# distinguish between an individual escape character entered on the
# keyboard from escape sequences sent by cursor and function keys (see
# curses(3X).
os.putenv("ESCDELAY", "0") # was 25
#
global STDSCR
STDSCR = curses.initscr()
curses.noecho()
curses.cbreak()
#
if not curses.has_colors():
raise Exception("Need colour support to run.")
curses.raw()
#
curses.start_color()
#
# This is what allows us to use -1 for default when we initialise
# the pairs
curses.use_default_colors()
#
curses.init_pair(PROFILE_GREY , curses.COLOR_WHITE , -1)
curses.init_pair(PROFILE_WHITE , curses.COLOR_WHITE , -1)
curses.init_pair(PROFILE_RED , curses.COLOR_RED , -1)
curses.init_pair(PROFILE_VERMILION , curses.COLOR_RED , -1)
curses.init_pair(PROFILE_ORANGE , curses.COLOR_RED , -1)
curses.init_pair(PROFILE_AMBER , curses.COLOR_YELLOW , -1)
curses.init_pair(PROFILE_YELLOW , curses.COLOR_YELLOW , -1)
curses.init_pair(PROFILE_CHARTREUSE , curses.COLOR_GREEN , -1)
curses.init_pair(PROFILE_GREEN , curses.COLOR_GREEN , -1)
curses.init_pair(PROFILE_TEAL , curses.COLOR_CYAN , -1)
curses.init_pair(PROFILE_BLUE , curses.COLOR_BLUE , -1)
curses.init_pair(PROFILE_VIOLET , curses.COLOR_MAGENTA , -1)
curses.init_pair(PROFILE_PURPLE , curses.COLOR_MAGENTA , -1)
curses.init_pair(PROFILE_MAGENTA , curses.COLOR_MAGENTA , -1)
curses.init_pair(PROFILE_BLACK_INFO , curses.COLOR_BLACK , curses.COLOR_WHITE)
curses.init_pair(PROFILE_ALARM, curses.COLOR_RED , curses.COLOR_WHITE)
def interact(stdscr, broker):
curses.raw()
broker.interact()
def __init__(self, items, parent_window, which_menu="left"):
self.which_menu = which_menu
self.window = parent_window.derwin(1, 0)
self.window.keypad(1)
curses.noecho()
curses.raw()
self.position = 0
self.items = items
if self.which_menu == 'left':
nothing = namedtuple("Nothing", 'message, action_str', 'article', 'formatted')
nothing.message = "Nothing"
nothing.action_str = "Do"
nothing.article = ""
nothing.formatted = "Nothing"
self.items.insert(0, nothing)
self.detailwindow = None
code = locale.getpreferredencoding()
self.arrow_up = (3*'\u2191').encode(code)
self.arrow_down = (3*'\u2193').encode(code)
self.first_item_index = self.position
self.last_item_index = min(self.LIST_SIZE, len(self.items))
self.next_window = None
self.has_focus = False
self.item_message = '{1.action_str} {1.article} {1.message}'
def __init__(self, items, parent_window):
self.window = parent_window.derwin(1, 0)
self.window.keypad(1)
curses.noecho()
curses.raw()
self.position = 0
self.items = items
def __init__(self, cursesScreen):
self.clicks = 0
self.debugMouseEvent = (0, 0, 0, 0, 0)
self.exiting = False
self.modalUi = None
self.modeStack = []
self.priorClick = 0
self.savedMouseButton1Down = False
self.savedMouseWindow = None
self.savedMouseX = -1
self.savedMouseY = -1
self.cursesScreen = cursesScreen
self.ch = 0
curses.mousemask(-1)
curses.mouseinterval(0)
# Enable mouse tracking in xterm.
sys.stdout.write('\033[?1002;h\n')
#sys.stdout.write('\033[?1005;h\n')
curses.meta(1)
# Access ^c before shell does.
curses.raw()
# Enable Bracketed Paste Mode.
sys.stdout.write('\033[?2004;h\n')
#curses.start_color()
curses.use_default_colors()
if 0:
assert(curses.COLORS == 256)
assert(curses.can_change_color() == 1)
assert(curses.has_colors() == 1)
app.log.detail("color_content:")
for i in range(0, curses.COLORS):
app.log.detail("color", i, ": ", curses.color_content(i))
for i in range(16, curses.COLORS):
curses.init_color(i, 500, 500, i * 787 % 1000)
app.log.detail("color_content, after:")
for i in range(0, curses.COLORS):
app.log.detail("color", i, ": ", curses.color_content(i))
self.setUpPalette()
if 1:
#rows, cols = self.cursesScreen.getmaxyx()
cursesWindow = self.cursesScreen
cursesWindow.leaveok(1) # Don't update cursor position.
cursesWindow.scrollok(0)
cursesWindow.timeout(10)
cursesWindow.keypad(1)
self.top, self.left = cursesWindow.getyx()
self.rows, self.cols = cursesWindow.getmaxyx()
app.window.mainCursesWindow = cursesWindow
self.zOrder = []