Use an inner window in tui_py_window

This changes tui_py_window to create an inner curses window.  This
greatly simplifies tui_py_window::output, beacuse it no longer needs
to be careful to avoid overwriting the window's border.  This patch
also makes it a bit easier for a later patch to rewrite
tui_copy_source_line.

gdb/ChangeLog
2020-09-27  Tom Tromey  <tom@tromey.com>

	* python/py-tui.c (class tui_py_window) <refresh_window>: New
	method.
	<erase>: Update.
	<cursor_x, cursor_y>: Remove.
	<m_inner_window>: New member.
	(tui_py_window::rerender): Create inner window.
	(tui_py_window::output): Write to inner window.
This commit is contained in:
Tom Tromey
2020-09-27 20:30:30 -06:00
parent 5f278258cc
commit 149830c137
2 changed files with 42 additions and 27 deletions

View File

@ -86,15 +86,23 @@ public:
void do_scroll_vertical (int num_to_scroll) override;
void do_scroll_horizontal (int num_to_scroll) override;
void refresh_window () override
{
tui_win_info::refresh_window ();
if (m_inner_window != nullptr)
{
touchwin (m_inner_window.get ());
tui_wrefresh (m_inner_window.get ());
}
}
/* Erase and re-box the window. */
void erase ()
{
if (is_visible ())
if (is_visible () && m_inner_window != nullptr)
{
werase (handle.get ());
werase (m_inner_window.get ());
check_and_display_highlight_if_needed ();
cursor_x = 0;
cursor_y = 0;
}
}
@ -115,13 +123,13 @@ public:
private:
/* Location of the cursor. */
int cursor_x = 0;
int cursor_y = 0;
/* The name of this window. */
std::string m_name;
/* We make our own inner window, so that it is easy to print without
overwriting the border. */
std::unique_ptr<WINDOW, curses_deleter> m_inner_window;
/* The underlying Python window object. */
gdbpy_ref<> m_window;
@ -155,8 +163,21 @@ tui_py_window::~tui_py_window ()
void
tui_py_window::rerender ()
{
tui_win_info::rerender ();
gdbpy_enter enter_py (get_current_arch (), current_language);
int h = viewport_height ();
int w = viewport_width ();
if (h == 0 || w == 0)
{
/* The window would be too small, so just remove the
contents. */
m_inner_window.reset (nullptr);
return;
}
m_inner_window.reset (newwin (h, w, y + 1, x + 1));
if (PyObject_HasAttrString (m_window.get (), "render"))
{
gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "render",
@ -197,27 +218,11 @@ tui_py_window::do_scroll_vertical (int num_to_scroll)
void
tui_py_window::output (const char *text)
{
int vwidth = viewport_width ();
while (cursor_y < viewport_height () && *text != '\0')
if (m_inner_window != nullptr)
{
wmove (handle.get (), cursor_y + 1, cursor_x + 1);
std::string line = tui_copy_source_line (&text, 0, 0,
vwidth - cursor_x, 0);
tui_puts (line.c_str (), handle.get ());
if (*text == '\n')
{
++text;
++cursor_y;
cursor_x = 0;
}
else
cursor_x = getcurx (handle.get ()) - 1;
tui_puts (text, m_inner_window.get ());
tui_wrefresh (m_inner_window.get ());
}
wrefresh (handle.get ());
}