我们从Python开源项目中,提取了以下47个代码示例,用于说明如何使用curses.COLOR_BLACK。
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 __init__(self, stdscreen): curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) global screen screen = stdscreen self.screen = stdscreen curses.curs_set(0) main_menu_items = get_records() main_menu_items += [{'field': 'Insert new station information record', 'function': selection_main_menu}] main_menu = Menu(cnn, main_menu_items, self.screen, 'Station information new/edit/delete - %s.%s' % (stn['NetworkCode'], stn['StationCode'])) main_menu.display()
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 _add_line(y, x, window, line): # split but \033 which stands for a color change color_split = line.split('\033') # Print the first part of the line without color change default_color_pair = _get_color(curses.COLOR_WHITE, curses.COLOR_BLACK) window.addstr(y, x, color_split[0], curses.color_pair(default_color_pair)) x += len(color_split[0]) # Iterate over the rest of the line-parts and print them with their colors for substring in color_split[1:]: color_str = substring.split('m')[0] substring = substring[len(color_str)+1:] color_pair = _color_str_to_color_pair(color_str) window.addstr(y, x, substring, curses.color_pair(color_pair)) x += len(substring)
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 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 _setup_colour_pairs(self): """ Initialize all 63 color pairs based on the term: bg * 8 + 7 - fg So to get a color, we just need to use that term and get the right color pair number. """ if not self.has_color: return for fg in xrange(8): for bg in xrange(8): # leave out white on black if fg == curses.COLOR_WHITE and \ bg == curses.COLOR_BLACK: continue curses.init_pair(bg * 8 + 7 - fg, fg, bg)
def processmenu(screen, menu, parent=None, status_bottom = 'Uninitialized...'): curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_WHITE) curses.curs_set(0) status_mid = '' optioncount = len(menu['options']) exitmenu = False # response = None while not exitmenu: #Loop until the user exits the menu getin = runmenu(screen, menu, parent, status_mid, status_bottom) if getin == optioncount: exitmenu = True elif menu['options'][getin]['type'] == COMMAND: screen.clear() #clears previous screen status_mid, status_bottom = processrequest(menu['options'][getin], screen) # Add additional space ## Show the updated status screen.clear() #clears previous screen on key press and updates display based on pos elif menu['options'][getin]['type'] == MENU: screen.clear() #clears previous screen on key press and updates display based on pos processmenu(screen, menu['options'][getin], menu, status_bottom) # display the submenu, and make sure the status is persistent screen.clear() #clears previous screen on key press and updates display based on pos elif menu['options'][getin]['type'] == EXITMENU: exitmenu = True
def define_colors(self): # set curses color pairs manually curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(8, curses.COLOR_CYAN, curses.COLOR_BLACK)
def set_color_pairs(): # based on the colors of pyradio curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLUE, 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_WHITE, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_MAGENTA) curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(8, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_GREEN)
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 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): 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_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 __init__(self, foreground=curses.COLOR_BLACK, background=curses.COLOR_WHITE): self.index = Color.next_index() self.set(foreground, background)
def _color_str_to_color_pair(color): if color == TerminalColors.END: fg = curses.COLOR_WHITE else: fg = TERMINAL_COLOR_TO_CURSES[color] color_pair = _get_color(fg, curses.COLOR_BLACK) return color_pair
def __init__( self, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ): self.win = curses.newwin( height, width, y, x ) self.dimensions = ( x, y, width, height ) """ if curses.has_colors(): color = 1 curses.init_pair( color, fg, bg ) self.win.bkgdset( ord(' '), curses.color_pair(color) ) else: self.win.bkgdset( ord(' '), curses.A_BOLD ) """ self.erase() self.setScrolling() self.win.noutrefresh()
def __init__( self, title, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ): NCursesUI.Window.__init__( self, x+1, y+3, width-2, height-4, fg, bg ) self.decoration = NCursesUI.Window( x, y, width, height, fg, bg ) self.decoration.setBoxed() self.decoration.win.hline( 2, 1, curses.ACS_HLINE, width-2 ) self.setTitle( title )
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 mkpanel(color, rows, cols, tly, tlx): win = curses.newwin(rows, cols, tly, tlx) pan = panel.new_panel(win) if curses.has_colors(): if color == curses.COLOR_BLUE: fg = curses.COLOR_WHITE else: fg = curses.COLOR_BLACK bg = color curses.init_pair(color, fg, bg) win.bkgdset(ord(' '), curses.color_pair(color)) else: win.bkgdset(ord(' '), curses.A_BOLD) return pan
def setup_colors(): """Setup the colors for each player. Entry 8 is reserved for zero-strength unowned squares. """ curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE) curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_MAGENTA) curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_CYAN) curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW) curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK)
def init_colors(): """ Init the colors for the screen """ curses.use_default_colors() # Colors we use for messages, etc curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_WHITE) colors['white'] = curses.color_pair(1) colors['green'] = curses.color_pair(2) colors['cyan'] = curses.color_pair(3) colors['yellow'] = curses.color_pair(4) colors['green-black'] = curses.color_pair(5) colors['black-white'] = curses.color_pair(6) colors['red'] = curses.color_pair(7) colors['white-white'] = curses.color_pair(8) # Allocate colour ranges here for the ma display. maprange = 10 for i in range(curses.COLORS - maprange): curses.init_pair(i + maprange, 0, i)
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 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 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 parse_args(): parser = argparse.ArgumentParser() # parser.add_argument('-a', '--abs', action='store_true') parser.add_argument('abs_rel', choices=['at', 'after']) font_choices = [font.split('.')[0] for font in os.listdir('/usr/share/figlet') if font.split('.')[1] == 'tlf'] parser.add_argument('-f', '--font', default=DEFAULT_FONT, choices=font_choices) parser.add_argument('-m', '--msg', default=None) # parser.add_argument('-z', '--snooze', type=float, default=2) parser_volume = parser.add_mutually_exclusive_group() parser_song = parser_volume.add_argument_group() parser_song.add_argument('-d', '--dir', default=DEFAULT_MUSIC_DIR) parser_song.add_argument('--song', default=DEFAULT_SONG) parser_volume.add_argument('-ns', '--silent', action='store_true') parser.add_argument('-fg', choices=['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'], default='white') parser.add_argument('-bg', choices=['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'], default='black') parser.add_argument('time', nargs='+') args = parser.parse_args() args.abs = False if args.abs_rel == 'after' else True if not args.silent: args.song = validate_song(args) args.time = ' '.join(args.time) color_mapping = { 'black': curses.COLOR_BLACK, 'red': curses.COLOR_RED, 'green': curses.COLOR_GREEN, 'yellow': curses.COLOR_YELLOW, 'blue': curses.COLOR_BLUE, 'magenta': curses.COLOR_MAGENTA, 'cyan': curses.COLOR_CYAN, 'white': curses.COLOR_WHITE, } args.fg = color_mapping[args.fg] args.bg = color_mapping[args.bg] return args
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 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 setup_palette(): curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
def getStats(scr): curses.init_pair(9, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK) curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK) (maxY, maxX) = scr.getmaxyx() while 1: try: display_time(scr) display_loadavg(scr) display_header(scr) #write(scr, 3, 0, '%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD) cnt = 5 try: for i in os.listdir(DISTCC_DIR+'/state'): data = struct.unpack('@iLL128s128siiP', open(DISTCC_DIR+'/state/'+i).readline().strip()) file = data[3].split('\x00')[0] or 'None' host = data[4].split('\x00')[0] or 'None' slot = int(data[5]) stte = states[int(data[6])] scr.move(cnt,0) scr.clrtoeol() if 'None' not in (file, host): write(scr, cnt, 0, '%s' % slot, curses.color_pair(9)) write(scr, cnt, 5, '%s' % host, curses.color_pair(9)) if int(data[6]) in (2,3): write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(10)) elif int(data[6]) in (0,1): write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(11)) elif int(data[6]) in (4,5): write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(12)) elif int(data[6]) in (6,7): write(scr, cnt, 25, '%s ' % (stte), curses.color_pair(12)|curses.A_BOLD) else: write(scr, cnt, 25, '%s ' % (stte)) write(scr, cnt, 45, '%s' % file, curses.color_pair(9)) cnt += 1 except struct.error: pass except IOError: pass scr.refresh() time.sleep(0.75) scr.erase() scr.move(0,0) except KeyboardInterrupt: sys.exit(-1)
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 main(): steps = 0 scr = curses.initscr() scr.nodelay(1) curses.curs_set(0) curses.noecho() if USE_COLORS: curses.start_color() curses.use_default_colors() curses.init_pair(COLOR_CHAR_NORMAL, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(COLOR_CHAR_HIGHLIGHT, curses.COLOR_WHITE, curses.COLOR_GREEN) curses.init_pair(COLOR_WINDOW, curses.COLOR_GREEN, curses.COLOR_GREEN) height, width = scr.getmaxyx() window_animation = None lines = [] for i in range(DROPPING_CHARS): l = FallingChar(width, MIN_SPEED, MAX_SPEED) l.y = randint(0, height-2) lines.append(l) scr.refresh() while True: height, width = scr.getmaxyx() for line in lines: line.tick(scr, steps) for i in range(RANDOM_CLEANUP): x = randint(0, width-1) y = randint(0, height-1) scr.addstr(y, x, ' ') if randint(0, WINDOW_CHANCE) == 1: if window_animation is None: #start window animation line = random.choice(lines) window_animation = WindowAnimation(line.x, line.y) if not window_animation is None: still_active = window_animation.tick(scr, steps) if not still_active: window_animation = None scr.refresh() time.sleep(SLEEP_MILLIS) if SCREENSAVER_MODE: key_pressed = scr.getch() != -1 if key_pressed: raise KeyboardInterrupt() steps += 1
def main(): """ The entry point for the app. Called when music-scraper is typed in terminal. Starts the GUI and starts the scraping process after the input is given """ curses.initscr() if curses.COLS < 80 or curses.LINES < 5: curses.endwin() print('Terminal\'s dimensions are too small') return process = CrawlerProcess({'LOG_ENABLED': False}) def gui_input(screen): GUI.screen = screen 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 GUI.box = curses.newwin(curses.LINES, curses.COLS, 0, 0) GUI.message = GUI.get_input() curses.wrapper(gui_input) s = request.quote(GUI.message) MusicSpider.start_urls = [ "http://www.google.com/search?q=" + s, ] process.crawl(MusicSpider) thread = GUIThread(process, start_gui) thread.start() process.start() if not GUI.gui_stopped: if len(GUI.strings) == 0: GUI.box.erase() GUI.box.addstr(1, 1, "No Results Found... Try with Some other keywords.", GUI.high_light_text) GUI.add_bottom_menus() GUI.screen.refresh() GUI.box.refresh() else: GUI.box.addstr(curses.LINES - 2, 1, "Completed Scraping !!", GUI.high_light_text) GUI.add_bottom_menus() GUI.screen.refresh() GUI.box.refresh()
def draw(self,screen): help_string1 = '(W)Up (S)Down (A)Left (D)Right' help_string2 = ' (R)Restart (Q)Exit' gameover_string = ' GAME OVER' win_string = ' YOU WIN!' def cast(string): screen.addstr(string + "\n") def cast_pawn(string): curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_WHITE) curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_WHITE) word_list = string.split() for element in word_list: if element in "0123456789": if int(element) == 2: screen.addstr(element,curses.color_pair(1)) elif int(element) == 4: screen.addstr(element,curses.color_pair(2)) elif int(element) == 8: screen.addstr(element,curses.color_pair(3)) else: screen.addstr(element,curses.color_pair(4)) else: screen.addstr(element) screen.addstr("\n") def draw_hor_separator(): line = "+" + ("+------" * self.width + "+")[1:] separator = defaultdict(lambda:line) if not hasattr(draw_hor_separator,"counter"): draw_hor_separator.counter = 0 cast(separator[draw_hor_separator.counter]) draw_hor_separator.counter += 1 def draw_row(row): cast_pawn(''.join('|{: ^5} '.format(num) if num > 0 else '| ' for num in row) + '|') screen.clear() cast("SCORE: " + str(self.score)) if 0 != self.high_score: cast("HIGH SCORE " + str(self.high_score)) for row in self.field: draw_hor_separator() draw_row(row) draw_hor_separator() if self.is_win(): cast(win_string) else: if self.is_gameover(): cast(gameover_string) else: cast(help_string1) cast(help_string2)
def main(stdscr): config_file = args.config_file if args.config_file is not None else 'zmqchat.cfg' config = configparser.ConfigParser() config.read(config_file) config = config['default'] receiver = zmq.Context().instance().socket(zmq.PAIR) receiver.bind("inproc://clientchat") sender = zmq.Context().instance().socket(zmq.PAIR) sender.connect("inproc://clientchat") client = ClientChat(args.username, config['server_host'], config['chat_port'], receiver) client.run() display_receiver = zmq.Context().instance().socket(zmq.PAIR) display_receiver.bind("inproc://clientdisplay") display_sender = zmq.Context().instance().socket(zmq.PAIR) display_sender.connect("inproc://clientdisplay") display = ClientDisplay(config['server_host'], config['display_port'], display_sender) display.run() ### curses set up curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) # ensure that user input is echoed to the screen curses.echo() curses.curs_set(0) window_height = curses.LINES window_width = curses.COLS division_line = int(window_height * 0.8) # instaniate two pads - one for displaying received messages # and one for showing the message the user is about to send off top_pad = stdscr.subpad(division_line, window_width, 0, 0) bottom_pad = stdscr.subpad(window_height - division_line, window_width, division_line, 0) top_thread = threading.Thread(target=start_top_window, args=(top_pad, display_receiver)) top_thread.daemon = True top_thread.start() bottom_thread = threading.Thread(target=start_bottom_window, args=(bottom_pad, sender)) bottom_thread.daemon = True bottom_thread.start() top_thread.join() bottom_thread.join()
def init_ui(): check_size() begin_x = 1 begin_y = 1 height = 40 width = 160 left_win_width = 28 middle_win_width = 80 right_win_width = width - left_win_width - middle_win_width - 4 win = newwin(height, width, begin_y, begin_x) win.border(0, 0, 0, 0, 0, 0, 0, 0) win.addstr("So You Have an Idea") win.refresh() left_win = win.subwin(height-5, left_win_width, 2, 2) left_win.border(0, 0, 0, 0, 0, 0, 0, 0) left_win.refresh() left_win = left_win.derwin(height-7, left_win_width-2, 1, 1) middle_win = win.subwin(height-5, middle_win_width, 2, left_win_width+2) middle_win.border(0, 0, 0, 0, 0, 0, 0, 0) for x in range(6, 20, 2): middle_win.addstr(x, middle_win_width-1, ">") middle_win.refresh() middle_win = middle_win.derwin(height-7, middle_win_width-2, 1, 1) right_win = win.subwin(height-5, right_win_width, 2, left_win_width + middle_win_width + 2) right_win.border(0, 0, 0, 0, 0, 0, 0, 0) for x in range(7, 21, 2): right_win.addstr(x, 0, "<") right_win.refresh() right_win = right_win.derwin(height-7, right_win_width-2, 1, 1) bottom_win = win.subwin(3, width-4, height-3, 2) bottom_win.border(0, 0, 0, 0, 0, 0, 0, 0) bottom_win.refresh() bottom_win = bottom_win.derwin(1, 114, 1, 1) left_win.refresh() middle_win.refresh() right_win.refresh() bottom_win.refresh() 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_BLUE, curses.COLOR_BLACK) curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) return left_win, middle_win, right_win, bottom_win, win
def __init__(self, env, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, output_limit): """ :param dots.environment.Env env: The env of the interpreter :param int ticks: The max number of ticks for the program :param bool silent: True to turn off all outputs :param bool debug: True to show the execution of the program :param bool compat_debug: True to show the debug with only builtin functions :param int debug_lines: The number of lines to show the debug :param float autostep_debug: The timebetween automatic ticks. 0 disables the auto ticks. :param int output_limit: The max number of outputs for the program """ super().__init__(env) # if it is zero or false, we don't want to stop self.ticks_left = ticks or float('inf') self.outputs_left = output_limit or float('inf') self.silent = silent self.debug = debug self.compat_debug = compat_debug self.debug_lines = debug_lines self.debug_cols = terminalsize.get_terminal_size()[0] - 1 self.autostep_debug = autostep_debug self.compat_logging_buffer = '' self.compat_logging_buffer_lines = terminal_lines - debug_lines - 1 self.first_tick = True 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() # hides the cursor curses.curs_set(False) # defining the two main parts of the screen: the view of the program self.win_program = curses.newwin(self.debug_lines, curses.COLS, 0, 0) # and pad for the output of the prog 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)