added the possibility to display a custom message infront of the entries, as well as an entire entry

This commit is contained in:
Palanix 2021-07-13 16:23:20 +02:00
parent f8b79697c1
commit dfc541164d
2 changed files with 39 additions and 31 deletions

View File

@ -15,24 +15,26 @@
//here comes the order of elements
void order() {
hname();
os();
host();
kernel();
os("OS");
host("Host");
kernel("Kernel");
spacing();
spacing();
get_up();
get_shell();
get_term();
get_packages();
get_wm();
get_up("Uptime");
get_shell("Shell");
get_term("Terminal");
get_packages("Packages");
get_wm("DE/WM");
spacing();
spacing();
get_cpu();
get_memory();
get_cpu("CPU");
get_memory("Memory");
spacing();
spacing();
get_colors();
get_colors2();
// customPrint("preprint", "message");
}

48
main.c
View File

@ -17,20 +17,20 @@ struct sysinfo sys;
char info[ELEMENTS+1][150];
int i;
void os() {
void os(char preprint[]) {
FILE *os = fopen("/etc/os-release","r");
char buffer[150];
fscanf(os, "NAME=\"%[^\"]+", buffer);
snprintf(info[i], 149, COLOR"OS"SEPARATOR" "CLOSE"%s %s", buffer, u.machine);
snprintf(info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%s %s", preprint, buffer, u.machine);
fclose(os);
i += 1;
}
void host() {
void host(char preprint[]) {
FILE *host = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
char buffer[150];
fscanf(host, "%s", buffer);
snprintf( info[i], 149, COLOR"Host"SEPARATOR" "CLOSE"%s", buffer);
snprintf( info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%s", preprint, buffer);
fclose(host);
i += 1;
}
@ -46,23 +46,23 @@ void hname() {
}
void kernel() {
snprintf(info[i], 149, COLOR"Kernel"SEPARATOR" "CLOSE"%s", u.release);
void kernel( char preprint[]) {
snprintf(info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%s", preprint, u.release);
i += 1;
}
void get_up() {
void get_up(char preprint[]) {
float mins = sys.uptime / 60;
if((int) (mins / 60) == 0) {
snprintf(info[i], 149, COLOR"Uptime"SEPARATOR" "CLOSE"%d mins", (int)mins % 60);
snprintf(info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%d mins", preprint,(int)mins % 60);
} else {
snprintf(info[i], 149, COLOR"Uptime"SEPARATOR" "CLOSE"%d hours, %d mins", (int)(mins / 60), (int)mins % 60);
snprintf(info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%d hours, %d mins",preprint, (int)(mins / 60), (int)mins % 60);
}
i += 1;
}
void get_shell() {
snprintf(info[i], 149, COLOR"Shell"SEPARATOR" "CLOSE"%s", strrchr(getenv("SHELL"), '/') + 1);
void get_shell(char preprint[]) {
snprintf(info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%s",preprint, strrchr(getenv("SHELL"), '/') + 1);
i += 1;
}
@ -71,12 +71,12 @@ void spacing() {
i += 1;
}
void get_term() {
snprintf(info[i], 149, COLOR"Terminal"SEPARATOR" "CLOSE"%s", getenv("TERM"));
void get_term(char preprint[]) {
snprintf(info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%s",preprint, getenv("TERM"));
i += 1;
}
void get_cpu() {
void get_cpu(char preprint[]) {
FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); /* read from cpu info */
char *cpu_model = malloc(75);
@ -131,12 +131,12 @@ cpufreq_fallback:
snprintf(info[i], 150, COLOR"CPU"SEPARATOR" "CLOSE"%s (%d) @ %.*f%s", cpu_model, num_cores, prec, freq, freq_unit);
snprintf(info[i], 150, COLOR"%s"SEPARATOR" "CLOSE"%s (%d) @ %.*f%s", preprint,cpu_model, num_cores, prec, freq, freq_unit);
free(cpu_model);
i += 1;
}
void get_memory() {
void get_memory(char preprint[]) {
FILE *mem = fopen("/proc/meminfo","r");
char *line = NULL;
size_t len;
@ -160,7 +160,7 @@ void get_memory() {
total_memory = total / 1024;
int percentage = (int) (100 * (used_memory / (double) total_memory));
snprintf( info[i], 149, COLOR"Memory"SEPARATOR" "CLOSE"%dMiB / %dMiB (%d%%)", used_memory, total_memory, percentage);
snprintf( info[i], 149, COLOR"%s"SEPARATOR" "CLOSE"%dMiB / %dMiB (%d%%)", preprint, used_memory, total_memory, percentage);
i += 1;
}
@ -185,7 +185,7 @@ void get_colors2() {
snprintf(s, 5, "\e[0m");
i += 1;
}
void get_packages() {
void get_packages(char preprint[]) {
int num_packages = 0;
DIR * dirp;
struct dirent *entry;
@ -203,14 +203,20 @@ void get_packages() {
closedir(dirp);
snprintf(info[i], 150, COLOR"Packages"SEPARATOR" "CLOSE"%d", num_packages);
snprintf(info[i], 150, COLOR"%s"SEPARATOR" "CLOSE"%d",preprint, num_packages);
i += 1;
}
}
void get_wm() {
snprintf(info[i], 150, COLOR"DE/WM"SEPARATOR" "CLOSE"%s", getenv("XDG_CURRENT_DESKTOP"));
void get_wm(char preprint[]) {
snprintf(info[i], 150, COLOR"%s"SEPARATOR" "CLOSE"%s", preprint,getenv("XDG_CURRENT_DESKTOP"));
i += 1;
}
void customPrint(char preprint[], char message[]) {
snprintf(info[i], 150, COLOR"%s"SEPARATOR" "CLOSE"%s", preprint, message);
i += 1;
}
int main() {
uname(&u);
sysinfo(&sys);