Kaynağa Gözat

plugin_klish: The "prompt" symbol understands hex codes.

The prompt body can contain something like this "\x1b". This hex
number will be converted to the byte. The string must contain
exactly two characters (hex digits).
Serj Kalichev 4 ay önce
ebeveyn
işleme
7284de39c4
1 değiştirilmiş dosya ile 19 ekleme ve 0 silme
  1. 19 0
      plugins/klish/misc.c

+ 19 - 0
plugins/klish/misc.c

@@ -11,6 +11,7 @@
 #include <sys/types.h>
 #include <sys/utsname.h>
 
+#include <faux/conv.h>
 #include <faux/str.h>
 #include <faux/list.h>
 #include <faux/sysdb.h>
@@ -128,6 +129,24 @@ int klish_prompt(kcontext_t *context)
 				faux_str_cat(&prompt, "\x1b");
 				break;
 				}
+			// Hexadecimal byte
+			case 'x': {
+				char c;
+				char hs[3] = {};
+				if (*(pos + 1) == '\0')
+					break;
+				if (*(pos + 2) == '\0') {
+					pos++;
+					break;
+				}
+				hs[0] = *(pos + 1);
+				hs[1] = *(pos + 2);
+				pos += 2;
+				if (!faux_conv_atouc(hs, &c, 16))
+					break;
+				faux_str_catn(&prompt, &c, 1);
+				break;
+				}
 			// Hostname
 			case 'h': {
 				struct utsname buf;