def cleanup(gui, poll, injector, ts, tests, command_line, args):
ts.run = False
if gui:
gui.stop()
if poll:
poll.stop()
if injector:
injector.stop()
'''
# doesn't work
if gui:
for (i, c) in enumerate(gui.orig_colors):
curses.init_color(i, c[0], c[1], c[2])
'''
curses.nocbreak();
curses.echo()
curses.endwin()
dump_artifacts(tests, injector, command_line)
if args.save:
with open(LAST, "w") as f:
f.write(hexlify(cstr2py(tests.r.raw_insn)))
sys.exit(0)
python类init_color()的实例源码
def init_colors(self):
if curses.has_colors() and curses.can_change_color():
curses.init_color(self.COLOR_BLACK, 0, 0, 0)
curses.init_color(self.COLOR_WHITE, 1000, 1000, 1000)
curses.init_color(self.COLOR_BLUE, 0, 0, 1000)
curses.init_color(self.COLOR_RED, 1000, 0, 0)
curses.init_color(self.COLOR_GREEN, 0, 1000, 0)
for i in xrange(0, self.GRAYS):
curses.init_color(
self.GRAY_BASE + i,
i * 1000 / (self.GRAYS - 1),
i * 1000 / (self.GRAYS - 1),
i * 1000 / (self.GRAYS - 1)
)
curses.init_pair(
self.GRAY_BASE + i,
self.GRAY_BASE + i,
self.COLOR_BLACK
)
else:
self.COLOR_BLACK = curses.COLOR_BLACK
self.COLOR_WHITE = curses.COLOR_WHITE
self.COLOR_BLUE = curses.COLOR_BLUE
self.COLOR_RED = curses.COLOR_RED
self.COLOR_GREEN = curses.COLOR_GREEN
for i in xrange(0, self.GRAYS):
curses.init_pair(
self.GRAY_BASE + i,
self.COLOR_WHITE,
self.COLOR_BLACK
)
curses.init_pair(self.BLACK, self.COLOR_BLACK, self.COLOR_BLACK)
curses.init_pair(self.WHITE, self.COLOR_WHITE, self.COLOR_BLACK)
curses.init_pair(self.BLUE, self.COLOR_BLUE, self.COLOR_BLACK)
curses.init_pair(self.RED, self.COLOR_RED, self.COLOR_BLACK)
curses.init_pair(self.GREEN, self.COLOR_GREEN, self.COLOR_BLACK)
def start(screen):
curses.noecho()
curses.cbreak()
screen.keypad(True)
curses.start_color()
curses.use_default_colors()
curses.curs_set(0)
if curses.can_change_color():
curses.init_color(COLOR_DARKBLACK, 0, 0, 0)
curses.init_color(COLOR_SUPERWHITE, 1000, 1000, 1000)
curses.init_pair(PAIR_ACTIVE_TAB, COLOR_SUPERWHITE, COLOR_DARKBLACK)
curses.init_pair(PAIR_TABBAR_BG, COLOR_DARKBLACK, COLOR_SUPERWHITE)
else:
curses.init_pair(PAIR_ACTIVE_TAB,
curses.COLOR_WHITE, curses.COLOR_BLACK)
curses.init_pair(PAIR_TABBAR_BG,
curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(PAIR_INACTIVE_TAB,
curses.COLOR_WHITE, curses.COLOR_BLACK)
curses.init_pair(PAIR_ACTIVE_ACCOUNT_SEL,
curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(PAIR_INACTIVE_ACCOUNT_SEL, curses.COLOR_WHITE, -1)
curses.init_pair(PAIR_POSITIVE_VALUE, curses.COLOR_GREEN, -1)
curses.init_pair(PAIR_NEGATIVE_VALUE, curses.COLOR_RED, -1)
websockets_path = "ws://localhost:8888"
async with api.WebSocket(websockets_path) as ws:
app = Application(screen, ws)
await app.start()
def set_colours(colours):
"""
Set curses colours.
Arguments:
colours: Dict with colour information.
"""
crs.start_color()
# Define colours.
if colours['background'] == 'default':
crs.use_default_colors()
background = -1
else:
crs.init_color(0, *hex_to_rgb(colours['background']))
background = 0
crs.init_color(1, *hex_to_rgb(colours['foreground']))
crs.init_color(2, *hex_to_rgb(colours['highlight']))
crs.init_color(3, *hex_to_rgb(colours['content1']))
crs.init_color(4, *hex_to_rgb(colours['content2']))
# Define colour pairs.
crs.init_pair(1, 1, background)
crs.init_pair(2, 2, background)
crs.init_pair(3, 3, background)
crs.init_pair(4, 4, background)
# Set colours.
crs.start_color()
common.w.main.bkgdset(' ', crs.color_pair(1))
common.w.inbar.bkgdset(' ', crs.color_pair(1))
common.w.infobar.bkgdset(' ', crs.color_pair(2))
common.w.outbar.bkgdset(' ', crs.color_pair(4))
common.w.refresh()
def init_colors(self):
if curses.has_colors() and curses.can_change_color():
curses.init_color(self.COLOR_BLACK, 0, 0, 0)
curses.init_color(self.COLOR_WHITE, 1000, 1000, 1000)
curses.init_color(self.COLOR_BLUE, 0, 0, 1000)
curses.init_color(self.COLOR_RED, 1000, 0, 0)
curses.init_color(self.COLOR_GREEN, 0, 1000, 0)
# this will remove flicker, but gives boring colors
'''
self.COLOR_BLACK = curses.COLOR_BLACK
self.COLOR_WHITE = curses.COLOR_WHITE
self.COLOR_BLUE = curses.COLOR_BLUE
self.COLOR_RED = curses.COLOR_RED
self.COLOR_GREEN = curses.COLOR_GREEN
'''
for i in xrange(0, self.GRAYS):
curses.init_color(
self.GRAY_BASE + i,
i * 1000 / (self.GRAYS - 1),
i * 1000 / (self.GRAYS - 1),
i * 1000 / (self.GRAYS - 1)
)
curses.init_pair(
self.GRAY_BASE + i,
self.GRAY_BASE + i,
self.COLOR_BLACK
)
else:
self.COLOR_BLACK = curses.COLOR_BLACK
self.COLOR_WHITE = curses.COLOR_WHITE
self.COLOR_BLUE = curses.COLOR_BLUE
self.COLOR_RED = curses.COLOR_RED
self.COLOR_GREEN = curses.COLOR_GREEN
for i in xrange(0, self.GRAYS):
curses.init_pair(
self.GRAY_BASE + i,
self.COLOR_WHITE,
self.COLOR_BLACK
)
curses.init_pair(self.BLACK, self.COLOR_BLACK, self.COLOR_BLACK)
curses.init_pair(self.WHITE, self.COLOR_WHITE, self.COLOR_BLACK)
curses.init_pair(self.BLUE, self.COLOR_BLUE, self.COLOR_BLACK)
curses.init_pair(self.RED, self.COLOR_RED, self.COLOR_BLACK)
curses.init_pair(self.GREEN, self.COLOR_GREEN, self.COLOR_BLACK)
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 = []