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


Python click.get_terminal_size方法代码示例

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


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

示例1: list_fpgas

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def list_fpgas(self):
        """Return a list with all the supported FPGAs"""

        # Print table
        click.echo('\nSupported FPGAs:\n')

        FPGALIST_TPL = ('{fpga:40} {arch:<8} {type:<12} {size:<5} {pack:<10}')
        terminal_width, _ = click.get_terminal_size()

        click.echo('-' * terminal_width)
        click.echo(FPGALIST_TPL.format(
            fpga=click.style('FPGA', fg='cyan'), type='Type', arch='Arch',
            size='Size', pack='Pack'))
        click.echo('-' * terminal_width)

        for fpga in self.fpgas:
            click.echo(FPGALIST_TPL.format(
                fpga=click.style(fpga, fg='cyan'),
                arch=self.fpgas.get(fpga).get('arch'),
                type=self.fpgas.get(fpga).get('type'),
                size=self.fpgas.get(fpga).get('size'),
                pack=self.fpgas.get(fpga).get('pack'))) 
开发者ID:FPGAwars,项目名称:apio,代码行数:24,代码来源:resources.py

示例2: process

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def process(self):
        terminal_width, _ = click.get_terminal_size()
        start_time = time()

        click.echo("[%s] Processing %s (%s)" % (
            datetime.now().strftime("%c"),
            click.style(self.name, fg="cyan", bold=True),
            ", ".join(["%s: %s" % (k, v) for k, v in self.options.iteritems()])
        ))
        click.secho("-" * terminal_width, bold=True)

        result = self._run()

        is_error = result['returncode'] != 0
        summary_text = " Took %.2f seconds " % (time() - start_time)
        half_line = "=" * ((terminal_width - len(summary_text) - 10) / 2)
        click.echo("%s [%s]%s%s" % (
            half_line,
            (click.style(" ERROR ", fg="red", bold=True)
             if is_error else click.style("SUCCESS", fg="green", bold=True)),
            summary_text,
            half_line
        ), err=is_error)

        return not is_error, result # [JORGE_GARCIA] added result to the return for further use 
开发者ID:bq,项目名称:web2board,代码行数:27,代码来源:run.py

示例3: __init__

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def __init__(self, *, stream, verbosity, warnings, tests,
                 output_format=OutputFormat.auto, failfast=False, suite):
        super().__init__(stream, False, verbosity)
        self.verbosity = verbosity
        self.catch_warnings = warnings
        self.failfast = failfast
        self.test_stats = []
        self.warnings = []
        self.notImplemented = []
        self.currently_running = {}
        # An index of all seen warnings to keep track
        # of repeated warnings.
        self._warnings = {}
        self.suite = suite

        if (output_format is OutputFormat.verbose or
                (output_format is OutputFormat.auto and self.verbosity > 1)):
            self.ren = VerboseRenderer(tests=tests, stream=stream)
        elif (output_format is OutputFormat.stacked or
                (output_format is OutputFormat.auto and stream.isatty() and
                 click.get_terminal_size()[0] > 60 and
                 os.name != 'nt')):
            self.ren = MultiLineRenderer(tests=tests, stream=stream)
        else:
            self.ren = SimpleRenderer(tests=tests, stream=stream) 
开发者ID:edgedb,项目名称:edgedb,代码行数:27,代码来源:runner.py

示例4: even_columns

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def even_columns(items, bold_first_column=False, separator_width=1):
    """Prints two columns with the second column padded so that it always
    begins on the same line, regardless of how long the first column is on the
    same line. Takes input as a list of two item tuples.
    """
    first_column_length = len(max([x[0] for x in items], key=len))
    for item in items:
        padding = first_column_length - len(item[0])
        separator = ' ' * separator_width
        first_column = click.style(item[0] + ' ' * padding,
                                   bold=bold_first_column)
        indent = len(item[0]) + padding + separator_width
        line = click.wrap_text(separator.join([first_column, item[1]]),
                               subsequent_indent=' ' * indent,
                               width=click.get_terminal_size()[0])
        click.echo(line) 
开发者ID:Hamuko,项目名称:cum,代码行数:18,代码来源:output.py

示例5: list

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def list(items):
    """Print out a list of items in columns much like `ls` in bash."""
    if items:
        width = click.get_terminal_size()[0]
        longest = len(max(items, key=len))
        columns = int(width // (longest + 0.5))
        rows = ceil(len(items) / columns)

        for row in range(rows):
            line = []
            for column in range(columns):
                i = rows * column + row
                if i >= len(items):
                    continue
                line.append(items[i].ljust(longest))
            click.echo(' '.join(line)) 
开发者ID:Hamuko,项目名称:cum,代码行数:18,代码来源:output.py

示例6: chapters

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def chapters(alias):
    """List all chapters for a manga series.

    Chapter listing will contain the flag value for the chapter ('n' for new,
    'i' for ignored and blank for downloaded), the chapter identifier ("chapter
    number") and the possible chapter title and group.
    """
    s = db.Series.alias_lookup(alias)
    if s.chapters:
        click.secho('f  chapter  title [group]', bold=True)
        for chapter in s.ordered_chapters:
            name_len = click.get_terminal_size()[0] - 11
            name = '{} {}'.format(chapter.title, chapter.group_tag)[:name_len]
            row = '{}  {:>7}  {}'.format(chapter.status, chapter.chapter, name)
            if row[0] == 'n':
                style = {'fg': 'white', 'bold': True}
            elif row[0] == ' ':
                style = {'bold': True}
            else:
                style = {}
            click.secho(row, **style) 
开发者ID:Hamuko,项目名称:cum,代码行数:23,代码来源:cum.py

示例7: log

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def log(msg: str, clear: bool = False, nl: bool = True) -> None:
    """Prints a message with elapsed time."""
    if clear:
        # Clear the output line to overwrite.
        width, _ = click.get_terminal_size()
        click.echo('\b\r', nl=False)
        click.echo(' ' * width, nl=False)
        click.echo('\b\r', nl=False)

    t = time.time() - BASE_TIME
    h = t // 3600
    t %= 3600
    m = t // 60
    t %= 60
    s = t

    click.echo('%02d:%02d:%02d | ' % (h, m, s), nl=False)
    click.echo(msg, nl=nl) 
开发者ID:kakaobrain,项目名称:torchgpipe,代码行数:20,代码来源:main.py

示例8: _item_out

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def _item_out(item, cols, col_info, detail, indent, max_col_width, err):
    indent_padding = " " * indent
    click.echo(indent_padding, nl=False, err=err)
    line_pos = indent
    for i, col in enumerate(cols):
        val = item[col]
        last_col = i == len(cols) - 1
        val = _pad_col_val(val, col, col_info) if not last_col else val
        line_pos = line_pos + len(val)
        if line_pos > max_col_width:
            click.echo(val[: -(line_pos - max_col_width)], nl=False, err=err)
            break
        else:
            click.echo(val, nl=False, err=err)
    click.echo(err=err)
    terminal_width = click.get_terminal_size()[0]
    for key in detail or []:
        click.echo(indent_padding, nl=False, err=err)
        formatted = _format_detail_val(item[key], indent, terminal_width)
        click.echo("  %s:%s" % (key, formatted), err=err) 
开发者ID:guildai,项目名称:guildai,代码行数:22,代码来源:cli.py

示例9: gnql_stats_formatter

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def gnql_stats_formatter(results, verbose):
    """Convert GNQL stats result into human-readable text."""
    template = JINJA2_ENV.get_template("gnql_stats.txt.j2")
    max_width, _ = click.get_terminal_size()
    return template.render(results=results, verbose=verbose, max_width=max_width) 
开发者ID:GreyNoise-Intelligence,项目名称:pygreynoise,代码行数:7,代码来源:formatter.py

示例10: analyze_formatter

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def analyze_formatter(result, verbose):
    """Conver analyze result into human-readable text."""
    template = JINJA2_ENV.get_template("analyze.txt.j2")
    max_width, _ = click.get_terminal_size()
    return template.render(result=result, verbose=verbose, max_width=max_width) 
开发者ID:GreyNoise-Intelligence,项目名称:pygreynoise,代码行数:7,代码来源:formatter.py

示例11: list_boards

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def list_boards(self):
        """Return a list with all the supported boards"""

        # Print table
        click.echo('\nSupported boards:\n')

        BOARDLIST_TPL = ('{board:25} {fpga:30} {arch:<8} '
                         '{type:<12} {size:<5} {pack:<10}')
        terminal_width, _ = click.get_terminal_size()

        click.echo('-' * terminal_width)
        click.echo(BOARDLIST_TPL.format(
            board=click.style('Board', fg='cyan'), fpga='FPGA',
            arch='Arch', type='Type', size='Size', pack='Pack'))
        click.echo('-' * terminal_width)

        for board in self.boards:
            fpga = self.boards.get(board).get('fpga')
            click.echo(BOARDLIST_TPL.format(
                board=click.style(board, fg='cyan'),
                fpga=fpga,
                arch=self.fpgas.get(fpga).get('arch'),
                type=self.fpgas.get(fpga).get('type'),
                size=self.fpgas.get(fpga).get('size'),
                pack=self.fpgas.get(fpga).get('pack')))

        click.secho(BOARDS_MSG, fg='green') 
开发者ID:FPGAwars,项目名称:apio,代码行数:29,代码来源:resources.py

示例12: list_examples

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def list_examples(self):
        if util.check_package(
            self.name,
            self.version,
            self.spec_version,
            self.examples_dir
        ):
            # examples = sorted(os.listdir(self.examples_dir))
            examples = [dirname(y).replace(self.examples_dir + sep, '')
                        for x in os.walk(self.examples_dir)
                        for y in glob.glob(util.safe_join(x[0], 'info'))]
            click.secho('')
            for example in examples:
                example_dir = util.safe_join(self.examples_dir, example)
                if isdir(example_dir):
                    info_path = util.safe_join(example_dir, 'info')
                    info = ''
                    if isfile(info_path):
                        with codecs.open(info_path, 'r', 'utf-8') as info_file:
                            info = info_file.read().replace('\n', '')
                    click.secho(' ' + example, fg='blue', bold=True)
                    click.secho('-' * click.get_terminal_size()[0])
                    click.secho(' ' + info)
                    click.secho('')
            click.secho(EXAMPLE_DIR_FILE, fg='green')
            click.secho(EXAMPLE_OF_USE_CAD, fg='green')
        else:
            return 1
        return 0 
开发者ID:FPGAwars,项目名称:apio,代码行数:31,代码来源:examples.py

示例13: networks

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def networks(o):
    content = []
    for i, network in enumerate(o['networks'].networks, start=1):  # type: Network
        first = '*' if network.is_default_network else ' '
        content.append((i, first, network.netaddr_ip.cidr, network.interface_name))
    header = ['#', 'default', 'cidr', 'interface']
    width, height = click.get_terminal_size()
    table = texttable.Texttable(max_width=width)
    table.set_deco(table.HEADER)
    table.header(header)
    table.add_rows(content, header=False)
    print(table.draw()) 
开发者ID:sumpfgottheit,项目名称:lanscan,代码行数:14,代码来源:lanscan.py

示例14: interfaces

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def interfaces(o):
    networks = o['networks']  # type: Networks
    content = []
    for i, interface in enumerate(networks.interfaces, start=1):
        content.append((i, interface['name'], interface['driver'], interface['hardware']))
    header = ['#', 'interface', 'driver', 'hardware']
    width, height = click.get_terminal_size()
    table = texttable.Texttable(max_width=width)
    table.set_deco(table.HEADER)
    table.header(header)
    table.add_rows(content, header=False)
    print(table.draw()) 
开发者ID:sumpfgottheit,项目名称:lanscan,代码行数:14,代码来源:lanscan.py

示例15: scan

# 需要导入模块: import click [as 别名]
# 或者: from click import get_terminal_size [as 别名]
def scan(o, arg_network, vendor, portscan):
    networks = o['networks']  # type: Networks
    n = None  # type: Network
    if arg_network is None:
        n = networks.default_network
    else:
        try:
            i = int(arg_network)
            if 1 <= i <= len(networks.networks):
                n = networks.networks[i - 1]
            else:
                exit_n("No network for id {} found. Try 'lanscan networks' to get networks.".format(i))
        except ValueError:
            try:
                _n = netaddr.IPNetwork(arg_network)
                click.echo("Scan for: {}".format(_n.cidr))
                n = networks.get_network_for_netaddr_ip(_n)
            except (KeyError, netaddr.AddrFormatError) as e:
                exit_n(str(e))

    logger.debug("Network: {}".format(n.cidr))
    n.scan(vendor, portscan)
    header = ['ip', 'name', 'mac', 'alive', 'vendor', 'open ports']
    content = [(host.ip, host.hostname, host.mac, str(host.is_alive), host.vendor, ", ".join(map(str, host.open_port_numbers))) for host in
               n.neighbours]
    width, height = click.get_terminal_size()
    table = texttable.Texttable(max_width=width)
    table.set_deco(table.HEADER)
    table.header(header)
    table.add_rows(content, header=False)
    print(table.draw()) 
开发者ID:sumpfgottheit,项目名称:lanscan,代码行数:33,代码来源:lanscan.py


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