def palette(fg, bg=-1): """ Since curses only supports a finite amount of initialised colour pairs we memoise any selections you've made as an attribute on this function """ if not hasattr(palette, "counter"): palette.counter = 1 if not hasattr(palette, "selections"): palette.selections = {} selection = "%s%s" % (str(fg), str(bg)) if not selection in palette.selections: palette.selections[selection] = palette.counter palette.counter += 1 # Get available colours colors = [c for c in dir(_curses) if c.startswith('COLOR')] if isinstance(fg, str): if not "COLOR_"+fg.upper() in colors: fg = -1 else: fg = getattr(_curses, "COLOR_"+fg.upper()) if isinstance(bg, str): if not "COLOR_"+bg.upper() in colors: bg = -1 else: bg = getattr(_curses, "COLOR_"+bg.upper()) _curses.init_pair(palette.selections[selection], fg, bg) return _curses.color_pair(palette.selections[selection])
def add_messages(self): window = self.output_window max_y, max_x = self.max while True: msg = self.output.sync_q.get() self.output.sync_q.task_done() if msg is None: break (nickname, message, color_pair_code, is_info) = msg window.scroll() if is_info: window.addstr(max_y - 6, 0, message) else: window.addstr(max_y - 6, 0, nickname + " : " + message, color_pair(color_pair_code)) window.refresh()
_curses.init_pair(4, 4, 0) screen.clear for i in range(size + width + 1): b.append(0) while 1: for i in range(int(width / 9)): b[int((random.random() * width) + width * (height - 1))] = 65 for i in range(size): b[i] = int((b[i] + b[i + 1] + b[i + width] + b[i + width + 1]) / 4) color = (4 if b[i] > 15 else (3 if b[i] > 9 else (2 if b[i] > 4 else 1))) if (i < size - 1): screen.addstr(int(i / width), i % width, char[(9 if b[i] > 9 else b[i])], _curses.color_pair(color) | _curses.A_BOLD) screen.refresh() screen.timeout(30) if (screen.getch() != -1): break _curses.endwin()
def print_line_at(cls, row, col, text, colour: int): # writes a line of text at the specified row and column cls.__screen.addstr(row, col, text, _curses.color_pair(colour))