当前位置: 首页>>代码示例>>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;未经允许,请勿转载。