Skip to content

Commit f4f7b54

Browse files
committed
Wrap compact list output on terminal width minus 2
1 parent bf2b48d commit f4f7b54

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

todoman/formatters.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
from datetime import datetime
99
from datetime import timedelta
1010
from datetime import tzinfo
11+
from textwrap import wrap
1112
from time import mktime
1213
from typing import Iterable
1314

1415
import click
1516
import humanize
1617
import parsedatetime
1718
import pytz
19+
import shutil
1820
from dateutil.tz import tzlocal
1921

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

149151
table.append(item)
150152

153+
cols = 0
154+
try:
155+
cols = shutil.get_terminal_size().columns
156+
except shutil.Error:
157+
pass
158+
151159
ret = []
152160
for item in table:
153161
completed = item["completed"]
@@ -162,7 +170,17 @@ def compact_multiple(self, todos: Iterable[Todo], hide_list: bool = False) -> st
162170
summary = item["summary"]
163171
categories = item["categories"]
164172

165-
ret.append(f'[{completed}] {id} {pri}{due}{recurring}{percent}{summary}{categories}')
173+
leftcols = f'[{completed}] {id} {pri}{due}{recurring}{percent}'
174+
leftcolslen = 6 + id_width + pri_width + due_width + percent_width
175+
176+
# We only wrap if we have at least 20 extra columns...
177+
if cols > leftcolslen + 22:
178+
summary = wrap(summary + categories, cols - leftcolslen - 2)
179+
else:
180+
summary = [ leftcols + summary + categories ]
181+
ret.append(leftcols + summary[0])
182+
for i in summary[1:]:
183+
ret.append("".ljust(leftcolslen) + i)
166184

167185
return "\n".join(ret)
168186

0 commit comments

Comments
 (0)