Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 import curses
00033
00034 class Bag:
00035 pass
00036
00037 class CursesApp:
00038 def init_curses(self):
00039 self.colors = Bag()
00040 try:
00041 self.stdscr = curses.initscr()
00042 curses.start_color()
00043 curses.use_default_colors()
00044 curses.init_pair(1, curses.COLOR_GREEN, -1)
00045 self.colors.green = curses.color_pair(1)
00046 curses.init_pair(2, curses.COLOR_YELLOW, -1)
00047 self.colors.yellow = curses.color_pair(2)
00048 curses.init_pair(3, curses.COLOR_RED, -1)
00049 self.colors.red = curses.color_pair(3)
00050 curses.init_pair(4, curses.COLOR_BLUE, -1)
00051 self.colors.blue = curses.color_pair(4)
00052 curses.init_pair(5, curses.COLOR_BLACK, -1)
00053 self.colors.black = curses.color_pair(5)
00054 curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_WHITE)
00055 self.colors.black_on_white = curses.color_pair(6)
00056 curses.init_pair(7, curses.COLOR_WHITE, -1)
00057 self.colors.white = curses.color_pair(7)
00058 curses.init_pair(8, curses.COLOR_CYAN, -1)
00059 self.colors.cyan = curses.color_pair(8)
00060 curses.noecho()
00061 curses.cbreak()
00062 curses.curs_set(0)
00063 self.stdscr.nodelay(True)
00064 self.stdscr.clear()
00065 self.stdscr.keypad(True)
00066 except curses.error:
00067 pass
00068
00069 def restore_screen(self):
00070 curses.curs_set(1)
00071 curses.nocbreak()
00072 curses.echo()
00073 curses.endwin()
00074
00075
00076 def curses_msg(self, msg, line=25):
00077 try:
00078 self.stdscr.addstr(line, 0, " "*80)
00079 self.stdscr.addstr(line, 0, msg)
00080 self.stdscr.refresh()
00081 except curses.error:
00082 pass
00083
00084 def add_field(self, label, text, row=None, col=None, label_color=None):
00085 if label_color is None:
00086 label_color = self.colors.cyan
00087 if row is None and col is None:
00088 self.stdscr.addstr(label, label_color)
00089 else:
00090 self.stdscr.addstr(row, col, label, label_color)
00091 self.stdscr.addstr(text)
00092 self.stdscr.clrtoeol()