From 399a1f8feea6d7d1ecec394d96f10ca8a8bb62ec Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 3 Sep 2020 21:55:02 +0530 Subject: [PATCH] Add an option to disable OSC 8 --- kitty/config_data.py | 7 +++++++ kitty/screen.c | 15 ++++++++------- kitty/state.c | 1 + kitty/state.h | 1 + kitty/window.py | 3 +++ kitty_tests/__init__.py | 4 ++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/kitty/config_data.py b/kitty/config_data.py index 7b970a43d..417bf3e0e 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -1144,6 +1144,13 @@ that enabling the read functionality is a security risk as it means that any program, even one running on a remote server via SSH can read your clipboard. ''')) + +o('allow_hyperlinks', True, long_text=_(''' +Process hyperlink (OSC 8) escape sequences. If disabled OSC 8 escape +sequences are ignored. Otherwise they become clickable links, that you +can click by holding down ctrl+shift and clicking with the mouse''')) + + o('term', 'xterm-kitty', long_text=_(''' The value of the TERM environment variable to set. Changing this can break many terminal programs, only change it if you know what you are doing, not because diff --git a/kitty/screen.c b/kitty/screen.c index dd40b458b..bf32d9238 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -381,12 +381,13 @@ selection_has_screen_line(const Selections *selections, const int y) { void set_active_hyperlink(Screen *self, char *id, char *url) { - (void)id; - if (!url || !url[0]) { - self->active_hyperlink_id = 0; - return; + if (OPT(allow_hyperlinks)) { + if (!url || !url[0]) { + self->active_hyperlink_id = 0; + return; + } + self->active_hyperlink_id = get_id_for_hyperlink(self, id, url); } - self->active_hyperlink_id = get_id_for_hyperlink(self, id, url); } hyperlink_id_type @@ -1956,7 +1957,7 @@ screen_open_url(Screen *self) { if (hid) { const char *url = get_hyperlink_for_id(self, hid); if (url) { - call_boss(open_url, "s", url); + CALLBACK("open_url", "sH", url, hid); return true; } } @@ -1967,7 +1968,7 @@ screen_open_url(Screen *self) { } bool found = false; if (PyUnicode_Check(text)) { - call_boss(open_url, "O", text); + CALLBACK("open_url", "sH", text, 0); found = true; } Py_CLEAR(text); diff --git a/kitty/state.c b/kitty/state.c index 30090a195..91a1d805f 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -701,6 +701,7 @@ PYWRAP1(set_options) { S(force_ltr, PyObject_IsTrue); S(resize_draw_strategy, PyLong_AsLong); S(resize_in_steps, PyObject_IsTrue); + S(allow_hyperlinks, PyObject_IsTrue); S(pointer_shape_when_grabbed, pointer_shape); GA(tab_bar_style); diff --git a/kitty/state.h b/kitty/state.h index 13729bf04..5d4c5ca04 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -63,6 +63,7 @@ typedef struct { bool close_on_child_death; bool window_alert_on_bell; bool debug_keyboard; + bool allow_hyperlinks; monotonic_t resize_debounce_time; MouseShape pointer_shape_when_grabbed; struct { diff --git a/kitty/window.py b/kitty/window.py index 026956a18..04450c13b 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -489,6 +489,9 @@ class Window: def use_utf8(self, on: bool) -> None: get_boss().child_monitor.set_iutf8_winid(self.id, on) + def open_url(self, url: str, hyperlink_id: int) -> None: + get_boss().open_url(url) + def focus_changed(self, focused: bool) -> None: if self.destroyed: return diff --git a/kitty_tests/__init__.py b/kitty_tests/__init__.py index 7189fccec..e7d99c4e5 100644 --- a/kitty_tests/__init__.py +++ b/kitty_tests/__init__.py @@ -40,11 +40,15 @@ class Callbacks: def desktop_notify(self, osc_code: int, raw_data: str) -> None: self.notifications.append((osc_code, raw_data)) + def open_url(self, url: str, hyperlink_id: int) -> None: + self.open_urls.append((url, hyperlink_id)) + def clear(self): self.wtcbuf = b'' self.iconbuf = self.titlebuf = self.colorbuf = self.ctbuf = '' self.iutf8 = True self.notifications = [] + self.open_urls = [] def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()):