]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add keywords to TuiWindow.write
authorTom Tromey <tom@tromey.com>
Wed, 13 Dec 2023 05:49:52 +0000 (22:49 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 30 Dec 2023 19:21:44 +0000 (12:21 -0700)
The gdb docs promise that methods with more than two or more arguments
will accept keywords.  However, I found that TuiWindow.write didn't
allow them.  This patch adds the missing support.

gdb/python/py-tui.c
gdb/testsuite/gdb.python/tui-window.py

index a84e38a05635b4b6400df189be0913f8f711925e..a28137ee78fb99e0e6275483772ea3f4251d10ba 100644 (file)
@@ -476,13 +476,16 @@ gdbpy_tui_erase (PyObject *self, PyObject *args)
 
 /* Python function that writes some text to a TUI window.  */
 static PyObject *
-gdbpy_tui_write (PyObject *self, PyObject *args)
+gdbpy_tui_write (PyObject *self, PyObject *args, PyObject *kw)
 {
+  static const char *keywords[] = { "string", "full_window", nullptr };
+
   gdbpy_tui_window *win = (gdbpy_tui_window *) self;
   const char *text;
   int full_window = 0;
 
-  if (!PyArg_ParseTuple (args, "s|i", &text, &full_window))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords,
+                                       &text, &full_window))
     return nullptr;
 
   REQUIRE_WINDOW (win);
@@ -562,7 +565,7 @@ static PyMethodDef tui_object_methods[] =
 Return true if this TUI window is valid, false if not." },
   { "erase", gdbpy_tui_erase, METH_NOARGS,
     "Erase the TUI window." },
-  { "write", (PyCFunction) gdbpy_tui_write, METH_VARARGS,
+  { "write", (PyCFunction) gdbpy_tui_write, METH_VARARGS | METH_KEYWORDS,
     "Append a string to the TUI window." },
   { NULL } /* Sentinel.  */
 };
index dc72cc4c0f72c2cfe0671c90b82234f149a5aeab..47c4403bc483e930f5efb834a37fc73a70d932a4 100644 (file)
@@ -32,7 +32,8 @@ class TestWindow:
         self.win.erase()
         w = self.win.width
         h = self.win.height
-        self.win.write("Test: " + str(self.count) + " " + str(w) + "x" + str(h))
+        self.win.write(string="Test: " + str(self.count) + " " + str(w) + "x" + str(h),
+                       full_window=False)
         self.count = self.count + 1
 
     # Tries to delete the title attribute.  GDB will throw an error.