public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/6] Use an inner window in tui_py_window
Date: Sat, 27 Jun 2020 15:20:47 -0600	[thread overview]
Message-ID: <20200627212051.6155-3-tom@tromey.com> (raw)
In-Reply-To: <20200627212051.6155-1-tom@tromey.com>

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-06-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.
---
 gdb/ChangeLog       | 10 ++++++++
 gdb/python/py-tui.c | 59 ++++++++++++++++++++++++---------------------
 2 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 95c71f1d2dd..3f44cfc3d12 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -86,15 +86,23 @@ class tui_py_window : public tui_win_info
   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 @@ class tui_py_window : public tui_win_info
 
 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 ());
 }
 
 \f
-- 
2.17.2


  parent reply	other threads:[~2020-06-27 21:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-27 21:20 [PATCH 0/6] Handle UTF-8 in TUI source windows Tom Tromey
2020-06-27 21:20 ` [PATCH 1/6] Remove test duplicate from gdb.tui Tom Tromey
2020-06-27 21:20 ` Tom Tromey [this message]
2020-06-27 21:20 ` [PATCH 3/6] Remove a call to show_source_line from TUI Tom Tromey
2020-06-27 21:20 ` [PATCH 4/6] Use a curses pad for source and disassembly windows Tom Tromey
2020-06-27 21:20 ` [PATCH 5/6] Use ISCNTRL in tui_copy_source_line Tom Tromey
2020-06-27 21:20 ` [PATCH 6/6] Rewrite tui_puts Tom Tromey
2020-07-10 20:45 ` [PATCH 0/6] Handle UTF-8 in TUI source windows Tom Tromey
2020-09-28  2:29   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200627212051.6155-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).