Forráskód Böngészése

klish plugin: Prompt allows escape character \e.

The "prompt" symbol can use "\" symbol the same way as "%" one and
it allows to enter ESCape symbol "\e" for ANSI escape sequences.
Serj Kalichev 5 hónapja
szülő
commit
34e1a1501a
1 módosított fájl, 12 hozzáadás és 1 törlés
  1. 12 1
      plugins/klish/misc.c

+ 12 - 1
plugins/klish/misc.c

@@ -118,6 +118,16 @@ int klish_prompt(kcontext_t *context)
 				faux_str_cat(&prompt, "%");
 				break;
 				}
+			// Backslash symbol itself
+			case '\\': {
+				faux_str_cat(&prompt, "\\");
+				break;
+				}
+			// Escape character
+			case 'e': {
+				faux_str_cat(&prompt, "\x1b");
+				break;
+				}
 			// Hostname
 			case 'h': {
 				struct utsname buf;
@@ -136,7 +146,8 @@ int klish_prompt(kcontext_t *context)
 			}
 			is_macro = BOOL_FALSE;
 			start = pos + 1;
-		} else if (*pos == '%') {
+
+		} else if (*pos == '%' || *pos == '\\') {
 			is_macro = BOOL_TRUE;
 			if (pos > start)
 				faux_str_catn(&prompt, start, pos - start);