]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: rework/straighten pager handling 3434/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 8 Nov 2018 05:50:13 +0000 (06:50 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Thu, 6 Dec 2018 22:05:48 +0000 (23:05 +0100)
- no longer try to special-case a custom terminal length; the OS has
  procedures for that (SIGWINCH & TIOCGWINSZ)
- only use a pager if requested by CLI command or VTYSH_PAGER.  The
  behaviour with VTYSH_PAGER set should be compatible to previous
  versions.

Signed-off-by: David Lamparter <equinox@diac24.net>
vtysh/vtysh.c
vtysh/vtysh.h
vtysh/vtysh_main.c

index f57a4d9ddf0aee1e36b3ae5b2d6c7e49b835f0a7..2327f2b46d7e04219518ab89d5d7fe849d307db9 100644 (file)
@@ -104,7 +104,7 @@ static int vty_close_pager(struct vty *vty)
        return 0;
 }
 
-void vtysh_pager_init(void)
+static void vtysh_pager_envdef(void)
 {
        char *pager_defined;
 
@@ -2881,52 +2881,58 @@ DEFUN (vtysh_copy_running_config,
        return vtysh_write_memory(self, vty, argc, argv);
 }
 
+DEFUN (vtysh_terminal_paginate,
+       vtysh_terminal_paginate_cmd,
+       "[no] terminal paginate",
+       NO_STR
+       "Set terminal line parameters\n"
+       "Use pager for output scrolling\n")
+{
+       free(vtysh_pager_name);
+       vtysh_pager_name = NULL;
+
+       if (strcmp(argv[0]->text, "no"))
+               vtysh_pager_envdef();
+       return CMD_SUCCESS;
+}
+
 DEFUN (vtysh_terminal_length,
        vtysh_terminal_length_cmd,
-       "terminal length (0-512)",
+       "[no] terminal length (0-4294967295)",
+       NO_STR
        "Set terminal line parameters\n"
        "Set number of lines on a screen\n"
-       "Number of lines on screen (0 for no pausing)\n")
+       "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
 {
        int idx_number = 2;
-       int lines;
-       char *endptr = NULL;
-       char default_pager[10];
+       unsigned long lines;
 
-       lines = strtol(argv[idx_number]->arg, &endptr, 10);
-       if (lines < 0 || lines > 512 || *endptr != '\0') {
-               vty_out(vty, "length is malformed\n");
-               return CMD_WARNING;
-       }
+       free(vtysh_pager_name);
+       vtysh_pager_name = NULL;
 
-       if (vtysh_pager_name) {
-               free(vtysh_pager_name);
-               vtysh_pager_name = NULL;
+       if (!strcmp(argv[0]->text, "no") || !strcmp(argv[1]->text, "no")) {
+               /* "terminal no length" = use VTYSH_PAGER */
+               vtysh_pager_envdef();
+               return CMD_SUCCESS;
        }
 
+       lines = strtoul(argv[idx_number]->arg, NULL, 10);
        if (lines != 0) {
-               snprintf(default_pager, 10, "more -%i", lines);
-               vtysh_pager_name = strdup(default_pager);
+               vty_out(vty,
+                       "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
+                       "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
+               vtysh_pager_envdef();
        }
 
        return CMD_SUCCESS;
 }
 
-DEFUN (vtysh_terminal_no_length,
+ALIAS_DEPRECATED(vtysh_terminal_length,
        vtysh_terminal_no_length_cmd,
        "terminal no length",
        "Set terminal line parameters\n"
        NO_STR
        "Set number of lines on a screen\n")
-{
-       if (vtysh_pager_name) {
-               free(vtysh_pager_name);
-               vtysh_pager_name = NULL;
-       }
-
-       vtysh_pager_init();
-       return CMD_SUCCESS;
-}
 
 DEFUN (vtysh_show_daemons,
        vtysh_show_daemons_cmd,
@@ -3805,6 +3811,7 @@ void vtysh_init_vty(void)
        /* "write memory" command. */
        install_element(ENABLE_NODE, &vtysh_write_memory_cmd);
 
+       install_element(VIEW_NODE, &vtysh_terminal_paginate_cmd);
        install_element(VIEW_NODE, &vtysh_terminal_length_cmd);
        install_element(VIEW_NODE, &vtysh_terminal_no_length_cmd);
        install_element(VIEW_NODE, &vtysh_show_daemons_cmd);
index 430b117c50a68b45c64ce54135873dd057b4e801..eb69a20b839615837e247f13f2565674533a05a1 100644 (file)
@@ -98,8 +98,6 @@ void vtysh_config_dump(void);
 
 void vtysh_config_init(void);
 
-void vtysh_pager_init(void);
-
 void suid_on(void);
 void suid_off(void);
 
index 777eed7b5d136495b78f6668ac13dc3705549923..2e4510a45a876be3442567017e82e3e6bf356ad9 100644 (file)
@@ -675,8 +675,6 @@ int main(int argc, char **argv, char **env)
                        exit(0);
        }
 
-       vtysh_pager_init();
-
        vtysh_readline_init();
 
        vty_hello(vty);