Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../curses
File: __init__.py
"""curses
[0] Fix | Delete
[1] Fix | Delete
The main package for curses support for Python. Normally used by importing
[2] Fix | Delete
the package, and perhaps a particular module inside it.
[3] Fix | Delete
[4] Fix | Delete
import curses
[5] Fix | Delete
from curses import textpad
[6] Fix | Delete
curses.initscr()
[7] Fix | Delete
...
[8] Fix | Delete
[9] Fix | Delete
"""
[10] Fix | Delete
[11] Fix | Delete
from _curses import *
[12] Fix | Delete
import os as _os
[13] Fix | Delete
import sys as _sys
[14] Fix | Delete
[15] Fix | Delete
# Some constants, most notably the ACS_* ones, are only added to the C
[16] Fix | Delete
# _curses module's dictionary after initscr() is called. (Some
[17] Fix | Delete
# versions of SGI's curses don't define values for those constants
[18] Fix | Delete
# until initscr() has been called.) This wrapper function calls the
[19] Fix | Delete
# underlying C initscr(), and then copies the constants from the
[20] Fix | Delete
# _curses module to the curses package's dictionary. Don't do 'from
[21] Fix | Delete
# curses import *' if you'll be needing the ACS_* constants.
[22] Fix | Delete
[23] Fix | Delete
def initscr():
[24] Fix | Delete
import _curses, curses
[25] Fix | Delete
# we call setupterm() here because it raises an error
[26] Fix | Delete
# instead of calling exit() in error cases.
[27] Fix | Delete
setupterm(term=_os.environ.get("TERM", "unknown"),
[28] Fix | Delete
fd=_sys.__stdout__.fileno())
[29] Fix | Delete
stdscr = _curses.initscr()
[30] Fix | Delete
for key, value in _curses.__dict__.items():
[31] Fix | Delete
if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
[32] Fix | Delete
setattr(curses, key, value)
[33] Fix | Delete
[34] Fix | Delete
return stdscr
[35] Fix | Delete
[36] Fix | Delete
# This is a similar wrapper for start_color(), which adds the COLORS and
[37] Fix | Delete
# COLOR_PAIRS variables which are only available after start_color() is
[38] Fix | Delete
# called.
[39] Fix | Delete
[40] Fix | Delete
def start_color():
[41] Fix | Delete
import _curses, curses
[42] Fix | Delete
retval = _curses.start_color()
[43] Fix | Delete
if hasattr(_curses, 'COLORS'):
[44] Fix | Delete
curses.COLORS = _curses.COLORS
[45] Fix | Delete
if hasattr(_curses, 'COLOR_PAIRS'):
[46] Fix | Delete
curses.COLOR_PAIRS = _curses.COLOR_PAIRS
[47] Fix | Delete
return retval
[48] Fix | Delete
[49] Fix | Delete
# Import Python has_key() implementation if _curses doesn't contain has_key()
[50] Fix | Delete
[51] Fix | Delete
try:
[52] Fix | Delete
has_key
[53] Fix | Delete
except NameError:
[54] Fix | Delete
from .has_key import has_key
[55] Fix | Delete
[56] Fix | Delete
# Wrapper for the entire curses-based application. Runs a function which
[57] Fix | Delete
# should be the rest of your curses-based application. If the application
[58] Fix | Delete
# raises an exception, wrapper() will restore the terminal to a sane state so
[59] Fix | Delete
# you can read the resulting traceback.
[60] Fix | Delete
[61] Fix | Delete
def wrapper(func, *args, **kwds):
[62] Fix | Delete
"""Wrapper function that initializes curses and calls another function,
[63] Fix | Delete
restoring normal keyboard/screen behavior on error.
[64] Fix | Delete
The callable object 'func' is then passed the main window 'stdscr'
[65] Fix | Delete
as its first argument, followed by any other arguments passed to
[66] Fix | Delete
wrapper().
[67] Fix | Delete
"""
[68] Fix | Delete
[69] Fix | Delete
try:
[70] Fix | Delete
# Initialize curses
[71] Fix | Delete
stdscr = initscr()
[72] Fix | Delete
[73] Fix | Delete
# Turn off echoing of keys, and enter cbreak mode,
[74] Fix | Delete
# where no buffering is performed on keyboard input
[75] Fix | Delete
noecho()
[76] Fix | Delete
cbreak()
[77] Fix | Delete
[78] Fix | Delete
# In keypad mode, escape sequences for special keys
[79] Fix | Delete
# (like the cursor keys) will be interpreted and
[80] Fix | Delete
# a special value like curses.KEY_LEFT will be returned
[81] Fix | Delete
stdscr.keypad(1)
[82] Fix | Delete
[83] Fix | Delete
# Start color, too. Harmless if the terminal doesn't have
[84] Fix | Delete
# color; user can test with has_color() later on. The try/catch
[85] Fix | Delete
# works around a minor bit of over-conscientiousness in the curses
[86] Fix | Delete
# module -- the error return from C start_color() is ignorable.
[87] Fix | Delete
try:
[88] Fix | Delete
start_color()
[89] Fix | Delete
except:
[90] Fix | Delete
pass
[91] Fix | Delete
[92] Fix | Delete
return func(stdscr, *args, **kwds)
[93] Fix | Delete
finally:
[94] Fix | Delete
# Set everything back to normal
[95] Fix | Delete
if 'stdscr' in locals():
[96] Fix | Delete
stdscr.keypad(0)
[97] Fix | Delete
echo()
[98] Fix | Delete
nocbreak()
[99] Fix | Delete
endwin()
[100] Fix | Delete
[101] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function