Python curses 模块,curs_set() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用curses.curs_set()

项目:captiv8    作者:wraith-wireless    | 项目源码 | 文件源码
def setup():
    """
     sets environment up and creates main window
     :returns: the main window object
    """
    # setup the console
    mmask = curses.ALL_MOUSE_EVENTS # for now accept all mouse events
    main = curses.initscr()         # get a window object
    y,x = main.getmaxyx()           # get size
    if y < 24 or x < 80:            # verify minimum size rqmts
        raise RuntimeError("Terminal must be at least 80 x 24")
    curses.noecho()                 # turn off key echoing
    curses.cbreak()                 # turn off key buffering
    curses.mousemask(mmask)         # accept mouse events
    initcolors()                    # turn on and set color pallet
    main.keypad(1)                  # let curses handle multibyte special keys
    main.clear()                    # erase everything
    banner(main)                    # write the banner
    mainmenu(main)                  # then the min and menu
    main.attron(CPS[RED])           # make the border red
    main.border(0)                  # place the border
    main.attroff(CPS[RED])          # turn off the red
    curses.curs_set(0)              # hide the cursor
    main.refresh()                  # and show everything
    return main
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def refresh(self):
        prior, (cursr_y, cursr_x) = curses.curs_set(0), curses.getsyx()
        for idx, item in enumerate(self.items):
            fmt = '{{: <{}}}'.format(self.width-1)
            s = fmt.format(str(item))[:self.width-1]
            # s = str(item)[:self.width-1] if len(str(item)) > self.width-1 else str(item)
            color = colors.get_colorpair(self.default_color)
            if self.current == idx:
                if self.is_selected:
                    color = colors.get_colorpair('black-white')
                else:
                    color = colors.get_colorpair(self.highlight_color)
            self.textinpt.addstr(idx, 0, s, color)
        if self.is_selected:
            self.borderbox.bkgd(' ', curses.A_BOLD)
        else:
            self.borderbox.bkgd(' ', curses.A_DIM)
        self.borderbox.border()
        self.borderbox.refresh()
        self.textinpt.refresh()

        curses.curs_set(prior)
        curses.setsyx(cursr_y, cursr_x)
        curses.doupdate()
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
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()
项目:melomaniac    作者:sdispater    | 项目源码 | 文件源码
def __init__(self, ui):
        self.ui = ui
        self.scr = ui.stdscr
        self.player = ui.player
        self.colors = ui.colors
        self.height, self.width = self.scr.getmaxyx()
        self.header_height = 2
        self.footer_height = 2
        self.viewheight = self.height - self.header_height - self.footer_height
        self.current = None
        self.previous = []
        self.item = 0
        self.current_item = None
        self._search_mode = False

        curses.curs_set(0)

        self.scr.timeout(17)
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def edit(self, validate=None):
        """Edit in the widget window and collect the results."""
        # Make the cursor visible and update the screen
        curses.curs_set(1)
        self.win.refresh()
        while 1:
            ch = self.win.getch()
            if validate:
                ch = validate(ch)
            if not ch:
                continue
            if not self.do_command(ch):
                break
            self.win.refresh()
        # Hide the cursor
        curses.curs_set(0)
        return self.gather()
项目:gintonic    作者:redahe    | 项目源码 | 文件源码
def enter(self):
        self.history_point = 0
        curses.curs_set(1)
        curses.setsyx(2, 2)
        curses.doupdate()
        self.inp.erase()
        self.canceled = False
        res = self.text.edit(self._handle_key).strip()
        curses.curs_set(0)
        if self.canceled:
            self.inp.erase()
            self.inp.refresh()
            return ''
        elif (not(self.search_history) or self.search_history[-1] != res):
                self.search_history.append(res)
        return res
项目:rogueinabox    作者:rogueinabox    | 项目源码 | 文件源码
def _start_ui(self, stdscr):
        """TODO docs"""
        rogue_height = 26
        rogue_width = 84
        # using a pad instead of the default win, it's safer
        self.stdscr = curses.newpad(rogue_height, rogue_width)
        self.stdscr.nodelay(True)
        curses.curs_set(False)
        self.draw_from_rogue()
        minlogsize = 4
        if curses.LINES - 1 >= rogue_height + minlogsize:
            # there's enough space to show the logs
            self.logpad = curses.newpad(curses.LINES - 1, curses.COLS - 1)
        while True:
            if self.timer_callback:
                self.timer_callback()
                time.sleep(self.sleep_time)
            if self.keypress_callback:
                try:
                    key = self.stdscr.getkey()
                    event = Event()
                    event.char = key
                    self.keypress_callback(event)
                except curses.error:
                    pass
项目:ascii_qgis    作者:NathanW2    | 项目源码 | 文件源码
def display(self, title, content):
        curses.curs_set(0)
        self.infowin.clear()
        y, x = self.infowin.getmaxyx()
        self.infowin.bkgd(" ", curses.color_pair(6))
        self.infowin.box()
        self.infowin.addstr(0, 0, title + " - 'q' to close", curses.A_UNDERLINE | curses.A_BOLD)
        for count, line in enumerate(content.split('\n'), start=1):
            try:
                self.infowin.addstr(count, 1, line)
            except:
                pass

        self.infopanel.show()
        curses.panel.update_panels()
        curses.doupdate()
        while self.infowin.getch() != ord('q'):
            pass
        curses.curs_set(1)
项目:ascii_qgis    作者:NathanW2    | 项目源码 | 文件源码
def focus(self):
        modeline.update_activeWindow("Map")
        curses.curs_set(0)
        while True:
            event = self.mapwin.getch()
            # if event == -1:
            #     continue
            logging.info(event)
            try_handle_global_event(event)

            if event == curses.KEY_UP:
                self.pan("up")
            if event == curses.KEY_DOWN:
                self.pan("down")
            if event == curses.KEY_LEFT:
                self.pan("left")
            if event == curses.KEY_RIGHT:
                self.pan("right")
            if event == curses.KEY_NPAGE:
                self.zoom_out(5)
            if event == curses.KEY_PPAGE:
                self.zoom_in(5)
项目:YATE    作者:GarethNelson    | 项目源码 | 文件源码
def getinstr(self,prompt):
       self.scr.nodelay(0)
       self.scr.addstr(self.y+2,self.x+1,' '*(self.w-2),curses.color_pair(TOPSTATUS))
       self.scr.addstr(self.y+2,self.x+1,prompt,curses.color_pair(TOPSTATUS))
       self.scr.refresh()
       curses.curs_set(1)
       curses.echo()
       self.scr.attron(curses.color_pair(TOPSTATUS))
       retval = self.scr.getstr(self.y+2,self.x+len(prompt)+1,8)
       self.scr.addstr(self.y+2,self.x+len(prompt)+1,str(retval),curses.color_pair(TOPSTATUS))
       self.scr.attroff(curses.color_pair(TOPSTATUS))
       self.scr.refresh()
       curses.noecho()
       curses.curs_set(0)
       self.scr.nodelay(1)
       return retval
项目:logviewer    作者:romuloceccon    | 项目源码 | 文件源码
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()
项目:Utils    作者:disconsis    | 项目源码 | 文件源码
def countdown(stdscr, end_time, font, fg_color, bg_color, msg=None):
    stdscr.clear()
    curses.curs_set(False)
    curses.init_pair(1, fg_color, bg_color)

    now = datetime.datetime.now()
    timefmt = '%I:%M %p' if now.day == end_time.day else '%I:%M %p, %d %b'
    stdscr.addstr(0, 0, 'Alarm set for: ' + end_time.strftime(timefmt))
    stdscr.refresh()

    win = None
    while now < end_time:
        time_left = str(end_time - now).split('.')[0]
        win = center(stdscr, time_left, font, curses.color_pair(1), win)
        sleep(1)
        now = datetime.datetime.now()

    alert(stdscr, args, win)
项目:py_wsjtx    作者:teabreakninja    | 项目源码 | 文件源码
def __init__(self):
        self.stdscr = curses.initscr()
        # don't display keys
        curses.noecho()
        # don't need key + enter
        curses.cbreak()
        # remove cursor
        curses.curs_set(0)
        self.stdscr.keypad(1)

        #stdscr.border(0)
        self.height, self.width = self.stdscr.getmaxyx()

        self.header = self.stdscr.subwin(3, self.width, 0, 0)
        self.header.box()

        self.main_win = self.stdscr.subwin(20, self.width-2, 3, 1)
        self.main_win.scrollok(True)

        self.setup_colours()

        # self.main()
项目:connect4    作者:guglielmilo    | 项目源码 | 文件源码
def init():
    height_term, width_term = get_terminal_size()
    height_min = COL_HEIGHT * HEIGHT + 2 + 9
    width_min = COL_WIDTH * WIDTH + 2 + 5
    if height_term < height_min or width_term < width_min:
        # resize the terminal to fit the minimum size to display the connect4 before exit
        stdout.write("\x1b[8;{h};{w}t".format(h=max(height_min, height_term), w=max(width_min, width_term)))
        exit('\033[91m' + 'The terminal was too small, you can now restart ' + '\033[1m' + 'Connect4' + '\033[0m')
    stdscr = curses.initscr()
    height,width = stdscr.getmaxyx()
    if height < height_min or width < width_min:
        # abort the program if the terminal can't be resized
        curses.endwin()
        exit('Please resize your terminal [%d%s%d] (minimum required %d%s%d)' %(width, 'x', height, width_min, 'x', height_min))
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
    stdscr.keypad(1)
    #define the different colors
    if curses.can_change_color():
        defineColors()
    #return stdscr, width
    stdscr.clear()
    stdscr.border(0)
    return stdscr, width, height
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def refresh(self, drawList, cursor):
    """Repaint stacked windows, furthest to nearest in the main thread."""
    # Ask curses to hold the back buffer until curses refresh().
    cursesWindow = app.window.mainCursesWindow
    cursesWindow.noutrefresh()
    curses.curs_set(0)
    #drawList, cursor = app.render.frame.grabFrame()
    for i in drawList:
      try:
        cursesWindow.addstr(*i)
      except:
        #app.log.error('failed to draw', repr(i))
        pass
    if cursor is not None:
      curses.curs_set(1)
      try:
        cursesWindow.leaveok(0)  # Do update cursor position.
        cursesWindow.move(cursor[0], cursor[1])
        # Calling refresh will draw the cursor.
        cursesWindow.refresh()
        cursesWindow.leaveok(1)  # Don't update cursor position.
      except:
        pass
项目:fingerpi    作者:zafartahirov    | 项目源码 | 文件源码
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
项目:gpymusic    作者:christopher-dG    | 项目源码 | 文件源码
def goodbye(self, msg=''):
        """
        Exit gpymusic.

        Arguements:
        msg='': Message to display prior to exiting.
        """
        if not self.curses:
            if not self.test:
                print(msg)
            sys.exit()

        self.addstr(self.outbar, msg)
        common.mc.logout()
        try:
            common.client.mm.logout()
        except:
            pass
        sleep(2)
        crs.curs_set(1)
        crs.endwin()
        sys.exit()
项目:gpymusic    作者:christopher-dG    | 项目源码 | 文件源码
def get_input(self):
        """
        Get user input in the bottom bar.

        Returns: The user-inputted string.
        """
        if not self.curses:
            return input('Enter some input: ')

        self.addstr(self.inbar, '> ')
        crs.curs_set(2)  # Show the cursor.

        try:
            string = self.inbar.getstr()
        except KeyboardInterrupt:
            common.np.close()
            self.goodbye('Goodbye, thanks for using Google Py Music!')

        self.inbar.deleteln()
        crs.curs_set(0)  # Hide the cursor.

        return string.decode('utf-8')
项目:gpymusic    作者:christopher-dG    | 项目源码 | 文件源码
def login(user):
    """
    Log into Google Play Music. Succeeds or exits.

    Arguments:
    user: Dict containing auth information.
    """
    crs.curs_set(0)
    common.w.outbar_msg('Logging in...')
    try:
        if not common.mc.login(user['email'], user['password'], user['deviceid']):
            common.w.goodbye('Login failed: Exiting.')
        common.w.outbar_msg(
            'Logging in... Logged in as %s (%s).' %
            (user['email'], 'Full' if common.mc.is_subscribed else 'Free')
        )
    except KeyboardInterrupt:
        common.w.goodbye()
项目:s2e-env    作者:S2E    | 项目源码 | 文件源码
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)
项目:ssh-gateway    作者:bubbl    | 项目源码 | 文件源码
def processmenu(menu, parent = None):
  optioncount = len(menu['options'])
  exitmenu = False

  while not exitmenu:
    getin = runmenu(menu, parent)

    if getin == optioncount:
        exitmenu = True
    elif menu['options'][getin]['type'] == COMMAND:
      curses.def_prog_mode()
      os.system('reset')
      screen.clear()
      os.system(menu['options'][getin]['command'])
      screen.clear()
      curses.reset_prog_mode()
      curses.curs_set(1)
      curses.curs_set(0)
    elif menu['options'][getin]['type'] == MENU:
          screen.clear()
          processmenu(menu['options'][getin], menu)
          screen.clear()
    elif menu['options'][getin]['type'] == EXITMENU:
          exitmenu = True
项目:soyouhaveanidea    作者:yigitbey    | 项目源码 | 文件源码
def getstr(window, empty_ok=False):
    curses.curs_set(1)
    curses.echo()
    window.clear()
    window.move(0, 0)
    if empty_ok:
        response = window.getstr()
    else:
        response = b''
        while response == b'':
            response = window.getstr()
    window.clear()
    window.refresh()
    window.move(0, 0)
    curses.curs_set(0)
    return response
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def select(self):
        '''
        Not only selects this textbox, but turns on the cursor and moves it to
        the correct possition within this textbox.
        '''
        self.borderbox.bkgd(' ', curses.A_BOLD)
        self.textinpt.bkgd(' ', colors.get_colorpair(self.default_color))
        curses.curs_set(1)
        self.textinpt.move(0, self.keypos)
        self.refresh()
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def deselect(self):
        '''
        Deselects this Textbox and turns off cursor visiblity.
        '''
        self.borderbox.bkgd(' ', curses.A_NORMAL)
        self.textinpt.bkgd(' ', colors.get_colorpair(self.default_color))
        curses.curs_set(0)
        self.refresh()
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def redraw_bomb(stdscr, refresh_lock):
    global UPDATE_BOMBSPRITE
    idx = 0
    while True:
        time.sleep(0.25)
        if UPDATE_BOMBSPRITE:
            refresh_lock.acquire()
            curses.curs_set(0)
            idx = drawbomb(stdscr, idx)
            refresh_lock.release()
        else:
            break
项目:anonymine    作者:oskar-skog    | 项目源码 | 文件源码
def leave(self):
        '''Leave curses mode.'''
        curses.nocbreak()
        curses.echo()
        self.window.keypad(False)
        try:
            curses.curs_set(self.old_cursor)
        except:
            pass
        curses.endwin()
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def __init__(self, scr, title="", inittext="", win_location=(0, 0),
                 win_size=(20, 80), box=True, max_paragraphs=0, pw_mode=False,
                 edit=True):
        # Fix for python curses resize bug:
        # http://bugs.python.org/issue2675
        os.unsetenv('LINES')
        os.unsetenv('COLUMNS')
        self.scr = scr
        self.title_orig = title
        if sys.version_info.major < 3:
            enc = locale.getpreferredencoding() or 'utf-8'
            self.title_orig = str(self.title_orig, encoding=enc)
            inittext = str(inittext, encoding=enc)
        self.box = box
        self.max_paragraphs = max_paragraphs
        self.pw_mode = pw_mode
        self.edit = edit
        self.win_location_orig_y, self.win_location_orig_x = win_location
        self.win_size_orig_y, self.win_size_orig_x = win_size
        self.win_size_y = self.win_size_orig_y
        self.win_size_x = self.win_size_orig_x
        self.win_location_y = self.win_location_orig_y
        self.win_location_x = self.win_location_orig_x
        self.win_init()
        self.box_init()
        self.text_init(inittext)
        if self.edit is False:
            self.keys_init_noedit()
            try:
                curses.curs_set(0)
            except _curses.error:
                pass
        else:
            self.keys_init()
            curses.curs_set(1)
        self.display()
项目:botany    作者:jifunks    | 项目源码 | 文件源码
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')
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def __exit__(self):
        self.exit = True
        curses.curs_set(2)
        curses.endwin()
        os.system('clear')
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def enter_edit_mode(self, value=None):

        if self.items[self.position]['field'] == 'Comments':
            editwin = curses.newwin(10, 60, self.position+2, 27)
            rectangle(self.window, self.position + 1, 26, self.position + 12, 26 + 61)
        else:
            editwin = curses.newwin(1, 30, self.position+2, 27)

        editwin.attron(curses.color_pair(2))
        curses.curs_set(1)
        if value:
            box = _Textbox(editwin, True, text=value)
        else:
            box = _Textbox(editwin, True, text=self.items[self.position]['value'])

        _Textbox.stripspaces = True

        self.window.refresh()

        while True:
            edit_field = box.edit()
            if not edit_field is None:
                result = self.validate(edit_field.strip())
                if result:
                    self.navigate(1)
                    break
            else:
                break

        curses.curs_set(0)

        self.window.clear()
项目:lgsm-python    作者:jaredballou    | 项目源码 | 文件源码
def __init__(self, stdscreen, menudata=None):
        self.selection = None
        self.submenus = {}
        self.screen = stdscreen
        curses.curs_set(0)
    if menudata is not None:
        self.menu = iter_menu(menudata=menudata, rootmenu=self)
    else:
            self.menu = self.default_menu()
        self.menu.display()
项目:getTimer    作者:maxwellgerber    | 项目源码 | 文件源码
def _startWindow():
    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.keypad(1)
    curses.curs_set(0)
    return stdscr
项目:getTimer    作者:maxwellgerber    | 项目源码 | 文件源码
def _stopWindow(stdscr):
    stdscr.erase()
    stdscr.refresh()
    stdscr.keypad(0)
    curses.echo()
    curses.curs_set(1)
    curses.nocbreak()
    curses.endwin()
项目:getTimer    作者:maxwellgerber    | 项目源码 | 文件源码
def _cleanup():
    curses.echo()
    curses.curs_set(1)
    curses.nocbreak()
    curses.endwin()
    traceback.print_exc()
项目:cryptop    作者:huwwp    | 项目源码 | 文件源码
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)
项目:cryptop    作者:huwwp    | 项目源码 | 文件源码
def get_string(stdscr, prompt):
    '''Requests and string from the user'''
    curses.echo()
    stdscr.clear()
    stdscr.addnstr(0, 0, prompt, -1, curses.color_pair(2))
    curses.curs_set(1)
    stdscr.refresh()
    in_str = stdscr.getstr(1, 0, 20).decode()
    curses.noecho()
    curses.curs_set(0)
    stdscr.clear()
    curses.halfdelay(10)
    return in_str
项目:reinforcement_learning    作者:andreweskeclarke    | 项目源码 | 文件源码
def tetris_print(array, reward, screen):
    curses.noecho()
    curses.curs_set(0)
    screen.erase()
    for y, row in reversed(list(enumerate(array[0]))):
        for x, value in enumerate(row):
            character = "\u2588" if value else "."
            color = curses.color_pair(value)
            screen.addch(len(array[0]) - y, 3*x, character, color)
            screen.addch(len(array[0]) - y, 3*x + 1, character, color)
    screen.addstr(len(array[0]) + 5, 0, 'Reward: {}'.format(reward))
    screen.refresh()
项目:paint-it    作者:plainspooky    | 项目源码 | 文件源码
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))
项目:cluster-genesis    作者:open-power-ref-design-toolkit    | 项目源码 | 文件源码
def __init__(self, log, stdscr, title, subtitle=None, items=[]):
        self.log = log
        self.stdscr = stdscr
        self.title = title
        self.subtitle = subtitle
        self.items = items
        self.num_selects = (
            [ord(str(n)) for n in range(len(self.items)) if n < 10])
        self.enter_selects = [curses.KEY_ENTER, ord('\n')]
        curses.curs_set(0)
        self.cursor_pos = 0
项目:xcode_archive    作者:zhipengbird    | 项目源码 | 文件源码
def config_curses(self):
        # use the default colors of the terminal
        curses.use_default_colors ( )
        # hide the cursor
        curses.curs_set (0)
        # add some color for multi_select
        # @todo make colors configurable
        curses.init_pair (1, curses.COLOR_GREEN, curses.COLOR_WHITE)
项目:ssha    作者:claranet    | 项目源码 | 文件源码
def _display(screen, items, title=None):
    curses.curs_set(0)
    menu = Menu(title, items, screen)
    return menu.display()
项目:sandsifter    作者:xoreaxeaxeax    | 项目源码 | 文件源码
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()
项目:sandsifter    作者:xoreaxeaxeax    | 项目源码 | 文件源码
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()
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def matrix(self, args):
        try:
            core.matrix.main()
        except KeyboardInterrupt:
            curses.endwin()
            curses.curs_set(1)
            curses.reset_shell_mode()
            curses.echo()
项目:cyberbot    作者:RickGray    | 项目源码 | 文件源码
def init_scr(self):
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.curs_set(0)

        self.stdscr_size = self.stdscr.getmaxyx()
        self.task_total = count_file_linenum(self.config.seedfile)

        self.pgsscr_size = (self.config.proc_num + 2, 40)
        self.pgsscr = curses.newpad(*self.pgsscr_size)
        self.cntscr_size = (4, 40)
        self.cntscr = curses.newpad(*self.cntscr_size)
        self.optscr_size = (18, 80)
        self.optscr = curses.newpad(*self.optscr_size)
项目:taskhud    作者:usefulthings    | 项目源码 | 文件源码
def mainloop(self):
        """
        Called after HUD has been set up. Handles rendering and user input.
        """
        # Disable cursor display by default
        curses.curs_set(0)

        # Display initial state
        self.render()

        while True:
            # Render before fetching input
            self.render()

            # note: call is non-blocking, per __init__ calling nodelay(True)
            c = self.screen.getch()

            if c == curses.KEY_RESIZE:
                # Terminal has been resized

                # must be called so that curses.LINES, curses.COLS will change
                curses.update_lines_cols()

                # in case old data won't be redrawn after resize
                self.screen.clear()

            if c == curses.KEY_UP:
                # Move up as far as the 0th record
                self.selectpos = max(self.selectpos - 1, 0)
                if self.selectpos < self.scrollpos:
                    # Handle scrolling if we were at the first record on screen
                    self.scrollpos -= 1

            if c == curses.KEY_DOWN:
                # Move down as far as the Nth record
                self.selectpos = min(self.selectpos + 1, len(self.records) - 1)
                if self.selectpos >= (self.scrollpos + curses.LINES - 2 - self.bottom_panel_height) :
                    # Handle scrolling if we were at the last record on screen
                    self.scrollpos += 1
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
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)
项目:Remixatron    作者:drensin    | 项目源码 | 文件源码
def cleanup():
    """Cleanup before exiting"""

    if not window:
        return

    w_str = get_window_contents()
    curses.curs_set(1)
    curses.endwin()

    print w_str.rstrip()
    print

    mixer.quit()
项目:melomaniac    作者:sdispater    | 项目源码 | 文件源码
def display(self):
        curses.setsyx(self._y, self._x)
        self._view.scr.clrtoeol()
        self._view.string(self._text, 0, 0)
        curses.echo()
        curses.curs_set(1)
        self._view.scr.refresh()

        return self
项目:melomaniac    作者:sdispater    | 项目源码 | 文件源码
def response(self):
        response = self._view.scr.getstr(0, len(self._text) + 1)
        curses.noecho()
        curses.curs_set(0)

        return response