瀏覽代碼

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 10 月之前
父節點
當前提交
7284de39c4
共有 1 個文件被更改,包括 19 次插入0 次删除
  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;