add user colors based on uid

This commit is contained in:
Luca Conte 2024-08-11 23:59:15 +00:00
parent 969257860c
commit 1772a54d75
1 changed files with 18 additions and 5 deletions

23
main.c
View File

@ -34,8 +34,18 @@
int fg = C_BLACK; int fg = C_BLACK;
int bgUserRoot = C_L_MAGENTA;
// COLORS FOR USERS UID >= 1000 (UID - 1000 = Index)
int bgUsers[1] = {
C_L_GREEN // UID 1000
};
// COLOR FOR USERS UID < 1000
int bgUserOther = C_L_YELLOW;
int bgHost = C_L_CYAN; int bgHost = C_L_CYAN;
int bgUser = C_L_GREEN; int bgUser;
int bgBranch = C_L_GRAY; int bgBranch = C_L_GRAY;
int bgEnd = C_CYAN; int bgEnd = C_CYAN;
int bgFolder[] = { C_WHITE, C_CYAN }; int bgFolder[] = { C_WHITE, C_CYAN };
@ -78,12 +88,15 @@ int main(void) {
fclose(fp); fclose(fp);
uid_t uid = getuid();
if (strcmp(username_buf, "root") == 0) { if (uid == 0) {
bgUser = C_L_MAGENTA; bgUser = bgUserRoot;
} else if (uid >= 1000) {
bgUser = bgUsers[uid - 1000];
} else {
bgUser = bgUserOther;
} }
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
fgcol(C_BLACK); fgcol(C_BLACK);