sophuwu.site > bashprompt
color and imports
sophuwu sophie@skisiel.com
Thu, 25 Apr 2024 00:39:32 +0200
commit

22babeda39f9f625522646b3ffc8418829871e2b

parent

b09f9cf4f3c1f408dae245129220ebd2d631675c

1 files changed, 2 insertions(+), 5 deletions(-)

jump to
M src/prompt.cppsrc/prompt.cpp

@@ -5,7 +5,7 @@ * It can also be used to generate the necessary environment variables

* */ -#include <c++/11/string> +#include <string> #include <chrono> #include <cstdio> #include <ctime>

@@ -66,10 +66,7 @@ pipe("hostname -I | awk -F '.' ' { printf(\"%X%X%X%X\",int($1),int($2),int($3),int($4)); } ' ", ip);

unsigned char ipaddr[4]; for (int i = 0; i < 4; i++)ipaddr[i] = unhex(ip[2*i])<<4 | unhex(ip[2*i+1]); for (int i = 0; i < host.length(); i++) - printf("\033[48;2;%d;%d;%d;38;2;%d;%d;%dm%c", - ipaddr[(3-i)%4],ipaddr[(i+1)%4],ipaddr[(2+i)%4], - ipaddr[i-1%4],ipaddr[(i-2)%4],ipaddr[3], - host[i]); + printf("\033[38;2;%d;%d;%dm%c",ipaddr[i%3],ipaddr[i+1%3],ipaddr[2+i%3],host[i]); printf("\033[0m\n");