gdb: Add new 'layout cli' command.

Message ID cdefb1cb466c17bb9668b60f04fb1ea3b7bfe028.1432245947.git.andrew.burgess@embecosm.com
State Dropped
Headers

Commit Message

Andrew Burgess May 21, 2015, 10:06 p.m. UTC
  It always seemed a little strange to me that it's possible to enter
TUI mode by typing commands at the CLI, but to leave TUI mode you need
to know the readline bindings.

This commit adds a new 'layout cli' command to leave tui mode, which
is in addition to the readline bindings.

--

Add a new 'layout cli' command that disables tui mode and returns the
user to cli mode, this is an alternative method of leaving tui mode
which doesn't require knowing the readline bindings.

gdb/ChangeLog:

	* tui/tui-layout.c (_initialize_tui_layout): Add 'cli'
	description.
	(tui_set_layout_by_name): Check for 'cli' choice.
	(layout_completer): Add 'cli' choice.
	* NEWS (New commands): Mention new 'layout cli' command.

gdb/doc/ChangeLog:

	* gdb.texinfo (TUI Commands): Add 'layout cli' details.
---
 gdb/ChangeLog        | 8 ++++++++
 gdb/NEWS             | 3 +++
 gdb/doc/ChangeLog    | 4 ++++
 gdb/doc/gdb.texinfo  | 3 +++
 gdb/tui/tui-layout.c | 8 ++++++--
 5 files changed, 24 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves May 22, 2015, 12:29 a.m. UTC | #1
On 05/21/2015 11:06 PM, Andrew Burgess wrote:
> It always seemed a little strange to me that it's possible to enter
> TUI mode by typing commands at the CLI, but to leave TUI mode you need
> to know the readline bindings.

Agreed.

> 
> This commit adds a new 'layout cli' command to leave tui mode, which
> is in addition to the readline bindings.

IIUC, "layout prev/next" doesn't cycle this layout.  That seems odd.
I think it either should, or this should be a separate command.

A "layout cli" layout could reasonably be a layout that (with tui enabled)
only showed the console window, with status line at the top, similar to
"layout src; winheight src 3" (3 just because one can't go lower
than 3).  I supposed we could leave room for adding that later by calling
this one e.g., "layout off".

I notice that we have no blessed way to go back to the same layout that
was current when the tui was last active.  "layout current" would be odd,
given that the current is "cli"... Hmm, "layout last" (like "cd -")?
Not sure...

A separate command ("tui enable/disable"? "set tui enabled on/off"?)
would be a more direct mapping to the readline bindings.

What do you think?

Thanks,
Pedro Alves
  
Eli Zaretskii May 22, 2015, 7:14 a.m. UTC | #2
> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Cc: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Fri, 22 May 2015 00:06:25 +0200
> 
> It always seemed a little strange to me that it's possible to enter
> TUI mode by typing commands at the CLI, but to leave TUI mode you need
> to know the readline bindings.
> 
> This commit adds a new 'layout cli' command to leave tui mode, which
> is in addition to the readline bindings.

OK for the documentation parts.

Thanks.
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 42ef67d..b1c1598 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@ 
 2015-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* tui/tui-layout.c (_initialize_tui_layout): Add 'cli'
+	description.
+	(tui_set_layout_by_name): Check for 'cli' choice.
+	(layout_completer): Add 'cli' choice.
+	* NEWS (New commands): Mention new 'layout cli' command.
+
+2015-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* tui/tui-regs.c (tui_reg_next_command): Use NULL not 0.
 
 2015-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
diff --git a/gdb/NEWS b/gdb/NEWS
index e08dd0d..1f90a89 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -82,6 +82,9 @@  record bts
 compile print
   Evaluate expression by using the compiler and print result.
 
+layout cli
+  Leave tui mode and return to cli mode.
+
 * New options
 
 set max-completions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index f8b0487..f2699a7 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@ 
+2015-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* gdb.texinfo (TUI Commands): Add 'layout cli' details.
+
 2015-05-16  Doug Evans  <xdje42@gmail.com>
 
 	* guile.texi (Memory Ports in Guile): Document support for unbuffered
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 1665372..a78b0bf 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -24967,6 +24967,9 @@  Display the source and assembly window.
 @item layout regs
 Display the register window together with the source or assembly window.
 
+@item layout cli
+Close all windows and return to CLI mode.
+
 @item focus next
 @kindex focus
 Make the next window active for scrolling.
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 0255c39..ed364fb 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -358,7 +358,7 @@  layout_completer (struct cmd_list_element *ignore,
 		  const char *text, const char *word)
 {
   static const char *layout_names [] =
-    { "src", "asm", "split", "regs", "next", "prev", NULL };
+    { "src", "asm", "split", "regs", "cli", "next", "prev", NULL };
 
   return complete_on_enum (layout_names, text, word);
 }
@@ -378,6 +378,7 @@  _initialize_tui_layout (void)
 Change the layout of windows.\n\
 Usage: layout prev | next | <layout_name> \n\
 Layout names are:\n\
+   cli   : Close windows and return to command line.\n\
    src   : Displays source and command windows.\n\
    asm   : Displays disassembly and command windows.\n\
    split : Displays source, disassembly and command windows.\n\
@@ -426,6 +427,8 @@  tui_set_layout_by_name (const char *layout_name)
 	{
 	  if (subset_compare (buf_ptr, "SRC"))
 	    new_layout = SRC_COMMAND;
+	  else if (subset_compare (buf_ptr, "CLI"))
+	    tui_disable ();
 	  else if (subset_compare (buf_ptr, "ASM"))
 	    new_layout = DISASSEM_COMMAND;
 	  else if (subset_compare (buf_ptr, "SPLIT"))
@@ -445,7 +448,8 @@  tui_set_layout_by_name (const char *layout_name)
 	  else
 	    status = TUI_FAILURE;
 
-	  if (status == TUI_SUCCESS)
+	  if (status == TUI_SUCCESS
+	      && new_layout != UNDEFINED_LAYOUT)
 	    {
 	      /* Make sure the curses mode is enabled.  */
 	      tui_enable ();