Add an option to disable OSC 8

This commit is contained in:
Kovid Goyal 2020-09-03 21:55:02 +05:30
parent 9293d9b0ed
commit 399a1f8fee
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 24 additions and 7 deletions

View File

@ -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. 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=_(''' o('term', 'xterm-kitty', long_text=_('''
The value of the TERM environment variable to set. Changing this can break many 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 terminal programs, only change it if you know what you are doing, not because

View File

@ -381,13 +381,14 @@ selection_has_screen_line(const Selections *selections, const int y) {
void void
set_active_hyperlink(Screen *self, char *id, char *url) { set_active_hyperlink(Screen *self, char *id, char *url) {
(void)id; if (OPT(allow_hyperlinks)) {
if (!url || !url[0]) { if (!url || !url[0]) {
self->active_hyperlink_id = 0; self->active_hyperlink_id = 0;
return; 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 hyperlink_id_type
remap_hyperlink_ids(Screen *self, hyperlink_id_type *map) { remap_hyperlink_ids(Screen *self, hyperlink_id_type *map) {
@ -1956,7 +1957,7 @@ screen_open_url(Screen *self) {
if (hid) { if (hid) {
const char *url = get_hyperlink_for_id(self, hid); const char *url = get_hyperlink_for_id(self, hid);
if (url) { if (url) {
call_boss(open_url, "s", url); CALLBACK("open_url", "sH", url, hid);
return true; return true;
} }
} }
@ -1967,7 +1968,7 @@ screen_open_url(Screen *self) {
} }
bool found = false; bool found = false;
if (PyUnicode_Check(text)) { if (PyUnicode_Check(text)) {
call_boss(open_url, "O", text); CALLBACK("open_url", "sH", text, 0);
found = true; found = true;
} }
Py_CLEAR(text); Py_CLEAR(text);

View File

@ -701,6 +701,7 @@ PYWRAP1(set_options) {
S(force_ltr, PyObject_IsTrue); S(force_ltr, PyObject_IsTrue);
S(resize_draw_strategy, PyLong_AsLong); S(resize_draw_strategy, PyLong_AsLong);
S(resize_in_steps, PyObject_IsTrue); S(resize_in_steps, PyObject_IsTrue);
S(allow_hyperlinks, PyObject_IsTrue);
S(pointer_shape_when_grabbed, pointer_shape); S(pointer_shape_when_grabbed, pointer_shape);
GA(tab_bar_style); GA(tab_bar_style);

View File

@ -63,6 +63,7 @@ typedef struct {
bool close_on_child_death; bool close_on_child_death;
bool window_alert_on_bell; bool window_alert_on_bell;
bool debug_keyboard; bool debug_keyboard;
bool allow_hyperlinks;
monotonic_t resize_debounce_time; monotonic_t resize_debounce_time;
MouseShape pointer_shape_when_grabbed; MouseShape pointer_shape_when_grabbed;
struct { struct {

View File

@ -489,6 +489,9 @@ class Window:
def use_utf8(self, on: bool) -> None: def use_utf8(self, on: bool) -> None:
get_boss().child_monitor.set_iutf8_winid(self.id, on) 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: def focus_changed(self, focused: bool) -> None:
if self.destroyed: if self.destroyed:
return return

View File

@ -40,11 +40,15 @@ class Callbacks:
def desktop_notify(self, osc_code: int, raw_data: str) -> None: def desktop_notify(self, osc_code: int, raw_data: str) -> None:
self.notifications.append((osc_code, raw_data)) 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): def clear(self):
self.wtcbuf = b'' self.wtcbuf = b''
self.iconbuf = self.titlebuf = self.colorbuf = self.ctbuf = '' self.iconbuf = self.titlebuf = self.colorbuf = self.ctbuf = ''
self.iutf8 = True self.iutf8 = True
self.notifications = [] self.notifications = []
self.open_urls = []
def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()): def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()):