當前位置: 首頁>>代碼示例>>Python>>正文


Python shutil_get_terminal_size.get_terminal_size方法代碼示例

本文整理匯總了Python中backports.shutil_get_terminal_size.get_terminal_size方法的典型用法代碼示例。如果您正苦於以下問題:Python shutil_get_terminal_size.get_terminal_size方法的具體用法?Python shutil_get_terminal_size.get_terminal_size怎麽用?Python shutil_get_terminal_size.get_terminal_size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在backports.shutil_get_terminal_size的用法示例。


在下文中一共展示了shutil_get_terminal_size.get_terminal_size方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: saveErrorMessage

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def saveErrorMessage():
    """
    Simpan pesan error ke directory ``error`` *brutemap*
    """

    errMsg = "Running version: %s\n" % VERSION_STRING
    errMsg += "Python version: %s\n" % sys.version.split()[0]
    errMsg += "Operating system: %s\n" % platform.platform()
    errMsg += "Command line: %s\n" % re.sub(
        r".+?%s.py\b" % TOOL_NAME,
        "%s.py" % TOOL_NAME,
        " ".join(sys.argv)
    )
    errMsg += ("=" * get_terminal_size()[0]) + "\n"
    errMsg += getErrorMessage()
    filename = time.strftime("%d-%m-%Y_%X").replace(":", "-") + ".txt"
    filepath = os.path.join(DEFAULT.ERROR_DIRECTORY, filename)
    with open(filepath, "w") as fp:
        fp.write(errMsg)

    return filepath 
開發者ID:brutemap-dev,項目名稱:brutemap,代碼行數:23,代碼來源:core.py

示例2: say

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def say(msg):
    """Print a message.

    Unlike print(), this deals with de-denting and wrapping of text to fit
    within the width of the terminal.

    Paragraphs separated by blank lines in the input will be wrapped
    separately.

    """
    msg = str(msg)
    msg = re.sub(r'^[ \t]*(.*?)[ \t]*$', r'\1', msg, flags=re.M)
    width = get_terminal_size()[0]
    paragraphs = re.split(r'\n(?:[ \t]*\n)', msg)
    formatted = (textwrap.fill(p.strip(), width=width) for p in paragraphs)
    print('\n\n'.join(formatted)) 
開發者ID:lordmauve,項目名稱:adventurelib,代碼行數:18,代碼來源:adventurelib.py

示例3: __init__

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def __init__(self, *args, **kwargs):
        kwargs["width"] = get_terminal_size()[0] - 2
        HelpFormatter.__init__(self, *args, **kwargs) 
開發者ID:brutemap-dev,項目名稱:brutemap,代碼行數:5,代碼來源:option.py

示例4: terminal_width

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def terminal_width(self):
        """Get the width of the terminal in columns."""
        if self._terminal_width is None:
            try:
                self._terminal_width = get_terminal_size().columns
            except ValueError:
                # sometimes seen in unit tests:
                # ValueError: underlying buffer has been detached
                # Easy enough to work around...
                self._terminal_width = 80
            if self._terminal_width <= 0:
                self._terminal_width = 80
        return self._terminal_width 
開發者ID:glennmatthews,項目名稱:cot,代碼行數:15,代碼來源:cli.py

示例5: _get_output_lines

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def _get_output_lines(output):
    lines = output.split('\n')
    screen = pyte.Screen(get_terminal_size().columns, len(lines))
    stream = pyte.Stream(screen)
    stream.feed('\n'.join(lines))
    return screen.display 
開發者ID:nvbn,項目名稱:thefuck,代碼行數:8,代碼來源:shell_logger.py

示例6: _get_output_lines

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def _get_output_lines(script, log_file):
    data = log_file.read().decode()
    data = re.sub(r'\x00+$', '', data)
    lines = data.split('\n')
    grouped = list(_group_by_calls(lines))
    script_lines = _get_script_group_lines(grouped, script)
    screen = pyte.Screen(get_terminal_size().columns, len(script_lines))
    stream = pyte.Stream(screen)
    stream.feed('\n'.join(script_lines))
    return screen.display 
開發者ID:nvbn,項目名稱:thefuck,代碼行數:12,代碼來源:read_log.py

示例7: get_size

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def get_size(self):
		try:
			from backports.shutil_get_terminal_size import get_terminal_size
			return get_terminal_size().columns
		except:
			return None 
開發者ID:hash3liZer,項目名稱:WiFiBroot,代碼行數:8,代碼來源:screen.py

示例8: _get_max_width

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def _get_max_width(self):
        if sys.version_info > (3, 3):
            from shutil import get_terminal_size
        else:
            from backports.shutil_get_terminal_size import get_terminal_size
        terminal_width, _ = get_terminal_size()
        max_width = min(int(terminal_width * 0.6), terminal_width - 50)
        return max_width 
開發者ID:PaddlePaddle,項目名稱:hapi,代碼行數:10,代碼來源:progressbar.py

示例9: get_terminal_size

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def get_terminal_size(fallback=(80, 24)):
            return fallback 
開發者ID:lordmauve,項目名稱:adventurelib,代碼行數:4,代碼來源:adventurelib.py

示例10: _get_max_bar_width

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def _get_max_bar_width(self):
        if sys.version_info > (3, 3):
            from shutil import get_terminal_size
        else:
            from backports.shutil_get_terminal_size import get_terminal_size
        terminal_width, _ = get_terminal_size()
        max_bar_width = min(int(terminal_width * 0.6), terminal_width - 50)
        if max_bar_width < 10:
            print(
                "terminal width is too small ({}), please consider "
                "widen the terminal for better progressbar "
                "visualization".format(terminal_width)
            )
            max_bar_width = 10
        return max_bar_width 
開發者ID:poodarchu,項目名稱:Det3D,代碼行數:17,代碼來源:progressbar.py

示例11: generate_progress_handler

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def generate_progress_handler(file_path, action='', max_bar_length=80):
    """Returns a function that prints a progress bar in the terminal

    :param file_path: The name of the file being transferred
    :param action: Uploading/Downloading
    :param max_bar_length: Maximum allowed length of the bar. Default: 80
    :return: The configured print_progress function
    """
    # We want to limit the maximum line length to 80, but allow for a smaller
    # terminal size. We also include the action string, and some extra chars
    terminal_width = get_terminal_size().columns

    # This takes care of the case where there is no terminal (e.g. unittest)
    terminal_width = terminal_width or max_bar_length
    bar_length = min(max_bar_length, terminal_width) - len(action) - 12

    # Shorten the file name if it's too long
    file_name = os.path.basename(file_path)
    if len(file_name) > (bar_length // 4) + 3:
        file_name = file_name[:bar_length // 4] + '...'

    bar_length -= len(file_name)

    def print_progress(read_bytes, total_bytes):
        """Print upload/download progress on a single line

        Call this function in a loop to create a progress bar in the terminal

        :param read_bytes: Number of bytes already processed
        :param total_bytes: Total number of bytes in the file
        """

        filled_length = min(bar_length, int(round(bar_length * read_bytes /
                                                  float(total_bytes))))
        percents = min(100.00, round(
            100.00 * (read_bytes / float(total_bytes)), 2))
        bar = '#' * filled_length + '-' * (bar_length - filled_length)

        # The \r caret makes sure the cursor moves back to the beginning of
        # the line
        msg = '\r{0} {1} |{2}| {3}%'.format(action, file_name, bar, percents)
        click.echo(msg, nl=False)
        if read_bytes >= total_bytes:
            sys.stdout.write('\n')

    return print_progress 
開發者ID:cloudify-cosmo,項目名稱:cloudify-cli,代碼行數:48,代碼來源:utils.py

示例12: generate_progress_handler

# 需要導入模塊: from backports import shutil_get_terminal_size [as 別名]
# 或者: from backports.shutil_get_terminal_size import get_terminal_size [as 別名]
def generate_progress_handler(file_path, action='', max_bar_length=80):
    """
    Returns a function that prints a progress bar in the terminal.

    :param file_path: the name of the file being transferred
    :param action: uploading/downloading
    :param max_bar_length: maximum allowed length of the bar
    :return: configured ``print_progress`` function
    """
    # We want to limit the maximum line length to 80, but allow for a smaller terminal size. We also
    # include the action string, and some extra chars
    terminal_width = get_terminal_size().columns

    # This takes care of the case where there is no terminal (e.g. unittest)
    terminal_width = terminal_width or max_bar_length
    bar_length = min(max_bar_length, terminal_width) - len(action) - 12

    # Shorten the file name if it's too long
    file_name = os.path.basename(file_path)
    if len(file_name) > (bar_length / 4) + 3:
        file_name = file_name[:bar_length / 4] + '...'

    bar_length -= len(file_name)

    def print_progress(read_bytes, total_bytes):
        """
        Print upload/download progress on a single line.

        Call this function in a loop to create a progress bar in the terminal.

        :param read_bytes: number of bytes already processed
        :param total_bytes: total number of bytes in the file
        """

        filled_length = min(bar_length, int(round(bar_length * read_bytes / float(total_bytes))))
        percents = min(100.00, round(100.00 * (read_bytes / float(total_bytes)), 2))
        bar = '#' * filled_length + '-' * (bar_length - filled_length)                              # pylint: disable=blacklisted-name

        # The \r caret makes sure the cursor moves back to the beginning of the line
        sys.stdout.write('\r{0} {1} |{2}| {3}%'.format(action, file_name, bar, percents))
        if read_bytes >= total_bytes:
            sys.stdout.write(os.linesep)

    return print_progress 
開發者ID:apache,項目名稱:incubator-ariatosca,代碼行數:46,代碼來源:utils.py


注:本文中的backports.shutil_get_terminal_size.get_terminal_size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。