def print_entries(entries, trim, reverse_order=False):
"""
Builds the output and prints all entries.
"""
maxlength = sys.maxsize
if trim:
try:
maxlength = os.get_terminal_size().columns
# piped output to file or other process
except OSError:
maxlength = sys.maxsize
size_entry_id = 0
show_read_column = False
show_starred_column = False
if len(entries) > 0:
size_entry_id = len(str(entries[0].entry_id))
entry_id_last = len(str(entries[len(entries) - 1].entry_id))
if entry_id_last > size_entry_id:
size_entry_id = entry_id_last
for item in entries:
if item.read:
show_read_column = True
if item.starred:
show_starred_column = True
if reverse_order:
entries = reversed(entries)
for item in entries:
entry_id = str(item.entry_id).rjust(size_entry_id)
read = " "
if item.read:
if platform.system() == "Windows":
read = "r"
else:
read = "?"
starred = " "
if item.starred:
starred = "*"
title = item.title
line = entry_id
if show_read_column or show_starred_column:
line = line + " "
if show_read_column:
line = line + read
if show_starred_column:
line = line + starred
line = line + " {0}".format(title)
print(line[0:maxlength])
评论列表
文章目录