Skip to content

Commit 94fba0b

Browse files
ui,popups: strip non-printable characters from labels
Commands with non-printable characters were misaligning the labels. Now these characters are exclude from the labels, and texts are displayed as a single line.
1 parent abdfd39 commit 94fba0b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

ui/opensnitch/dialogs/prompt.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,13 @@ def _check_advanced_toggled(self, state):
198198
def _button_clicked(self):
199199
self._stop_countdown()
200200

201-
def _set_elide_text(self, widget, text, max_size=132):
201+
def truncate_text(self, text, max_size=64):
202202
if len(text) > max_size:
203203
text = text[:max_size] + "..."
204+
return text
204205

206+
def _set_elide_text(self, widget, text, max_size=64):
207+
text = self.truncate_text(text, max_size)
205208
widget.setText(text)
206209

207210
def promptUser(self, connection, is_local, peer):
@@ -296,6 +299,12 @@ def _set_app_description(self, description):
296299
self.appDescriptionLabel.setFixedHeight(0)
297300
self.appDescriptionLabel.setText("")
298301

302+
self.appDescriptionLabel.setText(
303+
"".join(
304+
filter(str.isprintable, self.appDescriptionLabel.text())
305+
)
306+
)
307+
299308
def _set_app_path(self, app_name, app_args, con):
300309
# show the binary path if it's not part of the cmdline args:
301310
# cmdline: telnet 1.1.1.1 (path: /usr/bin/telnet.netkit)
@@ -314,17 +323,29 @@ def _set_app_path(self, app_name, app_args, con):
314323
self.appPathLabel.setVisible(False)
315324
self.appPathLabel.setText("")
316325

326+
self.appPathLabel.setText(
327+
"".join(
328+
filter(str.isprintable, self.appPathLabel.text())
329+
)
330+
)
331+
317332
def _set_app_args(self, app_name, app_args):
318333
# if the app name and the args are the same, there's no need to display
319334
# the args label (amule for example)
320335
if app_name.lower() != app_args:
321336
self.argsLabel.setVisible(True)
322-
self._set_elide_text(self.argsLabel, app_args)
337+
self._set_elide_text(self.argsLabel, app_args, 256)
323338
self.argsLabel.setToolTip(app_args)
324339
else:
325340
self.argsLabel.setVisible(False)
326341
self.argsLabel.setText("")
327342

343+
self.argsLabel.setText(
344+
"".join(
345+
filter(str.isprintable, self.argsLabel.text())
346+
)
347+
)
348+
328349
def _set_default_target(self, combo, con, app_name, app_args):
329350
# set appimage as default target if the process path starts with
330351
# /tmp/._mount
@@ -514,6 +535,7 @@ def _get_popup_message(self, app_name, con):
514535
the pop-up dialog. Example:
515536
curl is connecting to www.opensnitch.io on TCP port 443
516537
"""
538+
app_name = self.truncate_text(app_name)
517539
message = "<b>%s</b>" % app_name
518540
if not self._local:
519541
message = QC.translate("popups", "<b>Remote</b> process %s running on <b>%s</b>") % ( \

0 commit comments

Comments
 (0)