def build_table(self, view_entries, limit, pager, format_method,
build_urls=True, print_output=True):
"""Build the table used for the gh view command.
:type view_entries: list
:param view_entries: A list of `github3` items.
:type limit: int
:param limit: Determines the number of items to show.
:type format_method: callable
:param format_method: A method called to format each item in the table.
:type build_urls: bool
:param build_urls: Determines whether to build urls for the
gh view # command.
:type print_output: bool
:param print_output: determines whether to print the output
(True) or return the output as a string (False).
:rtype: str
:return: the output if print_output is True, else, return None.
"""
if build_urls:
self.build_table_urls(view_entries)
index = 0
output = ''
for view_entry in view_entries:
index += 1
view_entry.index = index
output += format_method(view_entry) + '\n'
if index >= limit:
break
if build_urls:
if len(view_entries) > limit:
output += click.style((' <Hiding ' +
str(len(view_entries) - limit) +
' item(s) with the -l/--limit flag>\n'),
fg=self.config.clr_message)
if index == 0:
output += click.style('No results found',
fg=self.config.clr_message)
elif build_urls:
output += click.style(self.create_tip(index))
else:
output += click.style('')
if print_output:
if pager:
color = None
if platform.system() == 'Windows':
color = True
# Strip out Unicode, which seems to have issues on
# Windows with click.echo_via_pager.
output = re.sub(r'[^\x00-\x7F]+', '', output)
click.echo_via_pager(output, color)
else:
click.secho(output)
return None
else:
return output
评论列表
文章目录