소스 검색

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 달 전
부모
커밋
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;