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

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

项目: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
项目:Round1    作者:general-ai-challenge    | 项目源码 | 文件源码
def initialize(self):
        # initialize curses
        self._stdscr = curses.initscr()

        # TODO generalize this:
        begin_x = 0
        begin_y = 0
        # self._info_win_width = 20
        self._info_win_height = 4
        self.height, self.width = self._stdscr.getmaxyx()
        self._win = self._stdscr.subwin(self.height, self.width, begin_y,
                                        begin_x)
        # create info box with reward and time
        self._info_win = self._win.subwin(self._info_win_height,
                                          self.width,
                                          0,
                                          0)

        curses.noecho()
        curses.cbreak()
项目:slacky    作者:mathiasbc    | 项目源码 | 文件源码
def setup(self, stdscr):
        self.stdscr = stdscr
        # define curses color pairs
        set_color_pairs()
        # set getch to blocking
        self.stdscr.nodelay(0)
        # don't echo key strokes on the screen
        curses.noecho()
        # read keystrokes instantly, without waiting for enter to be pressed
        curses.cbreak()
        # enable keypad mode
        self.stdscr.keypad(1)
        # draw the main frame
        self.setup_draw()
        # find what's the erase character
        self.del_char = curses.erasechar()
        self.run()
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
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()
项目:mitogen    作者:dw    | 项目源码 | 文件源码
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'
        )
项目:gdax-trader    作者:mcardillo55    | 项目源码 | 文件源码
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...")
项目:flux_line_bot    作者:blesscat    | 项目源码 | 文件源码
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()
项目: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
项目:transmission_scripts    作者:leighmacdonald    | 项目源码 | 文件源码
def top(args):
    scr = curses.initscr()
    #scr.start_color()
    curses.noecho()
    curses.cbreak()
    hx, wm = scr.getmaxyx()
    scr.keypad(True)
    try:
        header = curses.newwin(HEADER_SIZE, wm, 0, 0)
        body = curses.newwin(BODY_SIZE, wm, HEADER_SIZE, 0)
        while True:
            draw_header(header)
            draw_body(body)
            draw_footer(scr)
            sleep(0.2)
    except KeyboardInterrupt:
        curses.nocbreak()
        scr.keypad(False)
        curses.echo()
        curses.endwin()
项目:CommAI-env    作者:facebookresearch    | 项目源码 | 文件源码
def initialize(self):
        # initialize curses
        self._stdscr = curses.initscr()

        # TODO generalize this:
        begin_x = 0
        begin_y = 0
        # self._info_win_width = 20
        self._info_win_height = 4
        self.height, self.width = self._stdscr.getmaxyx()
        self._win = self._stdscr.subwin(self.height, self.width, begin_y,
                                        begin_x)
        # create info box with reward and time
        self._info_win = self._win.subwin(self._info_win_height,
                                          self.width,
                                          0,
                                          0)

        curses.noecho()
        curses.cbreak()
项目:commai-env    作者:axbaretto    | 项目源码 | 文件源码
def initialize(self):
        # initialize curses
        self._stdscr = curses.initscr()

        # TODO generalize this:
        begin_x = 0
        begin_y = 0
        # self._info_win_width = 20
        self._info_win_height = 4
        self.height, self.width = self._stdscr.getmaxyx()
        self._win = self._stdscr.subwin(self.height, self.width, begin_y,
                                        begin_x)
        # create info box with reward and time
        self._info_win = self._win.subwin(self._info_win_height,
                                          self.width,
                                          0,
                                          0)

        curses.noecho()
        curses.cbreak()
项目:AutoCode    作者:HashCode55    | 项目源码 | 文件源码
def __init__(self, file, n, godmode):
        """
        main is the wrapper window
        There are two nested windows, namely header and stdscr.        
        """
        self.main = curses.initscr()
        self.ROWS, self.COLS = self.main.getmaxyx()  

        self.header = self.main.subwin(2, self.COLS, 0, 0)
        # center the text 
        # cast it to int for python3 support
        center = int((self.COLS / 2) - (len(HEADER) / 2))
        self.header.addstr(center * ' ' + HEADER)        
        self.header.refresh()

        self.stdscr = self.main.subwin(self.ROWS-1, self.COLS, 1, 0)        
        self.stdscr.idlok(True) 
        self.stdscr.scrollok(True)  

        curses.cbreak()        
        curses.noecho()         

        self.stdscr.keypad(1)
        self.stdscr.refresh()

        self.file = file           
        # this is for handling the backspaces 
        self.virtualfile = file.split('\n') 

        self.godmode = godmode
        self.n = n   

        # handle terminal size
        if self.COLS < 100:
            curses.endwin()            
            print ('Error: Increase the width of your terminal')
            sys.exit(1)
项目:supremm    作者:ubccr    | 项目源码 | 文件源码
def __enter__(self):
        """ init curses library """
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        self.stdscr.keypad(1)

        return self
项目:Round1    作者:general-ai-challenge    | 项目源码 | 文件源码
def initialize(self):
        # initialize curses
        self._stdscr = curses.initscr()
        begin_x = 0
        begin_y = 0
        self._teacher_seq_y = 0
        self._learner_seq_y = 1
        self._reward_seq_y = 2
        self._world_win_y = 4
        self._world_win_x = 0
        self._info_win_width = 20
        self._info_win_height = 4
        self._user_input_win_y = 4
        self._user_input_win_x = 10
        self.height, self.width = self._stdscr.getmaxyx()
        self._scroll_msg_length = self.width - self._info_win_width - 1
        self._win = self._stdscr.subwin(self.height, self.width, begin_y,
                                        begin_x)
        self._worldwin = self._win.subwin(self.height - self._world_win_y,
                                          self.width - self._world_win_x,
                                          self._world_win_y,
                                          self._world_win_x)
        # create info box with reward and time
        self._info_win = self._win.subwin(self._info_win_height,
                                          self._info_win_width,
                                          0,
                                          self.width - self._info_win_width)
        self._user_input_win = \
            self._win.subwin(1,
                             self.width - self._user_input_win_x,
                             self._user_input_win_y,
                             self._user_input_win_x)
        self._user_input_label_win = \
            self._win.subwin(1,
                             self._user_input_win_x - 1,
                             self._user_input_win_y,
                             0)
        curses.noecho()
        curses.cbreak()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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()
项目:awesome-finder    作者:mingrammer    | 项目源码 | 文件源码
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)
项目:getTimer    作者:maxwellgerber    | 项目源码 | 文件源码
def _startWindow():
    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    stdscr.keypad(1)
    curses.curs_set(0)
    return stdscr
项目: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))
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
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()
项目: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()
项目: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)
项目:cursed    作者:johannestaas    | 项目源码 | 文件源码
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
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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()
项目:pycreate2    作者:MomsFriendlyRobotCompany    | 项目源码 | 文件源码
def __init__(self):
        # print('start')
        locale.setlocale(locale.LC_ALL, '')
        self.screen = curses.initscr()  # Initialize curses.
        curses.noecho()
        curses.cbreak()  # don't need to hit enter
        curses.curs_set(0)  # disable mouse cursor
        self.screen.nodelay(True)  # non-blocking on getch - not sure this works
        # pass

        self.windows = {}
        self.windows['commands'] = CommandWindow(4, 1)
        self.windows['light'] = LightBumperWindow(11, 1)

        self.dummy = -100.0
项目:gintonic    作者:redahe    | 项目源码 | 文件源码
def init_curses():
    mainwindow.keypad(1)
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
项目:sawtooth-validator    作者:hyperledger-archives    | 项目源码 | 文件源码
def __init__(self):
        self.use_curses = True if curses_imported else False
        self.start = True
        self.scrn = None

        if self.use_curses:
            self.scrn = curses.initscr()

            curses.noecho()
            curses.cbreak()

            self.scrn.nodelay(1)
项目:WxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
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
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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()
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
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()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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()
项目:solent    作者:solent-eng    | 项目源码 | 文件源码
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)
项目:Music-Scraper    作者:srivatsan-ramesh    | 项目源码 | 文件源码
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()
项目:youtube_watcher    作者:Sjc1000    | 项目源码 | 文件源码
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
项目:RasWxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
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
项目:trtop    作者:aol    | 项目源码 | 文件源码
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
项目:NEmusicbox    作者:PyCN    | 项目源码 | 文件源码
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
项目:app    作者:pythonfucku    | 项目源码 | 文件源码
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()
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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()
项目:ffw    作者:dobin    | 项目源码 | 文件源码
def initCurses():
    screen = curses.initscr()
    curses.noecho()  # disable the keypress echo to prevent double input
    curses.cbreak()  # disable line buffers to run the keypress immediately
    curses.curs_set(0)
    screen.keypad(1)  # enable keyboard use

    screen.addstr(1, 2, "Fuzzing For Worms", curses.A_UNDERLINE)
    return screen
项目:pubmarine    作者:abadger    | 项目源码 | 文件源码
def __enter__(self):
        self.stdscr = curses.initscr()

        curses.noecho()
        curses.cbreak()
        self.stdscr.keypad(1)

        max_y, max_x = self.stdscr.getmaxyx()

        self.error_buffer = self.stdscr.derwin(1, max_x, 0, 0)

        self.separator1 = self.stdscr.derwin(1, max_x, 1, 0)
        sep_txt = b'-' * (max_x - 1)
        self.separator1.addstr(0, 0, sep_txt)

        self.chat_log = self.stdscr.derwin(max_y - 3, max_x, 2, 0)
        self.chat_max_y, self.chat_max_x = self.chat_log.getmaxyx()
        self.current_chat_line = 0

        self.separator2 = self.stdscr.derwin(1, max_x, max_y - 2, 0)
        sep_txt = b'=' * (max_x - 1)
        self.separator2.addstr(0, 0, sep_txt)

        self.input_buffer = self.stdscr.derwin(1, max_x, max_y - 1, 0)
        self.input_max_y, self.input_max_x = self.input_buffer.getmaxyx()
        self.input_current_x = 0
        self.input_contents = ''

        self.stdscr.refresh()
        return self
项目:DarkWallet    作者:DissentDifference    | 项目源码 | 文件源码
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()
项目:ipmap-creator    作者:ASP-Labs    | 项目源码 | 文件源码
def curses_start(self):
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        self.win = curses.newwin(
            5 + self.window_height,
            self.window_width,
            2,
            4
        )
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def _getch(self, wait_tenths):
        if wait_tenths==0:
            return self._getch_nodelay()
        if wait_tenths is None:
            curses.cbreak()
        else:
            curses.halfdelay(wait_tenths)
        self.s.nodelay(0)
        return self.s.getch()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def _getch_nodelay(self):
        self.s.nodelay(1)
        while 1:
            # this call fails sometimes, but seems to work when I try again
            try:
                curses.cbreak()
                break
            except _curses.error:
                pass

        return self.s.getch()
项目:CommAI-env    作者:facebookresearch    | 项目源码 | 文件源码
def initialize(self):
        # initialize curses
        self._stdscr = curses.initscr()
        begin_x = 0
        begin_y = 0
        self._teacher_seq_y = 0
        self._learner_seq_y = 1
        self._world_win_y = 3
        self._world_win_x = 0
        self._info_win_width = 20
        self._info_win_height = 2
        self._user_input_win_y = 2
        self._user_input_win_x = 10
        self.height, self.width = self._stdscr.getmaxyx()
        self._scroll_msg_length = self.width - self._info_win_width - 1
        self._win = self._stdscr.subwin(self.height, self.width, begin_y,
                                        begin_x)
        self._worldwin = self._win.subwin(self.height - self._world_win_y,
                                          self.width - self._world_win_x,
                                          self._world_win_y,
                                          self._world_win_x)
        # create info box with reward and time
        self._info_win = self._win.subwin(self._info_win_height,
                                          self._info_win_width,
                                          0,
                                          self.width - self._info_win_width)
        self._user_input_win = \
            self._win.subwin(1,
                             self.width - self._user_input_win_x,
                             self._user_input_win_y,
                             self._user_input_win_x)
        self._user_input_label_win = \
            self._win.subwin(1,
                             self._user_input_win_x - 1,
                             self._user_input_win_y,
                             0)
        curses.noecho()
        curses.cbreak()
项目:vpn-fetch    作者:Flynston    | 项目源码 | 文件源码
def init_curses(self):
        self.stdscr.refresh()

        curses.use_default_colors()
        self.max_y, self.max_x = self.stdscr.getmaxyx()

        curses.noecho()
        curses.cbreak()

        curses.curs_set(0)
        self.stdscr.keypad(1)
项目:commai-env    作者:axbaretto    | 项目源码 | 文件源码
def initialize(self):
        # initialize curses
        self._stdscr = curses.initscr()
        begin_x = 0
        begin_y = 0
        self._teacher_seq_y = 0
        self._learner_seq_y = 1
        self._world_win_y = 3
        self._world_win_x = 0
        self._info_win_width = 20
        self._info_win_height = 2
        self._user_input_win_y = 2
        self._user_input_win_x = 10
        self.height, self.width = self._stdscr.getmaxyx()
        self._scroll_msg_length = self.width - self._info_win_width - 1
        self._win = self._stdscr.subwin(self.height, self.width, begin_y,
                                        begin_x)
        self._worldwin = self._win.subwin(self.height - self._world_win_y,
                                          self.width - self._world_win_x,
                                          self._world_win_y,
                                          self._world_win_x)
        # create info box with reward and time
        self._info_win = self._win.subwin(self._info_win_height,
                                          self._info_win_width,
                                          0,
                                          self.width - self._info_win_width)
        self._user_input_win = \
            self._win.subwin(1,
                             self.width - self._user_input_win_x,
                             self._user_input_win_y,
                             self._user_input_win_x)
        self._user_input_label_win = \
            self._win.subwin(1,
                             self._user_input_win_x - 1,
                             self._user_input_win_y,
                             0)
        curses.noecho()
        curses.cbreak()