Make ALIGN(x) behave as ALIGN(.,x)
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
index 957addc57881bb1fa6f12ac57034134711afe02b..629d54d8a45b1c0bab21af64a4df5348a4eca762 100644 (file)
@@ -64,7 +64,6 @@ static int new_height_ok (struct tui_win_info *, int);
 static void tui_set_tab_width_command (char *, int);
 static void tui_refresh_all_command (char *, int);
 static void tui_set_win_height_command (char *, int);
-static void tui_xdb_set_win_height_command (char *, int);
 static void tui_all_windows_info (char *, int);
 static void tui_set_focus_command (char *, int);
 static void tui_scroll_forward_command (char *, int);
@@ -355,6 +354,71 @@ tui_set_var_cmd (char *null_args, int from_tty, struct cmd_list_element *c)
     tui_rehighlight_all ();
 }
 
+/* Complete possible window names to focus on.  TEXT is the complete text
+   entered so far, WORD is the word currently being completed.  */
+
+static VEC (char_ptr) *
+focus_completer (struct cmd_list_element *ignore,
+                 const char *text, const char *word)
+{
+  VEC (const_char_ptr) *completion_name_vec = NULL;
+  VEC (char_ptr) *matches_vec;
+  int win_type;
+
+  for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++)
+    {
+      const char *completion_name = NULL;
+
+      /* We can't focus on an invisible window.  */
+      if (tui_win_list[win_type] == NULL
+         || !tui_win_list[win_type]->generic.is_visible)
+       continue;
+
+      switch (win_type)
+       {
+       case SRC_WIN:
+         completion_name = "src";
+         break;
+       case DISASSEM_WIN:
+         completion_name = "asm";
+         break;
+       case DATA_WIN:
+         completion_name = "regs";
+         break;
+       case CMD_WIN:
+         completion_name = "cmd";
+         break;
+       default:
+         break;
+       }
+
+      if (completion_name != NULL)
+       VEC_safe_push (const_char_ptr, completion_name_vec, completion_name);
+    }
+
+  /* If no windows are considered visible then the TUI has not yet been
+     initialized.  But still "focus src" and "focus cmd" will work because
+     invoking the focus command will entail initializing the TUI which sets the
+     default layout to SRC_COMMAND.  */
+  if (VEC_length (const_char_ptr, completion_name_vec) == 0)
+    {
+      VEC_safe_push (const_char_ptr, completion_name_vec, "src");
+      VEC_safe_push (const_char_ptr, completion_name_vec, "cmd");
+    }
+
+  VEC_safe_push (const_char_ptr, completion_name_vec, "next");
+  VEC_safe_push (const_char_ptr, completion_name_vec, "prev");
+  VEC_safe_push (const_char_ptr, completion_name_vec, NULL);
+
+  matches_vec
+    = complete_on_enum (VEC_address (const_char_ptr, completion_name_vec),
+                       text, word);
+
+  VEC_free (const_char_ptr, completion_name_vec);
+
+  return matches_vec;
+}
+
 /* Function to initialize gdb commands, for tui window
    manipulation.  */
 
@@ -366,6 +430,7 @@ _initialize_tui_win (void)
 {
   static struct cmd_list_element *tui_setlist;
   static struct cmd_list_element *tui_showlist;
+  struct cmd_list_element *focus_cmd;
 
   /* Define the classes of commands.
      They will appear in the help list in the reverse of this order.  */
@@ -380,8 +445,6 @@ _initialize_tui_win (void)
 
   add_com ("refresh", class_tui, tui_refresh_all_command,
            _("Refresh the terminal display.\n"));
-  if (xdb_commands)
-    add_com_alias ("U", "refresh", class_tui, 0);
   add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
 Set the width (in characters) of tab stops.\n\
 Usage: tabset <n>\n"));
@@ -396,7 +459,7 @@ regs : the register display\n"));
   add_com_alias ("wh", "winheight", class_tui, 0);
   add_info ("win", tui_all_windows_info,
            _("List of all displayed windows.\n"));
-  add_com ("focus", class_tui, tui_set_focus_command, _("\
+  focus_cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
 Set focus to named window or next/prev window.\n\
 Usage: focus {<win> | next | prev}\n\
 Valid Window names are:\n\
@@ -405,6 +468,7 @@ asm  : the disassembly window\n\
 regs : the register display\n\
 cmd  : the command window\n"));
   add_com_alias ("fs", "focus", class_tui, 0);
+  set_cmd_completer (focus_cmd, focus_completer);
   add_com ("+", class_tui, tui_scroll_forward_command, _("\
 Scroll window forward.\n\
 Usage: + [win] [n]\n"));
@@ -417,10 +481,6 @@ Usage: < [win] [n]\n"));
   add_com (">", class_tui, tui_scroll_right_command, _("\
 Scroll window text to the right.\n\
 Usage: > [win] [n]\n"));
-  if (xdb_commands)
-    add_com ("w", class_xdb, tui_xdb_set_win_height_command, _("\
-XDB compatibility command for setting the height of a command window.\n\
-Usage: w <#lines>\n"));
 
   /* Define the tui control variables.  */
   add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
@@ -472,15 +532,20 @@ bold-standout   use extra bright or bold with standout mode"),
 void
 tui_update_gdb_sizes (void)
 {
-  char cmd[50];
-
-  /* Set to TUI command window dimension or use readline values.  */
-  xsnprintf (cmd, sizeof (cmd), "set width %d",
-           tui_active ? TUI_CMD_WIN->generic.width : tui_term_width());
-  execute_command (cmd, 0);
-  xsnprintf (cmd, sizeof (cmd), "set height %d",
-           tui_active ? TUI_CMD_WIN->generic.height : tui_term_height());
-  execute_command (cmd, 0);
+  int width, height;
+
+  if (tui_active)
+    {
+      width = TUI_CMD_WIN->generic.width;
+      height = TUI_CMD_WIN->generic.height;
+    }
+  else
+    {
+      width = tui_term_width ();
+      height = tui_term_height ();
+    }
+
+  set_screen_width_and_height (width, height);
 }
 
 
@@ -628,7 +693,7 @@ tui_scroll (enum tui_scroll_direction direction,
 void
 tui_refresh_all_win (void)
 {
-  enum tui_win_type type;
+  int type;
 
   clearok (curscr, TRUE);
   tui_refresh_all (tui_win_list);
@@ -660,7 +725,7 @@ tui_refresh_all_win (void)
 void
 tui_rehighlight_all (void)
 {
-  enum tui_win_type type;
+  int type;
 
   for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
     tui_check_and_display_highlight_if_needed (tui_win_list[type]);
@@ -684,7 +749,7 @@ tui_resize_all (void)
       struct tui_win_info *first_win;
       struct tui_win_info *second_win;
       struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
-      enum tui_win_type win_type;
+      int win_type;
       int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
 
 #ifdef HAVE_RESIZE_TERM
@@ -838,12 +903,6 @@ static struct async_signal_handler *tui_sigwinch_token;
 static void
 tui_sigwinch_handler (int signal)
 {
-  /* Set win_resized to TRUE and asynchronously invoke our resize callback.  If
-     the callback is invoked while TUI is active then it ought to successfully
-     resize the screen, resetting win_resized to FALSE.  Of course, if the
-     callback is invoked while TUI is inactive then it will do nothing; in that
-     case, win_resized will remain TRUE until we get a chance to synchronously
-     resize the screen from tui_enable().  */
   mark_async_signal_handler (tui_sigwinch_token);
   tui_set_win_resized_to (TRUE);
 }
@@ -852,14 +911,26 @@ tui_sigwinch_handler (int signal)
 static void
 tui_async_resize_screen (gdb_client_data arg)
 {
+  rl_resize_terminal ();
+
   if (!tui_active)
-    return;
+    {
+      int screen_height, screen_width;
 
-  tui_resize_all ();
-  tui_refresh_all_win ();
-  tui_update_gdb_sizes ();
-  tui_set_win_resized_to (FALSE);
-  tui_redisplay_readline ();
+      rl_get_screen_size (&screen_height, &screen_width);
+      set_screen_width_and_height (screen_width, screen_height);
+
+      /* win_resized is left set so that the next call to tui_enable()
+        resizes the TUI windows.  */
+    }
+  else
+    {
+      tui_set_win_resized_to (FALSE);
+      tui_resize_all ();
+      tui_refresh_all_win ();
+      tui_update_gdb_sizes ();
+      tui_redisplay_readline ();
+    }
 }
 #endif
 
@@ -988,8 +1059,7 @@ The window name specified must be valid and visible.\n"));
        tui_refresh_data_win ();
       xfree (buf_ptr);
       printf_filtered (_("Focus set to %s window.\n"),
-                      tui_win_name ((struct tui_gen_win_info *)
-                                    tui_win_with_focus ()));
+                      tui_win_name (&tui_win_with_focus ()->generic));
     }
   else
     warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
@@ -1007,7 +1077,7 @@ tui_set_focus_command (char *arg, int from_tty)
 static void
 tui_all_windows_info (char *arg, int from_tty)
 {
-  enum tui_win_type type;
+  int type;
   struct tui_win_info *win_with_focus = tui_win_with_focus ();
 
   for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
@@ -1167,45 +1237,6 @@ tui_set_win_height_command (char *arg, int from_tty)
   tui_set_win_height (arg, from_tty);
 }
 
-
-/* XDB Compatibility command for setting the window height.  This will
-   increase or decrease the command window by the specified
-   amount.  */
-static void
-tui_xdb_set_win_height (char *arg, int from_tty)
-{
-  /* Make sure the curses mode is enabled.  */
-  tui_enable ();
-  if (arg != (char *) NULL)
-    {
-      int input_no = atoi (arg);
-
-      if (input_no > 0)
-       {                       /* Add 1 for the locator.  */
-         int new_height = tui_term_height () - (input_no + 1);
-
-         if (!new_height_ok (tui_win_list[CMD_WIN], new_height)
-             || tui_adjust_win_heights (tui_win_list[CMD_WIN],
-                                        new_height) == TUI_FAILURE)
-           warning (_("Invalid window height specified.\n%s"),
-                    XDBWIN_HEIGHT_USAGE);
-       }
-      else
-       warning (_("Invalid window height specified.\n%s"),
-                XDBWIN_HEIGHT_USAGE);
-    }
-  else
-    warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE);
-}
-
-/* Set the height of the specified window, with va_list.  */
-static void
-tui_xdb_set_win_height_command (char *arg, int from_tty)
-{
-  tui_xdb_set_win_height (arg, from_tty);
-}
-
-
 /* Function to adjust all window heights around the primary.   */
 static enum tui_status
 tui_adjust_win_heights (struct tui_win_info *primary_win_info,
This page took 0.028523 seconds and 4 git commands to generate.