Browse Source

vty: Add ctrl-v <literal> to allow, e.g., '?' to be input for regex

* Support the standard ctrl-v <literal> control sequence. Otherwise there
  is no way to do this from the venerable telnet vty. vtysh supports this
  (configurably) via readline.
* lib/vty.c: (VTY_ESC_LITERAL) New mode, for ctrl-v.
  (vty_read) Additional mode to go ctrl-v -> VTY_ESC_LITERAL, and
  always insert next char.

Acked-by: Vincent.Jardin@6wind.com
Paul Jakma 3 years ago
parent
commit
126b0e7c29
2 changed files with 23 additions and 3 deletions
  1. 9 0
      doc/basic.texi
  2. 14 3
      lib/vty.c

+ 9 - 0
doc/basic.texi

@@ -552,6 +552,12 @@ Kill line from the beginning, erasing input.
 @kindex C-t
 Transpose character.
 
+@item C-v
+@kindex C-v
+Interpret following character literally. Do not treat it specially.
+This can be used to, e.g., type in a literal @kbd{?} rather than do
+help completion.
+
 @end table
 
 @node CLI Advanced Commands
@@ -593,4 +599,7 @@ You can use command line help by typing @code{help} at the beginning of
 the line.  Typing @kbd{?} at any point in the line will show possible
 completions.
 
+To enter an actual @kbd{?} character rather show completions, e.g. to
+enter into a regexp, use @kbd{@key{C}-v ?}.
+
 @end table

+ 14 - 3
lib/vty.c

@@ -1386,8 +1386,9 @@ vty_execute (struct vty *vty)
 
 #define CONTROL(X)  ((X) - '@')
 #define VTY_NORMAL     0
-#define VTY_PRE_ESCAPE 1
-#define VTY_ESCAPE     2
+#define VTY_PRE_ESCAPE 1  /* Esc seen */
+#define VTY_ESCAPE     2  /* ANSI terminal escape (Esc-[) seen */
+#define VTY_LITERAL    3  /* Next char taken as literal */
 
 /* Escape character command map. */
 static void
@@ -1515,7 +1516,14 @@ vty_read (struct thread *thread)
 	  vty_escape_map (buf[i], vty);
 	  continue;
 	}
-
+      
+      if (vty->escape == VTY_LITERAL)
+        {
+          vty_self_insert (vty, buf[i]);
+          vty->escape = VTY_NORMAL;
+          continue;
+        }
+      
       /* Pre-escape status. */
       if (vty->escape == VTY_PRE_ESCAPE)
 	{
@@ -1587,6 +1595,9 @@ vty_read (struct thread *thread)
 	case CONTROL('U'):
 	  vty_kill_line_from_beginning (vty);
 	  break;
+        case CONTROL('V'):
+          vty->escape = VTY_LITERAL;
+          break;
 	case CONTROL('W'):
 	  vty_backward_kill_word (vty);
 	  break;