当前位置: 首页>>代码示例>>Python>>正文


Python terminalsize.get_terminal_size函数代码示例

本文整理汇总了Python中terminalsize.get_terminal_size函数的典型用法代码示例。如果您正苦于以下问题:Python get_terminal_size函数的具体用法?Python get_terminal_size怎么用?Python get_terminal_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_terminal_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    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.storage = Storage()
        self.newversion = False

        # Set cursor to invisible.
        try:
            curses.curs_set(0)
        except curses.error:
            # The terminal does not supports the visibility requested.
            pass
开发者ID:royaso,项目名称:musicbox,代码行数:31,代码来源:ui.py

示例2: init

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
开发者ID:guglielmilo,项目名称:connect4,代码行数:25,代码来源:terminal.py

示例3: __init__

    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
开发者ID:Zorgodon,项目名称:musicbox,代码行数:26,代码来源:ui.py

示例4: print_game_field

def print_game_field():
    '''
    Function prints game field.
    Arguments: none
    Return: 
        game_matrix - array with screen coordinates
    '''
    cols, rows = terminalsize.get_terminal_size()
    start_x = cols/2-5
    start_y = rows/2-5
    sys.stdout.write("\033[{}H".format(start_y))
    sys.stdout.write("\033[{}G   |   |   \n".format(start_x))
    sys.stdout.write("\033[{}G---+---+---\n".format(start_x))
    sys.stdout.write("\033[{}G   |   |   \n".format(start_x))
    sys.stdout.write("\033[{}G---+---+---\n".format(start_x))
    sys.stdout.write("\033[{}G   |   |   \n".format(start_x))
    sys.stdout.flush()
    
    game_matrix = []
    for x in range(3):
        game_matrix.append([])
        for y in range(3):
            game_matrix[x].append({'x':(start_x+1+x*4),'y':(start_y+y*2)})
    
    return game_matrix
开发者ID:andreikhudavets,项目名称:pylearning,代码行数:25,代码来源:tictactoe.py

示例5: main

def main():
    print("Let the adventure begin!")
    getgoing()
    print("And so we continue!")
    #Give the screen dimensions greater scope than the renderscreen function
    (widthpass, heightpass) = terminalsize.get_terminal_size()
    #The first screen
    (numofchoices, choicemap) = renderscreen("_init", widthpass, heightpass)
    #The main game loop
    while True == True:
        #getchoice handles exiting the loop, so no external control is needed
        choice = getchoice(numofchoices)
        #Get the proper screen size
        (widthpass, heightpass) = terminalsize.get_terminal_size()
        #Will use the choice to render the appropriate screen, ultimately
        (numofchoices, choicemap) = renderscreen(choicemap[choice], widthpass, heightpass)
开发者ID:mhspradlin,项目名称:python,代码行数:16,代码来源:main.py

示例6: list_dbentries

 def list_dbentries(self):
     """
     list all entries in the db.
     """
     dbdir = os.path.expanduser('~')
     fragnames = []
     num = 0
     try:
         (width, _) = get_terminal_size()
     except():
         width = 80
     print('\n Entries found in the databases:\n')
     print(' Fragment         | Line | DB Name    | Full name, Comments ')
     print(sep_line)
     for num, line in enumerate(self.gdb.list_fragments()):
         fragnames.append(line[0])
         line = ' {:<17}| {:<5}| {:<11}| {}'.format(*line)
         print(line[:width - 1])
     print('\n {} Fragments in the database(s).'.format(num),
           '\n Feel free to add more fragments to "{}dsr_user_db.txt"'.format(dbdir + os.path.sep))
     for fragment in fragnames:
         self.gdb.check_consistency(fragment)
         self.gdb.check_db_atom_consistency(fragment)
         self.gdb.check_db_restraints_consistency(fragment)
         self.gdb.check_sadi_consistence(fragment)
     from selfupdate import is_update_needed
     if is_update_needed(silent=True):
         print("\n*** An update for DSR is available. You can update with 'dsr -u' ***")
     sys.exit()
开发者ID:dkratzert,项目名称:DSR,代码行数:29,代码来源:dsr.py

示例7: borrar

def borrar(secadora):
	global esclavo
	width,height=terminalsize.get_terminal_size()
	sys.stdout.write('\0\033[' + str(esclavo[secadora].renglon) + ';1H')
	sys.stdout.write('\0\033[1;31m')
	printw(esclavo[secadora].nombre)
	printw('-',width-9)
开发者ID:hhautomatizacion,项目名称:monitorsecadoras,代码行数:7,代码来源:dryermon.py

示例8: main

def main():
    assert_git_config()

    try:
        usage = ("""usage: %prog <command> [options]
       %prog clone [-r alias] [-m URL]
       %prog branch [-r alias] [-m URL] [--rf package] [--dryrun]
       %prog prepare [-r alias] [-m URL] [--rf package] [--dryrun]
       %prog perform [-r alias] [-m URL] [--rf package] [--dryrun]""")
        description = """Release Nuxeo Packages.\n
The first call must provide an URL for the configuration. If set to '' (empty string), it defaults to '%s'. You can use
a local file URL ('file://').\n
Then, a 'release.ini' file is generated and will be reused for the next calls. For each package, a
'release-$PACKAGE_NAME.log' file is also generated and corresponds to the file generated by the release.py script.\n
The 'release.ini' file contains informations about the release process:\n
- 'prepared = True' if the prepare task succeeded,\n
- 'performed = True' if the perform task succeeded,\n
- 'uploaded = ...' if an upload successfully happened,\n
- 'skip = Failed!' followed by a stack trace in case of error.\n
The script can be re-called: it will skip the packages with a skip value and skip the prepare (or perform) if
'prepared = True' (or 'performed = True').\n
Failed uploads are not retried and must be manually done.""" % DEFAULT_MP_CONF_URL
        help_formatter = IndentedHelpFormatterWithNL(max_help_position=7, width=get_terminal_size()[0])
        parser = optparse.OptionParser(usage=usage, description=description, formatter=help_formatter)
        parser.add_option('-r', action="store", type="string", dest='remote_alias', default='origin',
                          help="""The Git alias of remote URL. Default: '%default'""")
        parser.add_option('-m', "--marketplace-conf", action="store", type="string", dest='marketplace_conf',
                          default=None, help="""The Marketplace configuration URL. Default: '%default'""")
        parser.add_option('-i', '--interactive', action="store_true", dest='interactive', default=False,
                          help="""Not implemented (TODO NXP-8573). Interactive mode. Default: '%default'""")
        parser.add_option('--rf', '--restart-from', action="store", dest='restart_from', default=None,
                          help="""Restart from a package. Default: '%default'""")
        parser.add_option('--dryrun', action="store_true", dest='dryrun', default=False,
                          help="""Dry run mode. Default: '%default'""")
        (options, args) = parser.parse_args()
        if len(args) == 1:
            command = args[0]
        elif len(args) > 1:
            raise ExitException(1, "'command' must be a single argument. See usage with '-h'.")
        full_release = ReleaseMP(options.remote_alias, options.restart_from, options.marketplace_conf)
        if "command" not in locals():
            raise ExitException(1, "Missing command. See usage with '-h'.")
        elif command == "clone":
            full_release.clone()
        elif command == "branch":
            full_release.release_branch(dryrun=options.dryrun)
        elif command == "prepare":
            full_release.prepare(dryrun=options.dryrun)
        elif command == "perform":
            full_release.perform(dryrun=options.dryrun)
        elif command == "test":
            full_release.test()
        else:
            raise ExitException(1, "Unknown command! See usage with '-h'.")
    except ExitException, e:
        if e.message is not None:
            log("[ERROR] %s" % e.message, sys.stderr)
        sys.exit(e.return_code)
开发者ID:Vozro,项目名称:nuxeo,代码行数:58,代码来源:release_mp.py

示例9: print_top_right

def print_top_right(text):
    '''
    print text to top right in terminal
    '''
    (width, heigth) = terminalsize.get_terminal_size()  # @UnusedVariable
    text_len = len(text)
    text = '| %s |' % text
    print_there(1, width - len(text) + 1, '+%s+' % ('-' * (text_len + 2)))
    print_there(2, width - len(text) + 1, text)
    print_there(3, width - len(text) + 1, '+%s+' % ('-' * (text_len + 2)))
开发者ID:eljrax,项目名称:pyraxshell,代码行数:10,代码来源:utility.py

示例10: printwords

 def printwords(self):
     """Nicely print words in columns, sensitive to console width!"""
     (console_width, console_height) = terminalsize.get_terminal_size()
     if len(self.wordlist) > 0:
         word_length = max([len(word) for word in self.wordlist]) + 1
         columns = console_width / word_length
         for index, word in enumerate(self.wordlist):
             if (index+1) % columns == 0:
                 print
             print word.ljust(word_length),
     print "\n%d words in list" % len(self.wordlist)
开发者ID:LunaticNeko,项目名称:hackboy,代码行数:11,代码来源:hackboy.py

示例11: __init__

    def __init__(self, dim = 15):
        self.size = dim
        self.board = None
        #self.loadedWords = ["word", "test", "another", "much", "words", "blue", "etc"] #todo
        self.terminalSize = terminalsize.get_terminal_size()
        self.getchar = _Getch()
        self.cls = ClearScreen()

        self.loadWords()

        self.manageMenu()
开发者ID:wgml,项目名称:wordgame,代码行数:11,代码来源:wordgame.py

示例12: print_notification

def print_notification(text):
    '''
    Function prints notification about current game status.
    Input: 
        text - text string
    Return: none
    '''
    cols, rows = terminalsize.get_terminal_size()
    sys.stdout.write("\033[{};{}H".format(rows,0))
    sys.stdout.write(text)
    sys.stdout.flush()
开发者ID:andreikhudavets,项目名称:pylearning,代码行数:11,代码来源:tictactoe.py

示例13: __init__

    def __init__(self):
        self.stdout = sys.stdout
        self.width, self.height = get_terminal_size()
        self.buffers = ['' for i in xrange(self.width)]
        self.speed = [randint(-SPEED_RANGE, MAX_SPEED) 
                      for i in xrange(self.width)]
        self.in_matrix = True
        self.counter = 0
        self.animation_thread = Thread(target=self.animation)
        self.clrscr()

        self.animation_thread.start()
开发者ID:yashunsky,项目名称:matrix,代码行数:12,代码来源:matrix.py

示例14: update_size

 def update_size(self):
     # get terminal size
     size = terminalsize.get_terminal_size()
     self.x = max(size[0], 10)
     self.y = max(size[1], 25)
     
     # update intendations
     curses.resizeterm(self.y, self.x)
     self.startcol = int(float(self.x)/5)
     self.indented_startcol = max(self.startcol - 3, 0)
     self.update_space()
     self.screen.clear()
     self.screen.refresh()
开发者ID:hoyho,项目名称:musicbox,代码行数:13,代码来源:ui.py

示例15: print_list

    def print_list(self):
        colorama.init()
        sizex, sizey = terminalsize.get_terminal_size()
        sizex -= 5
        # Print active tasks
        tlen = 9 + 10 + 20 + 3
        clen = sizex - tlen
        fmtstr = (
            "%(id)3s | %(content)-"
            + str(clen)
            + "s | %(due)-20s | %(priority)-10s"
            + Fore.RESET
            + Back.RESET
            + Style.RESET_ALL
        )
        print Back.WHITE + Fore.BLACK + fmtstr % {"id": "#", "content": "Task", "due": "Due", "priority": "Priority"}

        if len(self.activetasks) == 0:
            print "There are no active tasks. Use the 'Add' command to to one."
        else:
            c = 0
            for t in self.activetasks:
                numlines = int(len(t.content) / (clen)) + 1
                col1 = c
                col2 = ""
                col3 = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(t.duedate))
                col4 = t.priority
                start = 0
                for i in range(numlines):

                    end = start + clen
                    if end < len(t.content):
                        while end > 0:
                            if t.content[end].isspace():
                                break
                            end -= 1
                        if end == 0:
                            end = start + clen
                    col2 = (t.content[start:end]).strip()
                    start = end
                    print self.priorityStyles[t.priority] + fmtstr % {
                        "id": col1,
                        "content": col2,
                        "due": col3,
                        "priority": col4,
                    }
                    col1 = col3 = col4 = ""
                c += 1

        print ""
开发者ID:AstromechZA,项目名称:Tasker,代码行数:50,代码来源:tasklist.py


注:本文中的terminalsize.get_terminal_size函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。