Skip to content

Commit

Permalink
Wrap compact list output on terminal width minus 2
Browse files Browse the repository at this point in the history
  • Loading branch information
elric1 committed Mar 3, 2024
1 parent bf2b48d commit f4f7b54
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion todoman/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
from datetime import datetime
from datetime import timedelta
from datetime import tzinfo
from textwrap import wrap
from time import mktime
from typing import Iterable

import click
import humanize
import parsedatetime
import pytz
import shutil
from dateutil.tz import tzlocal

from todoman.model import Todo
Expand Down Expand Up @@ -148,6 +150,12 @@ def compact_multiple(self, todos: Iterable[Todo], hide_list: bool = False) -> st

table.append(item)

cols = 0
try:
cols = shutil.get_terminal_size().columns
except shutil.Error:
pass

ret = []
for item in table:
completed = item["completed"]
Expand All @@ -162,7 +170,17 @@ def compact_multiple(self, todos: Iterable[Todo], hide_list: bool = False) -> st
summary = item["summary"]
categories = item["categories"]

ret.append(f'[{completed}] {id} {pri}{due}{recurring}{percent}{summary}{categories}')
leftcols = f'[{completed}] {id} {pri}{due}{recurring}{percent}'
leftcolslen = 6 + id_width + pri_width + due_width + percent_width

# We only wrap if we have at least 20 extra columns...
if cols > leftcolslen + 22:
summary = wrap(summary + categories, cols - leftcolslen - 2)
else:
summary = [ leftcols + summary + categories ]
ret.append(leftcols + summary[0])
for i in summary[1:]:
ret.append("".ljust(leftcolslen) + i)

return "\n".join(ret)

Expand Down

0 comments on commit f4f7b54

Please sign in to comment.