diff --git a/README.md b/README.md
index d62ee09..c3b9657 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
Un outil d'information système rapide, léger, écrit en C et sans dépendances externes. Inspiré de Fastfetch, il se concentre sur la rapidité d'exécution et la personnalisation via un fichier de configuration simple.
+
+
+
+
## Fonctionnalités
- **Zéro dépendance** : Uniquement la bibliothèque C standard (glibc/musl).
diff --git a/assets/picture.png b/assets/picture.png
new file mode 100644
index 0000000..60a0b97
Binary files /dev/null and b/assets/picture.png differ
diff --git a/config.c b/config.c
index f6c32cf..2b2dae9 100644
--- a/config.c
+++ b/config.c
@@ -29,7 +29,6 @@ void generate_default_config(const char *path)
fprintf(f, " {distro_color}{logo} {align:L}{fg:157,211,154}Date{reset}: {align:V}{date} {time}\n");
fprintf(f, " {distro_color}{logo} {align:L}{fg:157,211,154}Local IP{reset}: {align:V}{ip_local}\n");
fprintf(f, "{if:wifi} {distro_color}{logo} {align:L}{fg:157,211,154}Wifi{reset}: {align:V}{wifi}\n{endif}");
- fprintf(f, " {distro_color}{logo} {align:L}{fg:157,211,154}Public IP{reset}: {align:V}{ip_public}\n");
fprintf(f, " {distro_color}{logo} {align:L}{fg:157,211,154}DNS{reset}: {align:V}{dns}\n");
fprintf(f, " {distro_color}{logo}\n");
fprintf(f, " {distro_color}{logo} {align:L}{fg:157,211,154}███{fg:23,147,209}███{fg:255,200,87}███{fg:255,90,120}███{fg:180,120,255}███{fg:80,220,180}███{fg:240,240,240}███{fg:120,120,120}███{reset}\n");
diff --git a/renderer.c b/renderer.c
index 60a32bf..df4444c 100644
--- a/renderer.c
+++ b/renderer.c
@@ -18,10 +18,25 @@ static int current_pass = 1;
static int logo_line_idx = 0;
static int prev_line_had_logo = 0;
-
-// NOUVEAU : Variable pour ignorer les codes ANSI lors du calcul de la largeur
static int in_ansi_escape = 0;
+// NOUVEAU : Génère le code ANSI pour un pourcentage dynamique
+static void get_dynamic_color(double pct, char *out, size_t size)
+{
+ if (pct >= 80.0)
+ {
+ snprintf(out, size, "\033[38;2;255;50;50m"); // Rouge
+ }
+ else if (pct >= 50.0)
+ {
+ snprintf(out, size, "\033[38;2;255;165;0m"); // Orange
+ }
+ else
+ {
+ snprintf(out, size, "\033[38;2;0;200;0m"); // Vert
+ }
+}
+
static int get_align_width(const char *id)
{
for (int i = 0; i < align_count; i++)
@@ -60,7 +75,6 @@ static void my_putchar(char c)
putchar(c);
}
- // NOUVEAU : Logique pour ignorer les séquences d'échappement ANSI (\033[...m)
if (c == '\033')
{
in_ansi_escape = 1;
@@ -68,15 +82,13 @@ static void my_putchar(char c)
}
if (in_ansi_escape)
{
- // Les séquences ANSI se terminent par une lettre (souvent 'm')
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
in_ansi_escape = 0;
}
- return; // On ne compte pas ces caractères dans current_col
+ return;
}
- // Compte les caractères UTF-8 visuels
if ((c & 0xC0) != 0x80)
{
current_col++;
@@ -201,41 +213,67 @@ static void print_variable(const char *name, SysInfo *info)
snprintf(buf, sizeof(buf), "%s", info->locale);
else if (strcmp(name, "disk_fs") == 0)
snprintf(buf, sizeof(buf), "%s", info->disk_fs);
+
+ // NOUVEAU : Gestion des variables avec unités et couleurs dynamiques
else if (strncmp(name, "ram", 3) == 0)
{
char unit[128] = "mb";
if (strlen(name) > 4 && name[3] == ':')
snprintf(unit, sizeof(unit), "%s", name + 4);
- if (strcmp(unit, "gb") == 0)
- snprintf(buf, sizeof(buf), "%.1fGB / %.1fGB", (double)info->ram_used_mb / 1024.0, (double)info->ram_total_mb / 1024.0);
- else if (strcmp(unit, "%") == 0)
- snprintf(buf, sizeof(buf), "%.1f%%", info->ram_total_mb ? (double)info->ram_used_mb / (double)info->ram_total_mb * 100.0 : 0);
+ if (strcmp(unit, "%") == 0)
+ {
+ double pct = info->ram_total_mb ? (double)info->ram_used_mb / (double)info->ram_total_mb * 100.0 : 0;
+ char col[32];
+ get_dynamic_color(pct, col, sizeof(col));
+ snprintf(buf, sizeof(buf), "%s%.1f%%\033[0m", col, pct);
+ }
else
- snprintf(buf, sizeof(buf), "%luMB / %luMB", info->ram_used_mb, info->ram_total_mb);
+ {
+ if (strcmp(unit, "gb") == 0)
+ snprintf(buf, sizeof(buf), "%.1fGB / %.1fGB", (double)info->ram_used_mb / 1024.0, (double)info->ram_total_mb / 1024.0);
+ else
+ snprintf(buf, sizeof(buf), "%luMB / %luMB", info->ram_used_mb, info->ram_total_mb);
+ }
}
else if (strncmp(name, "swap", 4) == 0)
{
char unit[128] = "mb";
if (strlen(name) > 5 && name[4] == ':')
snprintf(unit, sizeof(unit), "%s", name + 5);
- if (strcmp(unit, "gb") == 0)
- snprintf(buf, sizeof(buf), "%.1fGB / %.1fGB", (double)info->swap_used_mb / 1024.0, (double)info->swap_total_mb / 1024.0);
- else if (strcmp(unit, "%") == 0)
- snprintf(buf, sizeof(buf), "%.1f%%", info->swap_total_mb ? (double)info->swap_used_mb / (double)info->swap_total_mb * 100.0 : 0);
+ if (strcmp(unit, "%") == 0)
+ {
+ double pct = info->swap_total_mb ? (double)info->swap_used_mb / (double)info->swap_total_mb * 100.0 : 0;
+ char col[32];
+ get_dynamic_color(pct, col, sizeof(col));
+ snprintf(buf, sizeof(buf), "%s%.1f%%\033[0m", col, pct);
+ }
else
- snprintf(buf, sizeof(buf), "%luMB / %luMB", info->swap_used_mb, info->swap_total_mb);
+ {
+ if (strcmp(unit, "gb") == 0)
+ snprintf(buf, sizeof(buf), "%.1fGB / %.1fGB", (double)info->swap_used_mb / 1024.0, (double)info->swap_total_mb / 1024.0);
+ else
+ snprintf(buf, sizeof(buf), "%luMB / %luMB", info->swap_used_mb, info->swap_total_mb);
+ }
}
else if (strncmp(name, "disk", 4) == 0)
{
char unit[128] = "mb";
if (strlen(name) > 5 && name[4] == ':')
snprintf(unit, sizeof(unit), "%s", name + 5);
- if (strcmp(unit, "gb") == 0)
- snprintf(buf, sizeof(buf), "%.1fGB / %.1fGB", (double)info->disk_used_mb / 1024.0, (double)info->disk_total_mb / 1024.0);
- else if (strcmp(unit, "%") == 0)
- snprintf(buf, sizeof(buf), "%.1f%%", info->disk_total_mb ? (double)info->disk_used_mb / (double)info->disk_total_mb * 100.0 : 0);
+ if (strcmp(unit, "%") == 0)
+ {
+ double pct = info->disk_total_mb ? (double)info->disk_used_mb / (double)info->disk_total_mb * 100.0 : 0;
+ char col[32];
+ get_dynamic_color(pct, col, sizeof(col));
+ snprintf(buf, sizeof(buf), "%s%.1f%%\033[0m", col, pct);
+ }
else
- snprintf(buf, sizeof(buf), "%luMB / %luMB", info->disk_used_mb, info->disk_total_mb);
+ {
+ if (strcmp(unit, "gb") == 0)
+ snprintf(buf, sizeof(buf), "%.1fGB / %.1fGB", (double)info->disk_used_mb / 1024.0, (double)info->disk_total_mb / 1024.0);
+ else
+ snprintf(buf, sizeof(buf), "%luMB / %luMB", info->disk_used_mb, info->disk_total_mb);
+ }
}
else
{
@@ -250,7 +288,7 @@ static void process_line(const char *line, SysInfo *info)
int i = 0;
current_col = 0;
skip_output = 0;
- in_ansi_escape = 0; // NOUVEAU : Réinitialiser l'état ANSI à chaque ligne
+ in_ansi_escape = 0;
int has_logo = (strstr(line, "{logo}") != NULL || strstr(line, "{small_logo}") != NULL);
if (has_logo && !prev_line_had_logo)
diff --git a/sysinfo.c b/sysinfo.c
index 3722847..bfd7237 100644
--- a/sysinfo.c
+++ b/sysinfo.c
@@ -38,6 +38,20 @@ static void clean_newline(char *str)
str[strcspn(str, "\n")] = 0;
}
+// NOUVEAU : Lecture précise de la mémoire depuis /proc/meminfo
+static long get_meminfo_kb(const char *buf, const char *key)
+{
+ const char *p = strstr(buf, key);
+ if (p)
+ {
+ p += strlen(key);
+ while (*p == ' ' || *p == '\t' || *p == ':')
+ p++;
+ return atol(p);
+ }
+ return 0;
+}
+
void get_info(SysInfo *info)
{
struct passwd *pw = getpwuid(getuid());
@@ -49,7 +63,7 @@ void get_info(SysInfo *info)
read_file("/etc/os-release", buf, sizeof(buf));
extract_value(buf, "PRETTY_NAME", info->os, sizeof(info->os));
extract_value(buf, "ID", info->os_id, sizeof(info->os_id));
- extract_value(buf, "ANSI_COLOR", info->distro_color, sizeof(info->distro_color)); // NOUVEAU
+ extract_value(buf, "ANSI_COLOR", info->distro_color, sizeof(info->distro_color));
struct utsname uts;
uname(&uts);
@@ -81,10 +95,17 @@ void get_info(SysInfo *info)
if (strlen(info->host_model) == 0)
snprintf(info->host_model, sizeof(info->host_model), "Unknown");
- info->ram_total_mb = s_info.totalram * s_info.mem_unit / (1024 * 1024);
- info->ram_used_mb = (s_info.totalram - s_info.freeram) * s_info.mem_unit / (1024 * 1024);
- info->swap_total_mb = s_info.totalswap * s_info.mem_unit / (1024 * 1024);
- info->swap_used_mb = (s_info.totalswap - s_info.freeswap) * s_info.mem_unit / (1024 * 1024);
+ // NOUVEAU : Calcul de la RAM et Swap sans le cache
+ read_file("/proc/meminfo", buf, sizeof(buf));
+ long mem_total_kb = get_meminfo_kb(buf, "MemTotal");
+ long mem_avail_kb = get_meminfo_kb(buf, "MemAvailable");
+ long swap_total_kb = get_meminfo_kb(buf, "SwapTotal");
+ long swap_free_kb = get_meminfo_kb(buf, "SwapFree");
+
+ info->ram_total_mb = mem_total_kb / 1024;
+ info->ram_used_mb = (mem_total_kb - mem_avail_kb) / 1024; // Vraie RAM utilisée
+ info->swap_total_mb = swap_total_kb / 1024;
+ info->swap_used_mb = (swap_total_kb - swap_free_kb) / 1024;
struct statvfs vfs;
if (statvfs("/", &vfs) == 0)