我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用curses.start_color()。
def __init__(self, file): self.file = file self.scr = curses.initscr() self.scr.border() self.scr_height, self.scr_width = self.scr.getmaxyx() self.text_win = curses.newwin(self.scr_height - 1, self.scr_width, 1, 0) self.file_text = file.content if self.file_text != None: self.text_win.addstr(self.file_text) curses.noecho() #curses.start_color() #curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN) if self.file.exists: self.start_editor() else: curses.endwin() gc.error('An error occurred while editing this file.')
def __init__(self, username): os.environ.setdefault('ESCDELAY', '25') # shorten esc delay self.username = username # set up IRC self.channel = "##HTP" # set up curses self.scr = curses.initscr() self.disconnect = False curses.start_color() self.scr_height, self.scr_width = self.scr.getmaxyx() self.chatbar = curses.newwin(5, self.scr_height - 1, 5, 10) self.msg_text = '' self.logfile = '../data/irc.txt' self.log_text = [] # curses color config curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN) # start the client try: curses.wrapper(self.start_loop()) except Exception as e: self.scr.addstr(2, 0, str(e), curses.A_REVERSE) # client game loop
def colors_init(): """ Initializes all color pairs possible into the dictionary CURSES_COLORPAIRS. Thus, getting an attribute for a black foreground and a green background would look like: >>> curses_color.colors_init() >>> green_black_attr = curses_color.CURSES_COLORPAIRS['black-green'] >>> stdscr.addstr(0, 0, "test", curses.color_pair(green_black_attr)) """ if len(CURSES_COLORPAIRS): return assert curses.has_colors( ), "Curses wasn't configured to support colors. Call curses.start_color()" start_number = 120 for fg in BASE_CURSES_COLORS.keys(): for bg in BASE_CURSES_COLORS.keys(): pair_num = len(CURSES_COLORPAIRS) + start_number curses.init_pair(pair_num, BASE_CURSES_COLORS[fg], BASE_CURSES_COLORS[bg]) pair_name = "{}-{}".format(fg, bg) CURSES_COLORPAIRS[pair_name] = pair_num
def initcolors(): """ initialize color pallet """ curses.start_color() if not curses.has_colors(): raise RuntimeError("Sorry. Terminal does not support colors") # setup colors on black background for i in range(1,9): curses.init_pair(i,i,BLACK) CPS[i] = curses.color_pair(i) # have to individually set up special cases curses.init_pair(BUTTON,WHITE,GRAY) # white on gray for buttons CPS[BUTTON] = curses.color_pair(BUTTON) curses.init_pair(HLITE,BLACK,GREEN) # black on Green for highlight aps,stas CPS[HLITE] = curses.color_pair(HLITE) curses.init_pair(ERR,WHITE,RED) # white on red CPS[ERR] = curses.color_pair(ERR) curses.init_pair(WARN,BLACK,YELLOW) # white on yellow CPS[WARN] = curses.color_pair(WARN) curses.init_pair(NOTE,WHITE,GREEN) # white on red CPS[NOTE] = curses.color_pair(NOTE)
def __init__(self): self.selected_index_stack = [0] self.returnString = "" self.play_in_room = None self.dir = DirBrowse() self.selected_index = 0 self.selected_column = 0 self.window = curses.initscr() curses.start_color() curses.noecho() curses.cbreak() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_RED) curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLUE) self.window.keypad(1) self.draw_ui()
def __init__(self, hosts): self.stdscr = curses.initscr() curses.start_color() self.height, self.width = self.stdscr.getmaxyx() curses.cbreak() curses.noecho() self.stdscr.keypad(1) self.hosts = hosts self.format = ( '%(hostname)10.10s ' '%(pid)7.7s ' '%(ppid)7.7s ' '%(pcpu)6.6s ' '%(rss)5.5s ' '%(command)20s' )
def main(stdscr): curses.start_color() curses.use_default_colors() for i in range(0, curses.COLORS): curses.init_pair(i + 1, i, -1) try: for i in range(0, 255): stdscr.addstr(str(i), curses.color_pair(i)) stdscr.addstr(" ") except curses.ERR: # End of screen reached pass stdscr.getch()
def __init__(self): self._colors = { 'white': curses.color_pair(self.PAIRS['white']), 'black': curses.color_pair(self.PAIRS['white']) | curses.A_REVERSE, 'red': curses.color_pair(self.PAIRS['red']), 'blue': curses.color_pair(self.PAIRS['blue']), 'green': curses.color_pair(self.PAIRS['green']), 'green_reverse': (curses.color_pair(self.PAIRS['green']) | curses.A_REVERSE), 'cyan': curses.color_pair(self.PAIRS['cyan']), 'cyan_reverse': (curses.color_pair(self.PAIRS['cyan']) | curses.A_REVERSE), 'yellow': curses.color_pair(self.PAIRS['yellow']), 'yellow_reverse': (curses.color_pair(self.PAIRS['yellow']) | curses.A_REVERSE), 'magenta': curses.color_pair(self.PAIRS['magenta']), 'magenta_reverse': (curses.color_pair(self.PAIRS['magenta']) | curses.A_REVERSE), } curses.start_color() curses.use_default_colors() for definition, (color, background) in self.DEFINITION.items(): curses.init_pair(definition, color, background)
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
def __init__(self, enable=True): self.enable = enable if not self.enable: return self.logger = logging.getLogger('trader-logger') self.stdscr = curses.initscr() self.pad = curses.newpad(23, 120) self.order_pad = curses.newpad(10, 120) self.timestamp = "" self.last_order_update = 0 curses.start_color() curses.noecho() curses.cbreak() curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED) self.stdscr.keypad(1) self.pad.addstr(1, 0, "Waiting for a trade...")
def __init__(self, curses, curses_window): curses.start_color() curses.curs_set(0) curses_window.nodelay(1) curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_BLUE, curses.COLOR_BLACK) self._curses = curses self._curses_window = curses_window self._stack = list()
def setup(self): curses.start_color() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.cbreak() curses.echo() lines, cols = self.stdscr.getmaxyx() self.logwin = self.stdscr.subwin(lines - 2, cols, 0, 0) self.sepwin = self.stdscr.subwin(1, cols, lines - 2, 0) self.cmdwin = self.stdscr.subwin(1, cols, lines - 1, 0) self.logwin.scrollok(True) self.sepwin.bkgd(curses.color_pair(1)) self.sepwin.refresh()
def get_screen(self): self.screen = curses.initscr() curses.start_color() curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) if self.x == 0: starty, startx = self.screen.getmaxyx() self.x = startx self.y = starty resize = curses.is_term_resized(self.y, self.x) # Action in loop if resize is True: if resize is True: y, x = self.screen.getmaxyx() self.screen.clear() curses.resizeterm(self.y, self.x) self.screen.refresh() self.show_header() return self.screen
def _create_desktop(self): global _s_screen _s_screen = curses.initscr() curses.noecho() curses.curs_set(0) curses.start_color() self._desktop = Form(None, 0, 0) self._stats = Form(self._desktop, 0, 0, 70, 20) self._stats.set_centering(True, True) self._title = Label(self._stats, 0, 0, 'S2E') self._title.set_centering(True, False) self._exitmsg = Label(self._stats, 0, 17, 'Press q to exit') self._exitmsg.set_centering(True, False) self._table = Table(self._stats, 2, 2, self._data, self._legend, self._layout) self._table.set_centering(True, True)
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 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 = curses.initscr() # Turn off echoing of keys, and enter cbreak mode, # where no buffering is performed on keyboard input curses.noecho() curses.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: curses.start_color() except: pass return func(stdscr, *args, **kwds) finally: # Set everything back to normal if 'stdscr' in locals(): stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
def init_curses(self): """Setup the curses""" self.window = curses.initscr() self.window.keypad(True) curses.noecho() curses.cbreak() curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_CYAN) self.current = curses.color_pair(2)
def conf_scr(): '''Configure the screen and colors/etc''' curses.curs_set(0) curses.start_color() curses.use_default_colors() text, banner, banner_text, background = get_theme_colors() curses.init_pair(2, text, background) curses.init_pair(3, banner_text, banner) curses.halfdelay(10)
def init_colors(self): curses.start_color() curses.use_default_colors() colors = [ curses.COLOR_BLUE, curses.COLOR_CYAN, curses.COLOR_GREEN, curses.COLOR_MAGENTA, curses.COLOR_RED, curses.COLOR_WHITE, curses.COLOR_YELLOW ] curses.init_pair(0, curses.COLOR_WHITE, curses.COLOR_BLACK) for i, c in enumerate(colors): curses.init_pair(i + 1, c, curses.COLOR_BLACK)
def __init__(self, arena_size): self.arena_size = arena_size self.max_moves = int(25*(2*arena_size*COLORS)/(28*6)) self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() try: curses.curs_set(False) except curses.error: pass self.screen.nodelay(True) self.window_size = self.screen.getmaxyx() if self.window_size[0] < self.arena_size+4 or self.window_size[1] < self.arena_size*2: print('Your screen is too short!') exit() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_GREEN) curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_CYAN) curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_MAGENTA) curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_YELLOW) curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_WHITE) self.offset_x = int((self.window_size[1]-2*self.arena_size)/2) self.offset_y = int((self.window_size[0]-self.arena_size)/2) self.moves_position=[ self.offset_y+self.arena_size+1, self.offset_x+self.arena_size-5 ] self.arena_initialize() self.screen.addstr( self.offset_y-2, self.offset_x, self.title, curses.color_pair(0)) self.screen.addstr( self.offset_y-2, self.offset_x+2*self.arena_size-17, "Press '?' to help", curses.color_pair(0))
def __init__(self): self.notification_count = 0 self.window = curses.initscr() curses.start_color() curses.noecho() curses.cbreak() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLUE) self.window.keypad(1) self.draw_ui()
def __init__(self, ts, injector, tests, do_tick, disassembler=disas_capstone): self.ts = ts; self.injector = injector self.T = tests self.gui_thread = None self.do_tick = do_tick self.ticks = 0 self.last_ins_count = 0 self.delta_log = deque(maxlen=self.RATE_Q) self.time_log = deque(maxlen=self.RATE_Q) self.disas = disassembler self.stdscr = curses.initscr() curses.start_color() # doesn't work # self.orig_colors = [curses.color_content(x) for x in xrange(256)] curses.use_default_colors() curses.noecho() curses.cbreak() curses.curs_set(0) self.stdscr.nodelay(1) self.sx = 0 self.sy = 0 self.init_colors() self.stdscr.bkgd(curses.color_pair(self.WHITE)) self.last_time = time.time()
def start(self, no_delay): self.window = curses.initscr() curses.start_color() curses.use_default_colors() curses.noecho() curses.cbreak() curses.curs_set(0) self.window.nodelay(no_delay) self.init_colors() self.window.bkgd(curses.color_pair(self.WHITE)) locale.setlocale(locale.LC_ALL, '') # set your locale self.code = locale.getpreferredencoding()
def _inner_addstr(window, string, y=-1, x=-1): assert curses.has_colors(), "Curses wasn't configured to support colors. Call curses.start_color()" cur_y, cur_x = window.getyx() if y == -1: y = cur_y if x == -1: x = cur_x for line in string.split(os.linesep): _add_line(y, x, window, line) # next line y += 1
def __init__(self): """ Initialize a new TUI window in terminal. """ locale.setlocale(locale.LC_ALL, '') self._stdscr = curses.initscr() curses.start_color() curses.noecho() curses.cbreak() curses.curs_set(0) # Set colors curses.use_default_colors() for i, color in enumerate(self.colorpairs): curses.init_pair(i + 1, *color)
def run(self): ''' Runs all the windows added to the application, and returns a `Result` object. ''' result = Result() try: self.scr = curses.initscr() self.MAX_HEIGHT, self.MAX_WIDTH = self.scr.getmaxyx() curses.noecho() curses.cbreak() curses.start_color() curses.use_default_colors() self.window = self.scr.subwin(0, 0) self.window.keypad(1) self.window.nodelay(1) self._run_windows() self.threads += [gevent.spawn(self._input_loop)] gevent.joinall(self.threads) for thread in self.threads: if thread.exception: result._extract_thread_exception(thread) except KeyboardInterrupt: result._extract_exception() except Exception: result._extract_exception() finally: if self.scr is not None: self.scr.keypad(0) curses.echo() curses.nocbreak() curses.endwin() return result
def __init__(self, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, head): super().__init__() self.ticks = ticks self.silent = silent self.debug = debug self.compat_debug = compat_debug self.debug_lines = debug_lines self.autostep_debug = autostep_debug self.head = head self.tick_number = 0 self.output_count = 0 if self.debug and not self.compat_debug: self.logging_loc = 0 self.logging_x = 1 self.stdscr = curses.initscr() curses.start_color() curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.noecho() curses.curs_set(False) self.win_program = curses.newwin(self.debug_lines, curses.COLS - 1, 0, 0) self.logging_pad = curses.newpad(1000, curses.COLS - 1) def signal_handler(signal, frame): self.on_finish() sys.exit(0) signal.signal(signal.SIGINT, signal_handler)
def __init__(self): self.screen = curses.initscr() self.screen.timeout(100) # the screen refresh every 100ms # charactor break buffer curses.cbreak() self.screen.keypad(1) self.netease = NetEase() curses.start_color() if Config().get_item('curses_transparency'): curses.use_default_colors() curses.init_pair(1, curses.COLOR_GREEN, -1) curses.init_pair(2, curses.COLOR_CYAN, -1) curses.init_pair(3, curses.COLOR_RED, -1) curses.init_pair(4, curses.COLOR_YELLOW, -1) else: curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) # term resize handling size = terminalsize.get_terminal_size() self.x = max(size[0], 10) self.y = max(size[1], 25) self.startcol = int(float(self.x) / 5) self.indented_startcol = max(self.startcol - 3, 0) self.update_space() self.lyric = '' self.now_lyric = '' self.tlyric = '' self.storage = Storage() self.config = Config() self.newversion = False
def create_screen(fn): """ Initializes curses and passes a Screen to the main loop function `fn`. Based on curses.wrapper. """ try: # Make escape key more responsive os.environ['ESCDELAY'] = '25' stdscr = curses.initscr() curses.noecho() curses.cbreak() stdscr.keypad(1) stdscr.nodelay(1) curses.curs_set(0) curses.mousemask(curses.BUTTON1_CLICKED) if curses.has_colors(): curses.start_color() curses.use_default_colors() screen = Screen(stdscr) fn(screen) finally: # Set everything back to normal if 'stdscr' in locals(): curses.use_default_colors() curses.curs_set(1) stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin()
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 init_display(): """ Inits the display GUI """ if not GUI.gui_stopped: curses.noecho() curses.cbreak() curses.start_color() GUI.screen.keypad(1) curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN) GUI.high_light_text = curses.color_pair(1) GUI.normal_text = curses.A_NORMAL curses.curs_set(0) GUI.refresh_values() GUI.position = 1 GUI.page = 1 GUI.box = curses.newwin(GUI.max_row + 3, curses.COLS, 0, 0) GUI.box.addstr(1, 1, GUI.status, GUI.high_light_text) GUI.add_bottom_menus() GUI.screen.refresh() GUI.box.refresh()
def start_screen(self): self.screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(0) self.screen.keypad(True) curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_GREEN, -1) curses.init_pair(3, curses.COLOR_CYAN, -1) curses.init_pair(4, curses.COLOR_YELLOW, -1) return None
def _init_screen(self): screen = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE) screen.border(0) return screen
def print_stock_data(col, row, data, title, scr_main, scr_strip, cursor_row, change_amount, scr_dim): scr_strip.addstr(0, col+10, title) data_length = len(str(data)) spaces_length = 9 - data_length n = 0 if col+10+18 > scr_dim[1]: spaces_length = spaces_length + scr_dim[1] - col-10-9 while n < spaces_length: data = data + " " n = n + 1 curses.start_color() curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_RED) curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(10, curses.COLOR_BLACK, curses.COLOR_YELLOW) curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(13, curses.COLOR_YELLOW, curses.COLOR_BLACK) if cursor_row == 1: if change_amount == -1: scr_main.addstr(row, col, data, curses.color_pair(8)) elif change_amount == 1: scr_main.addstr(row, col, data, curses.color_pair(9)) else: scr_main.addstr(row, col, data, curses.color_pair(10)) else: if change_amount == -1: scr_main.addstr(row, col, data, curses.color_pair(11)) elif change_amount == 1: scr_main.addstr(row, col, data, curses.color_pair(12)) else: scr_main.addstr(row, col, data, curses.color_pair(13))
def input_n(cursor, scr_bottom, max_stock_range, stock_list, scr_dim): stock_input = None curses.start_color() curses.init_pair(5,curses.COLOR_WHITE,curses.COLOR_BLUE) stock_win = curses.newwin(1, 10, scr_dim[0]-1, 0) stock_win.bkgd(curses.color_pair(5)) stock_box = textpad.Textbox(stock_win) stock_win.refresh() scr_bottom.addstr(0, curses.COLS-20, " [Enter]Save/Exit") scr_bottom.refresh() stock_input = stock_box.edit() stock_input = stock_input.upper() if str(stock_input) != "" and str(stock_input) not in stock_list: stocks.add_stock_code(str(stock_input)) total_stocks = len(stock_list) + 1 if total_stocks > scr_dim[0] - 6: cursor[1] = total_stocks cursor[2] = max_stock_range else: cursor[1] = max_stock_range + 1 cursor[2] = cursor[1] elif str(stock_input) or ((str(stock_input)[0:(len(str(stock_input)) - 2)] and str(stock_input)[len(str(stock_input))])) in stock_list: total_stocks = len(stock_list) stock_pos = stock_list.index(str(stock_input)) + 1 cursor[1] = stock_pos if total_stocks > max_stock_range: cursor[2] = 1 else: cursor[2] = cursor[1] return cursor
def print_permanents(scr_top, perm, row, col, perm_data, scr_dim): if perm == "GC=F": perm = "Gold" elif perm == "SI=F": perm = "Silver" elif perm == "HG=F": perm = "Copper" elif perm == "CL=F": perm = "Crude" elif perm[-2:] == "=X": perm = perm[0:3] + "/" + perm[3:6] elif perm[0] == "^": perm = perm[1:] curses.start_color() curses.init_pair(20, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(21, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(22, curses.COLOR_RED, curses.COLOR_BLACK) try: printing_perm = str(perm) + "=" + str(perm_data["price"]) except: printing_perm = str(perm) + "=N/A" perm_length = len(printing_perm) + 1 if perm_length+col < scr_dim[1]: if perm_data["change"] != "N/A": if float(perm_data["change"]) >= 0.5: scr_top.addstr(1+row, col, str(printing_perm), curses.color_pair(20)) if float(perm_data["change"]) <= -0.5: scr_top.addstr(1+row, col, str(printing_perm), curses.color_pair(22)) else: scr_top.addstr(1+row, col, str(printing_perm), curses.color_pair(21)) else: scr_top.addstr(1+row, col, str(printing_perm)) return perm_length
def __init__(self): self.screen = curses.initscr() self.screen.timeout(100) # the screen refresh every 100ms # charactor break buffer curses.cbreak() self.screen.keypad(1) self.netease = NetEase() curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) # term resize handling size = terminalsize.get_terminal_size() self.x = max(size[0], 10) self.y = max(size[1], 25) self.startcol = int(float(self.x) / 5) self.indented_startcol = max(self.startcol - 3, 0) self.update_space() self.lyric = '' self.now_lyric = '' self.tlyric = '' self.storage = Storage() self.config = Config() self.newversion = False
def show(self): t = threading.Thread(target=self.get_data,args=()) t.setDaemon(True) t.start() try: mainwindow = curses.initscr() curses.cbreak(); mainwindow.keypad(1); curses.noecho() mainwindow.border(0) mainwindow.refresh() curses.start_color() curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN) (h,w)= mainwindow.getmaxyx() l1= mainwindow.subwin(8,w/2,0,0) l1.border(0) t1 = threading.Thread(target=self._showdata,args=(l1,)) t1.setDaemon(True) t1.start() t1.join() t.join() mainwindow.addstr(h/2,w/2-15,"RUN OVER,PLEASE ENTER!",curses.color_pair(1)) mainwindow.getch() finally: curses.nocbreak(); mainwindow.keypad(0); curses.echo() curses.endwin()
def setup_colours(self): curses.start_color() # 0 - NOT_WORKED curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_RED) # 1 - WORKED_COUNTRY_AND_STATION curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) # 2 - WORKED_COUNTRY_NOT_STATION curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK) # 3 - WORKED_COUNTRY_DIFF_BAND curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)
def defineColors(): curses.start_color() curses.use_default_colors() curses.init_pair(color.BLACK, curses.COLOR_BLACK, -1) curses.init_pair(color.GREY, 250, -1) curses.init_pair(color.RED, curses.COLOR_RED, -1) curses.init_pair(color.YELLOW, 143, -1) curses.init_pair(color.BLUE, curses.COLOR_BLUE, -1) # highlight text curses.init_pair(color.RED_H, curses.COLOR_RED, curses.COLOR_WHITE) curses.init_pair(color.YELLOW_H, curses.COLOR_YELLOW, curses.COLOR_WHITE)
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 _start(self): """ Initialize the screen and input mode. """ self.s = curses.initscr() self.has_color = curses.has_colors() if self.has_color: curses.start_color() if curses.COLORS < 8: # not colourful enough self.has_color = False if self.has_color: try: curses.use_default_colors() self.has_default_colors=True except _curses.error: self.has_default_colors=False self._setup_colour_pairs() curses.noecho() curses.meta(1) curses.halfdelay(10) # use set_input_timeouts to adjust self.s.keypad(0) if not self._signal_keys_set: self._old_signal_keys = self.tty_signal_keys() super(Screen, self)._start()
def run(self): """ """ self.setup() # Clear screen self.screen.clear() # curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLACK) while True: # session.expire_all() # TODO: Add some standard header to the top? (like interval time etc) # self.render() # self.increment.reset() # self.screen.refresh() # time.sleep(self.interval) self.running += self.interval return
def __init__(self,win): self.win = win self.size = self.win.getmaxyx() curses.start_color() curses.use_default_colors() self.win.nodelay(1) for i in range(0, curses.COLORS): curses.init_pair(i + 1, i, -1) curses.curs_set(0)