本文整理匯總了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')))
示例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
示例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)
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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')
示例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
示例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())
示例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())
示例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())