From 9a878c9edc288d3014712a2e57567f4f617bbef6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 06:01:59 +0000 Subject: [PATCH] Accept keyword arguments in draw_single_line_of_text, use max_width=True in window.py, remove changelog entry Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/9a89a6c8-4bc2-4f11-9947-55b713b15348 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- docs/changelog.rst | 2 -- kitty/glfw.c | 7 ++++--- kitty/window.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 93073c871..1b930e61a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -185,8 +185,6 @@ Detailed list of changes - Allow optionally dragging URLs with the mouse, see :sc:`start_simple_selection` (:pull:`9804`) -- Improve ``draw_single_line_of_text()`` to accept an optional ``max_width`` parameter. When set, the width is treated as a maximum and reduced to the actual text width if smaller. The function now returns both pixel data and actual width used. - - Fix thickness of diagonal lines in box drawing characters not the same as horizontal/vertical lines (:iss:`9719`) - Graphics protocol: Fix crash when handling invalid PNG image with direct transmission diff --git a/kitty/glfw.c b/kitty/glfw.c index e7c502a1b..89bacf884 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -3087,12 +3087,13 @@ grab_keyboard(PyObject *self UNUSED, PyObject *action) { } static PyObject* -draw_single_line_of_text(PyObject *self UNUSED, PyObject *args) { +draw_single_line_of_text(PyObject *self UNUSED, PyObject *args, PyObject *kw) { unsigned long long os_window_id; const char *text; unsigned int fg, bg; int width, padding_y = 2, max_width = 0; - if (!PyArg_ParseTuple(args, "KsIIi|ip", &os_window_id, &text, &fg, &bg, &width, &padding_y, &max_width)) return NULL; + static const char* kwlist[] = {"os_window_id", "text", "fg", "bg", "width", "padding_y", "max_width", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "KsIIi|ip", (char**)kwlist, &os_window_id, &text, &fg, &bg, &width, &padding_y, &max_width)) return NULL; OSWindow *w = os_window_for_id(os_window_id); if (!w || !w->fonts_data) { PyErr_SetString(PyExc_KeyError, "OS Window with specified id does not exist or has no fonts data"); @@ -3256,7 +3257,7 @@ static PyMethodDef module_methods[] = { {"create_os_window", (PyCFunction)(void (*) (void))(create_os_window), METH_VARARGS | METH_KEYWORDS, NULL}, {"start_drag_with_data", (PyCFunction)(void (*) (void))(start_drag_with_data), METH_VARARGS | METH_KEYWORDS, NULL}, METHODB(change_drag_thumbnail, METH_VARARGS), - METHODB(draw_single_line_of_text, METH_VARARGS), + {"draw_single_line_of_text", (PyCFunction)(void (*) (void))(draw_single_line_of_text), METH_VARARGS | METH_KEYWORDS, NULL}, METHODB(set_default_window_icon, METH_VARARGS), METHODB(set_os_window_icon, METH_VARARGS), METHODB(set_clipboard_data_types, METH_VARARGS), diff --git a/kitty/window.py b/kitty/window.py index baaf1b88f..39e27e468 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1321,7 +1321,7 @@ class Window: fg = color_as_int(self.screen.color_profile.default_fg) bg = color_as_int(self.screen.color_profile.default_bg) width = self.geometry.right - self.geometry.left - pixels, width = draw_single_line_of_text(self.os_window_id, url, 0xff000000 | fg, 0xff000000 | bg, width) + pixels, width = draw_single_line_of_text(self.os_window_id, url, 0xff000000 | fg, 0xff000000 | bg, width, max_width=True) height = len(pixels) // (width * 4) thumbnails = ((pixels, width, height),) drag_data = {'text/uri-list': (url + '\r\n').encode()}