Skip to content

Commit 2f089ca

Browse files
committed
messages: Simplify ellipsizing, remove max-width-chars restriction,
detect urls and make them clickable in the label.
1 parent b539df2 commit 2f089ca

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

resources/op-item.ui

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@
248248
<property name="selectable">True</property>
249249
<property name="wrap">True</property>
250250
<property name="wrap-mode">word-char</property>
251-
<property name="max_width_chars">80</property>
252251
<property name="xalign">0</property>
253252
</object>
254253
<packing>

src/warpinator.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import locale
66
import gettext
77
import functools
8+
import html
89
import logging
910
import time
1011
import math
@@ -187,29 +188,30 @@ def refresh_status_widgets(self):
187188
self.op_transfer_problem_label.set_text(_("Some files not found"))
188189
elif self.op.status == OpStatus.FINISHED:
189190
if isinstance(self.op, TextMessageOp):
190-
label_length = 80
191-
lines_left = 4
191+
label = ""
192192
lines = self.op.message.split("\n")
193-
msg = ""
194-
for l in lines:
195-
wrapped_lines = math.ceil(len(l) / label_length)
196-
if wrapped_lines > lines_left:
197-
msg += "\n" + l[:label_length*lines_left-3] + "..."
193+
for i in range(len(lines)):
194+
print(i, len(lines))
195+
label += f"{lines[i]}"
196+
if i == 3 and len(lines) > 4:
197+
label += "..."
198198
break
199199
else:
200-
msg += "\n" + l
201-
lines_left -= wrapped_lines
202-
if lines_left < 1:
203-
last_line_len = len(l) % label_length
204-
if last_line_len == 0 and len(l) > 0:
205-
last_line_len = label_length
206-
if len(lines) > 4:
207-
if last_line_len > label_length-3:
208-
msg = msg[:-last_line_len+label_length-3]
209-
msg += "..."
210-
break
211-
msg = msg[1:] # skip first \n
212-
self.op_transfer_text_message.set_text(msg)
200+
if i + 1 < len(lines):
201+
label += "\n"
202+
203+
label = html.escape(label)
204+
url_pattern = r'(https?://[^\s<>"{}|\\^`\[\]]+|www\.[^\s<>"{}|\\^`\[\]]+)'
205+
def replace_url(match):
206+
url = match.group(0)
207+
# If URL doesn't start with http, add https://
208+
href = url if url.startswith('http') else f'https://{url}'
209+
return f'<a href="{href}">{url}</a>'
210+
211+
# Replace URLs with Pango markup
212+
markup = re.sub(url_pattern, replace_url, label)
213+
214+
self.op_transfer_text_message.set_markup(markup)
213215
else:
214216
self.op_transfer_status_message.set_text(_("Completed"))
215217
elif self.op.status == OpStatus.FINISHED_WARNING:

0 commit comments

Comments
 (0)