diff options
author | Tom Tromey <tom@tromey.com> | 2020-09-27 20:30:30 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2020-09-27 20:30:31 -0600 |
commit | 149830c137f351cb41888f87493cc42a72dbeac7 (patch) | |
tree | af25aff2c3a27b1a9b38fbee4bfa73387d2f3f69 /gdb/python | |
parent | 5f278258ccae6a666c72de709a3171975fbaeb05 (diff) | |
download | fsf-binutils-gdb-149830c137f351cb41888f87493cc42a72dbeac7.zip fsf-binutils-gdb-149830c137f351cb41888f87493cc42a72dbeac7.tar.gz fsf-binutils-gdb-149830c137f351cb41888f87493cc42a72dbeac7.tar.bz2 |
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.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-tui.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index 8a24f2f..58f9c5e 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -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 ()); } |