44struct gdbpy_tui_window
49 tui_py_window *window;
52 bool is_valid ()
const;
55extern PyTypeObject gdbpy_tui_window_object_type
66 m_wrapper (
std::move (wrapper))
68 m_wrapper->window =
this;
80 m_window = std::move (user_window);
83 const char *
name ()
const override
85 return m_name.c_str ();
94 if (m_inner_window !=
nullptr)
96 wnoutrefresh (handle.get ());
97 touchwin (m_inner_window.get ());
104 void click (
int mouse_x,
int mouse_y,
int mouse_button)
override;
109 if (is_visible () && m_inner_window !=
nullptr)
111 werase (m_inner_window.get ());
118 void output (
const char *str,
bool full_window);
121 int viewport_width ()
const
123 return std::max (0, width - 2);
127 int viewport_height ()
const
129 return std::max (0, height - 2);
139 std::unique_ptr<WINDOW, curses_deleter> m_inner_window;
151gdbpy_tui_window::is_valid ()
const
156tui_py_window::~tui_py_window ()
162 if (m_window !=
nullptr
163 && PyObject_HasAttrString (m_window.get (),
"close"))
167 if (result ==
nullptr)
172 m_wrapper->window =
nullptr;
175 m_wrapper.reset (
nullptr);
176 m_window.reset (
nullptr);
180tui_py_window::rerender ()
186 int h = viewport_height ();
187 int w = viewport_width ();
188 if (h == 0 || w == 0)
192 m_inner_window.reset (
nullptr);
195 m_inner_window.reset (newwin (h, w, y + 1, x + 1));
197 if (PyObject_HasAttrString (m_window.get (),
"render"))
201 if (result ==
nullptr)
207tui_py_window::do_scroll_horizontal (
int num_to_scroll)
211 if (PyObject_HasAttrString (m_window.get (),
"hscroll"))
214 "i", num_to_scroll,
nullptr));
215 if (result ==
nullptr)
221tui_py_window::do_scroll_vertical (
int num_to_scroll)
225 if (PyObject_HasAttrString (m_window.get (),
"vscroll"))
228 "i", num_to_scroll,
nullptr));
229 if (result ==
nullptr)
235tui_py_window::click (
int mouse_x,
int mouse_y,
int mouse_button)
239 if (PyObject_HasAttrString (m_window.get (),
"click"))
242 "iii", mouse_x, mouse_y,
244 if (result ==
nullptr)
250tui_py_window::output (
const char *text,
bool full_window)
252 if (m_inner_window !=
nullptr)
255 werase (m_inner_window.get ());
257 tui_puts (text, m_inner_window.get ());
259 check_and_display_highlight_if_needed ();
270class gdbpy_tui_window_maker
274 explicit gdbpy_tui_window_maker (
gdbpy_ref<> &&constr)
275 : m_constr (
std::move (constr))
279 ~gdbpy_tui_window_maker ();
281 gdbpy_tui_window_maker (gdbpy_tui_window_maker &&other) noexcept
282 : m_constr (std::move (other.m_constr))
286 gdbpy_tui_window_maker (
const gdbpy_tui_window_maker &other)
289 m_constr = other.m_constr;
292 gdbpy_tui_window_maker &operator= (gdbpy_tui_window_maker &&other)
294 m_constr = std::move (other.m_constr);
298 gdbpy_tui_window_maker &operator= (
const gdbpy_tui_window_maker &other)
301 m_constr = other.m_constr;
313gdbpy_tui_window_maker::~gdbpy_tui_window_maker ()
316 m_constr.reset (
nullptr);
320gdbpy_tui_window_maker::operator() (
const char *win_name)
325 (PyObject_New (gdbpy_tui_window, &gdbpy_tui_window_object_type));
326 if (wrapper ==
nullptr)
332 std::unique_ptr<tui_py_window> window
333 (
new tui_py_window (win_name, wrapper));
336 (PyObject_CallFunctionObjArgs (m_constr.get (),
339 if (user_window ==
nullptr)
345 window->set_user_window (std::move (user_window));
347 return window.release ();
355 static const char *keywords[] = {
"name",
"constructor",
nullptr };
369 catch (
const gdb_exception &except)
382#define REQUIRE_WINDOW(Window) \
384 if (!(Window)->is_valid ()) \
385 return PyErr_Format (PyExc_RuntimeError, \
386 _("TUI window is invalid.")); \
391#define REQUIRE_WINDOW_FOR_SETTER(Window) \
393 if (!(Window)->is_valid ()) \
395 PyErr_Format (PyExc_RuntimeError, \
396 _("TUI window is invalid.")); \
406 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
408 if (win->is_valid ())
417 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
419 REQUIRE_WINDOW (win);
421 win->window->erase ();
430 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
434 if (!PyArg_ParseTuple (args,
"s|i", &text, &full_window))
437 REQUIRE_WINDOW (win);
439 win->window->output (text, full_window);
446gdbpy_tui_width (
PyObject *self,
void *closure)
448 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
449 REQUIRE_WINDOW (win);
452 return result.release ();
457gdbpy_tui_height (
PyObject *self,
void *closure)
459 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
460 REQUIRE_WINDOW (win);
463 return result.release ();
468gdbpy_tui_title (
PyObject *self,
void *closure)
470 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
471 REQUIRE_WINDOW (win);
479 gdbpy_tui_window *win = (gdbpy_tui_window *) self;
481 REQUIRE_WINDOW_FOR_SETTER (win);
483 if (newvalue ==
nullptr)
485 PyErr_Format (PyExc_TypeError, _(
"Cannot delete \"title\" attribute."));
489 gdb::unique_xmalloc_ptr<char>
value
491 if (
value ==
nullptr)
494 win->window->title =
value.get ();
500 {
"width", gdbpy_tui_width, NULL,
"Width of the window.", NULL },
501 {
"height", gdbpy_tui_height, NULL,
"Height of the window.", NULL },
502 {
"title", gdbpy_tui_title, gdbpy_tui_set_title,
"Title of the window.",
507static PyMethodDef tui_object_methods[] =
509 {
"is_valid", gdbpy_tui_is_valid, METH_NOARGS,
510 "is_valid () -> Boolean\n\
511Return true if this TUI window is valid, false if not." },
512 {
"erase", gdbpy_tui_erase, METH_NOARGS,
513 "Erase the TUI window." },
514 {
"write", (PyCFunction) gdbpy_tui_write, METH_VARARGS,
515 "Append a string to the TUI window." },
519PyTypeObject gdbpy_tui_window_object_type =
521 PyVarObject_HEAD_INIT (NULL, 0)
523 sizeof (gdbpy_tui_window),
540 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
541 "GDB TUI window object",
568 gdbpy_tui_window_object_type.tp_new = PyType_GenericNew;
569 if (PyType_Ready (&gdbpy_tui_window_object_type) < 0)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
int gdbpy_initialize_tui()
gdbpy_ref host_string_to_python_string(const char *str)
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
void gdbpy_convert_exception(const struct gdb_exception &exception)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
void gdbpy_print_stack(void)
#define PyObject_CallMethod
PyObject * gdbpy_register_tui_window(PyObject *self, PyObject *args, PyObject *kw)
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
void check_and_display_highlight_if_needed()
DISABLE_COPY_AND_ASSIGN(tui_win_info)
virtual void do_scroll_horizontal(int num_to_scroll)=0
virtual const char * name() const =0
virtual void click(int mouse_x, int mouse_y, int mouse_button)
virtual void do_scroll_vertical(int num_to_scroll)=0
virtual void refresh_window()
void tui_puts(const char *string, WINDOW *w)
void tui_register_window(const char *name, window_factory &&factory)
void tui_wrefresh(WINDOW *win)