Home | History | Annotate | Line # | Download | only in gdb.tui
      1 # Copyright 2023-2024 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 # Test TUI resizing using maint screen info command.
     17 
     18 require allow_tui_tests
     19 
     20 tuiterm_env
     21 
     22 Term::clean_restart 24 80
     23 set screen_dim { 0 0 80 24 }
     24 
     25 # Use a layout with just a command window.
     26 gdb_test "tui new-layout command-layout cmd 1"
     27 
     28 if {![Term::prepare_for_tui]} {
     29     unsupported "TUI not supported"
     30     return 0
     31 }
     32 
     33 # Enter TUI.
     34 Term::command_no_prompt_prefix "layout command-layout"
     35 
     36 proc check_width { what n } {
     37     set re "Number of characters $what thinks are in a line is $n"
     38     Term::check_region_contents "$what width $n" {*}$::screen_dim $re
     39 }
     40 
     41 # Check that curses has the correct notion of screen width.
     42 Term::command "maint info screen"
     43 check_width curses 80
     44 check_width gdb 80
     45 
     46 # Resize with TUI enabled, wait for the resize message.
     47 Term::resize 40 90
     48 set screen_dim { 0 0 90 40 }
     49 
     50 # Check that curses has the correct notion of screen width after resize.
     51 Term::command "maint info screen"
     52 check_width curses 90
     53 check_width gdb 90
     54 
     55 # Temporarily disable TUI.
     56 gdb_test_multiple "tui disable" "" {
     57     -re "$gdb_prompt $" {
     58 	pass $gdb_test_name
     59     }
     60 }
     61 
     62 # Resize with TUI disabled, so don't wait for the resize message.  Instead,
     63 # do it in two steps, and wait for a prompt redisplay for each.  If we do
     64 # this in one step, it's unpredictable how may prompt redisplays we'll get.
     65 Term::resize 24 90 0
     66 set screen_dim { 0 0 90 24 }
     67 
     68 gdb_test_multiple "" "prompt redisplays after first resize" {
     69     -re "\r.*$gdb_prompt $" {
     70 	pass $gdb_test_name
     71     }
     72 }
     73 
     74 Term::resize 24 80 0
     75 set screen_dim { 0 0 80 24 }
     76 
     77 gdb_test_multiple "" "prompt redisplays after second resize" {
     78     -re "\r.*$gdb_prompt $" {
     79 	pass $gdb_test_name
     80     }
     81 }
     82 
     83 # At this point, curses still thinks the width is 90.  This doesn't look
     84 # harmful because TUI is disabled.
     85 gdb_test "maint info screen" \
     86     "\r\nNumber of characters curses thinks are in a line is 90.\\r\n.*" \
     87     "curses width after resize with TUI disabled"
     88 
     89 # Re-enable TUI.
     90 send_gdb "tui enable\n"
     91 # The "tui enable" command is issued on the CLI screen, on the TUI we have the
     92 # last command issued there: "tui disable".
     93 Term::wait_for "tui disable"
     94 
     95 # Check that curses has the correct notion of screen width after screen resize
     96 # with TUI disabled.
     97 Term::command "maint info screen"
     98 with_test_prefix again {
     99     check_width curses 80
    100     check_width gdb 80
    101 }
    102