diff --git a/AUTHORS.md b/AUTHORS.md index 1682e22..1bf98f7 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -11,6 +11,7 @@ * Frank Villaro-Dixon * Kevin Gillieron * Landry Breuil + * Lenni vH * Matthieu Le Jeune * Sylvain Laperche * Tobias Patzl diff --git a/man/dfc.1 b/man/dfc.1 index 340b1b6..615dab8 100644 --- a/man/dfc.1 +++ b/man/dfc.1 @@ -24,6 +24,9 @@ terminal width. If you want to override this behavior, use the "\-f" option. \-a Show all (do not omit any file system). .TP +\-A +The full graph width is proportional to the file system size. +.TP \-b Do not show the graph bar. .TP diff --git a/po/fr.po b/po/fr.po index 1faabb9..57fb5f4 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: dfc 3.1.1\n" "Report-Msgid-Bugs-To: robin.hahling@gw-computing.net\n" -"POT-Creation-Date: 2017-09-11 13:26+0200\n" +"POT-Creation-Date: 2020-12-05 09:49+0100\n" "PO-Revision-Date: 2012-04-15 13:52+0200\n" "Last-Translator: Robin Hahling \n" "Language-Team: French\n" @@ -17,41 +17,43 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: src/dfc.c:214 +#: src/dfc.c:218 #, c-format msgid "-c: illegal sub option %s\n" msgstr "-c: sous-option illégale %s\n" -#: src/dfc.c:251 +#: src/dfc.c:255 #, c-format msgid "-e: illegal sub option %s\n" msgstr "-e: sous-option illégale %s\n" -#: src/dfc.c:302 +#: src/dfc.c:306 #, c-format msgid "-q: illegal sub option %s\n" msgstr "-q: sous-option illégale %s\n" -#: src/dfc.c:363 +#: src/dfc.c:367 #, c-format msgid "-u: illegal sub option %s\n" msgstr "-u: sous-option illégale %s\n" -#: src/dfc.c:406 +#: src/dfc.c:410 #, c-format msgid "Error reading the configuration file: %s\n" msgstr "Erreur pendant la lecture du fichier de configuration: %s\n" -#: src/dfc.c:445 +#: src/dfc.c:449 msgid "Try dfc -h for more information\n" msgstr "Essayez dfc -h pour plus d'informations\n" -#: src/dfc.c:448 +#: src/dfc.c:452 +#, fuzzy msgid "" "Usage: dfc [OPTION(S)] [-c WHEN] [-e FORMAT] [-p FSNAME] [-q SORTBY] [-t " "FSTYPE] [-u UNIT]\n" "Available options:\n" "\t-a\tprint all mounted filesystem\n" +"\t-A\tprint graphs of absolute width\n" "\t-b\tdo not show the graph bar\n" "\t-c\tchoose color mode. Read the manpage for details\n" "\t-d\tshow used size\n" @@ -76,7 +78,7 @@ msgstr "" "\t-l\taffiche les informations sur les systèmes de fichiers montés " "localement uniquement\n" -#: src/dfc.c:466 +#: src/dfc.c:471 msgid "" "\t-m\tuse metric (SI unit)\n" "\t-M\tdo not print \"mounted on\"\n" @@ -115,8 +117,9 @@ msgstr "" msgid "" "Config file path is longer than %lu and was truncated. Please, open a bug " "report.\n" -msgstr "Le chemin vers le fichier de configuration est plus long que %lu et a " -"été tronqué. Veuillez svp ouvrir un rapport de bogue.\n" +msgstr "" +"Le chemin vers le fichier de configuration est plus long que %lu et a été " +"tronqué. Veuillez svp ouvrir un rapport de bogue.\n" #: src/dotfile.c:159 #, c-format @@ -187,61 +190,61 @@ msgstr "Couleur HTML invalide pour '%s': %s\n" msgid "Cannot assign value for '%s': %s\n" msgstr "Impossible d'assigner une valeur pour '%s': %s\n" -#: src/util.c:510 src/export/html.c:157 src/export/tex.c:140 +#: src/util.c:521 src/export/html.c:157 src/export/tex.c:140 #: src/export/text.c:101 msgid "FILESYSTEM" msgstr "SYSTÈME DE FICHIERS" -#: src/util.c:511 src/export/html.c:160 src/export/tex.c:142 +#: src/util.c:522 src/export/html.c:160 src/export/tex.c:142 #: src/export/text.c:104 msgid "TYPE" msgstr "TYPE" -#: src/util.c:513 src/export/html.c:164 src/export/text.c:114 +#: src/util.c:524 src/export/html.c:164 src/export/text.c:114 msgid "%USED" msgstr "%UTILISÉ" -#: src/util.c:514 src/export/html.c:166 src/export/tex.c:147 +#: src/util.c:525 src/export/html.c:166 src/export/tex.c:147 #: src/export/text.c:117 msgid "USED" msgstr " UT." -#: src/util.c:515 src/export/html.c:167 src/export/tex.c:148 +#: src/util.c:526 src/export/html.c:167 src/export/tex.c:148 #: src/export/text.c:119 msgid "AVAILABLE" msgstr "DISPO." -#: src/util.c:516 src/export/csv.c:104 src/export/html.c:168 +#: src/util.c:527 src/export/csv.c:104 src/export/html.c:168 #: src/export/tex.c:149 src/export/text.c:120 #, c-format msgid "TOTAL" msgstr "TOTAL" -#: src/util.c:517 src/export/html.c:171 src/export/text.c:123 +#: src/util.c:528 src/export/html.c:171 src/export/text.c:123 msgid "#INODES" msgstr "#INODES" -#: src/util.c:518 src/export/csv.c:108 src/export/html.c:172 +#: src/util.c:529 src/export/csv.c:108 src/export/html.c:172 #: src/export/text.c:124 #, c-format msgid "AV.INODES" msgstr "INODES DISP." -#: src/util.c:519 src/export/csv.c:112 src/export/html.c:176 +#: src/util.c:530 src/export/csv.c:112 src/export/html.c:176 #: src/export/tex.c:155 src/export/text.c:131 msgid "MOUNTED ON" msgstr "MONTÉ SUR" -#: src/util.c:520 src/export/html.c:179 src/export/tex.c:157 +#: src/util.c:531 src/export/html.c:179 src/export/tex.c:157 #: src/export/text.c:134 msgid "MOUNT OPTIONS" msgstr "OPTIONS DE MONTAGE" -#: src/util.c:545 +#: src/util.c:557 msgid "Cannot compute required width\n" msgstr "Impossible de calculer la largeur requise\n" -#: src/util.c:621 +#: src/util.c:635 msgid "" "WARNING: TTY too narrow. Some options have been disabled to make dfc output " "fit (use -f to override).\n" @@ -249,7 +252,7 @@ msgstr "" "AVERTISSEMENT: le TTY est trop étroit. Certaines options ont été désactivées " "afin d'ajuster l'affichage (utilisez -f afin d'outrepasser).\n" -#: src/util.c:667 +#: src/util.c:681 msgid "WARNING: Output still messed up. Enlarge your terminal if you can...\n" msgstr "" "AVERTISSEMENT: l'affichage est toujours perturbé. Agrandissez votre terminal " @@ -328,16 +331,16 @@ msgstr "(=) UT." msgid "FREE (-)" msgstr "LIB. (-)" -#: src/export/text.c:165 +#: src/export/text.c:166 msgid "SUM:" msgstr "SOM:" -#: src/platform/services-bsd.c:353 +#: src/platform/services-bsd.c:350 #, c-format msgid "Could not retrieve mount flags for %s\n" msgstr "Impossible de récupérer les options de montage pour %s\n" -#: src/platform/services-bsd.c:382 +#: src/platform/services-bsd.c:379 #, c-format msgid "Truncating mount options for %s\n" msgstr "Troncation des options de montage pour %s\n" diff --git a/po/nl.po b/po/nl.po index 7a35ce0..6acedd9 100644 --- a/po/nl.po +++ b/po/nl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: dfc 3.1.1\n" "Report-Msgid-Bugs-To: robin.hahling@gw-computing.net\n" -"POT-Creation-Date: 2017-09-09 08:48+0200\n" +"POT-Creation-Date: 2020-12-05 09:49+0100\n" "PO-Revision-Date: 2016-04-15 02:02+0200\n" "Last-Translator: Michiel Pater \n" "Language-Team: Dutch\n" @@ -17,41 +17,43 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: src/dfc.c:214 +#: src/dfc.c:218 #, c-format msgid "-c: illegal sub option %s\n" msgstr "-c: ongeldige suboptie %s\n" -#: src/dfc.c:251 +#: src/dfc.c:255 #, c-format msgid "-e: illegal sub option %s\n" msgstr "-e: ongeldige suboptie %s\n" -#: src/dfc.c:302 +#: src/dfc.c:306 #, c-format msgid "-q: illegal sub option %s\n" msgstr "-q: ongeldige suboptie %s\n" -#: src/dfc.c:363 +#: src/dfc.c:367 #, c-format msgid "-u: illegal sub option %s\n" msgstr "-u: ongeldige suboptie %s\n" -#: src/dfc.c:406 +#: src/dfc.c:410 #, c-format msgid "Error reading the configuration file: %s\n" msgstr "Fout bij het lezen van het configuratiebestand: %s\n" -#: src/dfc.c:445 +#: src/dfc.c:449 msgid "Try dfc -h for more information\n" msgstr "Probeer dfc -h voor meer informatie\n" -#: src/dfc.c:448 +#: src/dfc.c:452 +#, fuzzy msgid "" "Usage: dfc [OPTION(S)] [-c WHEN] [-e FORMAT] [-p FSNAME] [-q SORTBY] [-t " "FSTYPE] [-u UNIT]\n" "Available options:\n" "\t-a\tprint all mounted filesystem\n" +"\t-A\tprint graphs of absolute width\n" "\t-b\tdo not show the graph bar\n" "\t-c\tchoose color mode. Read the manpage for details\n" "\t-d\tshow used size\n" @@ -75,7 +77,7 @@ msgstr "" "\t-i\tlaat informatie zien over inodes\n" "\t-l\tgeef alleen informatie weer over lokaal-gemountte bestandssystemen\n" -#: src/dfc.c:466 +#: src/dfc.c:471 msgid "" "\t-m\tuse metric (SI unit)\n" "\t-M\tdo not print \"mounted on\"\n" @@ -186,61 +188,61 @@ msgstr "Ongeldige HTML kleurcode voor '%s': %s\n" msgid "Cannot assign value for '%s': %s\n" msgstr "Kan geen waarde voor '%s' toewijzen: %s\n" -#: src/util.c:510 src/export/html.c:157 src/export/tex.c:140 +#: src/util.c:521 src/export/html.c:157 src/export/tex.c:140 #: src/export/text.c:101 msgid "FILESYSTEM" msgstr "BEST.SYS." -#: src/util.c:511 src/export/html.c:160 src/export/tex.c:142 +#: src/util.c:522 src/export/html.c:160 src/export/tex.c:142 #: src/export/text.c:104 msgid "TYPE" msgstr "TYPE" -#: src/util.c:513 src/export/html.c:164 src/export/text.c:114 +#: src/util.c:524 src/export/html.c:164 src/export/text.c:114 msgid "%USED" msgstr "%GEBR" -#: src/util.c:514 src/export/html.c:166 src/export/tex.c:147 +#: src/util.c:525 src/export/html.c:166 src/export/tex.c:147 #: src/export/text.c:117 msgid "USED" msgstr "GEBR" -#: src/util.c:515 src/export/html.c:167 src/export/tex.c:148 +#: src/util.c:526 src/export/html.c:167 src/export/tex.c:148 #: src/export/text.c:119 msgid "AVAILABLE" msgstr "BESCH." -#: src/util.c:516 src/export/csv.c:104 src/export/html.c:168 +#: src/util.c:527 src/export/csv.c:104 src/export/html.c:168 #: src/export/tex.c:149 src/export/text.c:120 #, c-format msgid "TOTAL" msgstr "TOT." -#: src/util.c:517 src/export/html.c:171 src/export/text.c:123 +#: src/util.c:528 src/export/html.c:171 src/export/text.c:123 msgid "#INODES" msgstr "#INODES" -#: src/util.c:518 src/export/csv.c:108 src/export/html.c:172 +#: src/util.c:529 src/export/csv.c:108 src/export/html.c:172 #: src/export/text.c:124 #, c-format msgid "AV.INODES" msgstr "BB.INODES" -#: src/util.c:519 src/export/csv.c:112 src/export/html.c:176 +#: src/util.c:530 src/export/csv.c:112 src/export/html.c:176 #: src/export/tex.c:155 src/export/text.c:131 msgid "MOUNTED ON" msgstr "MOUNT" -#: src/util.c:520 src/export/html.c:179 src/export/tex.c:157 +#: src/util.c:531 src/export/html.c:179 src/export/tex.c:157 #: src/export/text.c:134 msgid "MOUNT OPTIONS" msgstr "MOUNT OPTIES" -#: src/util.c:545 +#: src/util.c:557 msgid "Cannot compute required width\n" msgstr "Kan vereiste breedte niet berekenen\n" -#: src/util.c:621 +#: src/util.c:635 msgid "" "WARNING: TTY too narrow. Some options have been disabled to make dfc output " "fit (use -f to override).\n" @@ -248,7 +250,7 @@ msgstr "" "WAARSCHUWING: TTY te smal. Sommige opties zijn uitgeschakeld om dfc output " "te laten passen (gebruik -f om te overschrijven).\n" -#: src/util.c:667 +#: src/util.c:681 msgid "WARNING: Output still messed up. Enlarge your terminal if you can...\n" msgstr "" "WAARSCHUWING: Output nog steeds te breed. Probeer uw terminal te\n" @@ -327,16 +329,16 @@ msgstr "(=) GEBR" msgid "FREE (-)" msgstr "VRIJ (-)" -#: src/export/text.c:165 +#: src/export/text.c:166 msgid "SUM:" msgstr "TOTAAL:" -#: src/platform/services-bsd.c:353 +#: src/platform/services-bsd.c:350 #, c-format msgid "Could not retrieve mount flags for %s\n" msgstr "Kan mount flags niet ontvangen voor %s\n" -#: src/platform/services-bsd.c:382 +#: src/platform/services-bsd.c:379 #, c-format msgid "Truncating mount options for %s\n" msgstr "Mount opties inkorten voor %s\n" diff --git a/src/dfc.c b/src/dfc.c index d35a949..8b9e33c 100644 --- a/src/dfc.c +++ b/src/dfc.c @@ -52,8 +52,9 @@ char g_unknown_str[] = "unknown"; char g_none_str[] = "none"; struct conf cnf; struct maxwidths max; +double maxfssize = 0; int aflag, bflag, cflag, dflag, eflag, fflag, hflag, iflag, lflag, mflag, - nflag, oflag, pflag, qflag, sflag, tflag, uflag, vflag, wflag; + nflag, oflag, pflag, qflag, sflag, tflag, uflag, vflag, wflag, agflag; int Mflag, Tflag, Wflag; char unitflag; @@ -187,11 +188,14 @@ main(int argc, char *argv[]) /* Init default colors and symbol sign */ init_conf(&cnf); - while ((ch = getopt(argc, argv, "abc:de:fhilmMnop:q:st:Tu:vwW")) != -1) { + while ((ch = getopt(argc, argv, "aAbc:de:fhilmMnop:q:st:Tu:vwW")) != -1) { switch (ch) { case 'a': aflag = 1; break; + case 'A': + agflag = 1; + break; case 'b': bflag = 1; break; @@ -450,6 +454,7 @@ usage(int status) "[-u UNIT]\n" "Available options:\n" "\t-a\tprint all mounted filesystem\n" + "\t-A\tprint graphs of absolute width\n" "\t-b\tdo not show the graph bar\n" "\t-c\tchoose color mode. Read the manpage for " "details\n" @@ -583,7 +588,7 @@ disp(struct list *lst, const char *fstfilter, const char *fsnfilter, } if (!bflag) - sdisp->print_bar(p->perctused); + sdisp->print_bar(p->perctused, p->total, maxfssize); /* %used */ sdisp->print_perct(p->perctused); diff --git a/src/export/csv.c b/src/export/csv.c index 94b4a12..d8eb19a 100644 --- a/src/export/csv.c +++ b/src/export/csv.c @@ -52,7 +52,7 @@ static void csv_disp_header(void); static void csv_disp_sum(double stot, double utot, double ftot, double ifitot, double ifatot); -static void csv_disp_bar(double perct); +static void csv_disp_bar(double used, double size, double gsize); static void csv_disp_uat(double n, double perct, int req_width); static void csv_disp_fs(const char *fsname); static void csv_disp_type(const char *type); @@ -163,12 +163,16 @@ csv_disp_sum(double stot, double atot, double utot, double ifitot, double ifatot * Should display the nice usage bar but this makes no sense in CSV export * Therefore, this is a dummy function that does nothing when called from * dfc.c but it is required in order to avoid stupid checks in dfc.c - * @perct: is ignored + * @used: is ignored + * @size: is ignored + * @gsize: is ignored */ static void -csv_disp_bar(double perct) +csv_disp_bar(double used, double size, double gsize) { - (void)perct; + (void)used; + (void)size; + (void)gsize; /* DUMMY */ } diff --git a/src/export/display.h b/src/export/display.h index 7b981a5..3575188 100644 --- a/src/export/display.h +++ b/src/export/display.h @@ -44,7 +44,7 @@ struct display void (*print_header) (void); void (*print_sum) (double, double, double, double, double); - void (*print_bar) (double); + void (*print_bar) (double, double, double); void (*print_used) (double, double, int); void (*print_avail) (double, double, int); void (*print_total) (double, double, int); diff --git a/src/export/html.c b/src/export/html.c index 746a111..b196a2a 100644 --- a/src/export/html.c +++ b/src/export/html.c @@ -54,7 +54,7 @@ static void html_disp_deinit(void); static void html_disp_header(void); static void html_disp_sum(double stot, double utot, double ftot, double ifitot, double ifatot); -static void html_disp_bar(double perct); +static void html_disp_bar(double used, double size, double gsize); static void html_disp_uat(double n, double perct, int req_width); static void html_disp_fs(const char *fsname); static void html_disp_type(const char *type); @@ -207,7 +207,7 @@ html_disp_sum(double stot, double atot, double utot, (void)puts("\t N/A"); if (!bflag) - html_disp_bar(ptot); + html_disp_bar(ptot, stot, maxfssize); html_disp_perct(ptot); @@ -236,13 +236,21 @@ html_disp_sum(double stot, double atot, double utot, /* * Display the nice usage bar * @perct: percentage value + * @size: how much total space this volume has + * @gsize: how much total space the greatest volume has */ static void -html_disp_bar(double perct) +html_disp_bar(double perct, double size, double gsize) { int barwidth = 100; /* In pixels */ int barheight = 25; /* In pixels */ - int size; + int barsize; + + double sperct = 100; + if (agflag) { + sperct = size / gsize * 100; + perct = perct * size / gsize; + } (void)puts("\t "); @@ -252,26 +260,40 @@ html_disp_bar(double perct) if (!cflag) { (void)printf("\t \n", - (int)perct*barwidth/100, barheight); + (int)perct * barwidth / 100, barheight); } else { /* color */ - size = (perct < cnf.gmedium) ? (int)perct : cnf.gmedium; + // draw to either the next color or the full bar + // scaling each colors' width according to the bar width: + if (perct < cnf.gmedium * sperct / 100) { + barsize = (int)perct; + } else { + barsize = (int)(cnf.gmedium * sperct / 100); + } (void)printf("\t \n", - size * barwidth / 100, barheight, cnf.hclow); - - if (perct >= cnf.gmedium) { - size = (perct < cnf.ghigh) ? (int)perct : cnf.ghigh; - size -= cnf.gmedium; + barsize * barwidth / 100, barheight, cnf.hclow); + + if (perct >= cnf.gmedium * sperct / 100) { + // if there is something left after the low color, draw + // to the next color or the rest of the full bar + // scaling the colors according to the bar width: + if (perct < cnf.ghigh * sperct / 100) { + barsize = (int)perct; + } else { + barsize = (int)(cnf.ghigh * sperct / 100); + } + barsize -= (int)(cnf.gmedium * sperct / 100); (void)printf("\t \n", - size * barwidth / 100, barheight, cnf.hcmedium); + barsize * barwidth / 100, barheight, cnf.hcmedium); } - if (perct >= cnf.ghigh) { - size = (int)perct - cnf.ghigh; + // if there is something left after the medium color, draw it: + if (perct >= cnf.ghigh * sperct / 100) { + barsize = (int)(perct - cnf.ghigh * sperct / 100); (void)printf("\t \n", - size * barwidth / 100, barheight, cnf.hchigh); + barsize * barwidth / 100, barheight, cnf.hchigh); } } (void)puts("\t "); diff --git a/src/export/json.c b/src/export/json.c index 9c460a6..66ac6b9 100644 --- a/src/export/json.c +++ b/src/export/json.c @@ -57,7 +57,7 @@ static void json_disp_deinit(void); static void json_disp_header(void); static void json_disp_sum(double stot, double utot, double ftot, double ifitot, double ifatot); -static void json_disp_bar(double perct); +static void json_disp_bar(double used, double size, double gsize); static void json_disp_uat(double n, const char *key); static void json_disp_used(double used, double perct, int req_width); static void json_disp_avail(double avail, double perct, int req_width); @@ -145,9 +145,11 @@ json_disp_sum(double stot, double atot, double utot, double ifitot, double ifato } static void -json_disp_bar(double perct) +json_disp_bar(double used, double size, double gsize) { - (void)perct; + (void)used; + (void)size; + (void)gsize; /* DUMMY */ } diff --git a/src/export/tex.c b/src/export/tex.c index 438e29a..e88636c 100644 --- a/src/export/tex.c +++ b/src/export/tex.c @@ -54,7 +54,7 @@ static void tex_disp_deinit(void); static void tex_disp_header(void); static void tex_disp_sum(double stot, double utot, double ftot, double ifitot, double ifatot); -static void tex_disp_bar(double perct); +static void tex_disp_bar(double perct, double size, double gsize); static void tex_disp_uat(double n, double perct, int req_width); static void tex_disp_fs(const char *fsname); static void tex_disp_type(const char *type); @@ -185,7 +185,7 @@ tex_disp_sum(double stot, double atot, double utot, (void)printf(" & N/A"); if (!bflag) - tex_disp_bar(ptot); + tex_disp_bar(ptot, stot, maxfssize); tex_disp_perct(ptot); @@ -213,52 +213,66 @@ tex_disp_sum(double stot, double atot, double utot, /* * Display the nice usage bar - * @perct: percentage value + * @perct: usage percentage + * @size: how much total space this volume has + * @gsize: how much total space the greatest volume has */ static void -tex_disp_bar(double perct) +tex_disp_bar(double perct, double size, double gsize) { /* * It could be nice to have a non-ASCII graph bar but it requires TeX * packages usually using postscript and so on. So stick with ASCII for * now until someone shows up with a better idea. */ - int i, j; - int barinc = 5; + int i; + double uperct, sperct; + if (agflag) { + // used percentage on the current volume: + uperct = perct * size / gsize; + // percentage of the current volume size on the greatest volume size: + sperct = size * 100 / gsize; + } else { + uperct = perct; + sperct = 100; + } - (void)printf(" & "); + int barinc = 100 / ((wflag ? GRAPHBAR_WIDE : GRAPHBAR_SHORT) - 2); - /* option to display a wider bar */ - if (wflag) { - barinc = 2; - } + (void)printf(" & "); if (!cflag) { - for (i = 0; i < perct; i += barinc) + for (i = 0; i < uperct; i += barinc) (void)printf("%c", cnf.gsymbol); - for (j = i; j < 100; j += barinc) + for (; i < sperct; i += barinc) (void)printf("\\-"); + + for (; i < 100; i += barinc) + (void)printf(" "); } else { /* color */ /* green */ (void)printf("\\textcolor{%s}{", colortostr(cnf.clow)); - for (i = 0; (i < cnf.gmedium) && (i < perct); i += barinc) + for (i = 0; (i < cnf.gmedium * sperct / 100) && (i < uperct); i += barinc) (void)printf("%c", cnf.gsymbol); /* yellow */ (void)printf("}\\textcolor{%s}{", colortostr(cnf.cmedium)); - for (; (i < cnf.ghigh) && (i < perct); i += barinc) + for (; (i < cnf.ghigh * sperct / 100) && (i < uperct); i += barinc) (void)printf("%c", cnf.gsymbol); /* red */ (void)printf("}\\textcolor{%s}{", colortostr(cnf.chigh)); - for (; (i < 100) && (i < perct); i += barinc) + for (; (i < sperct) && (i < uperct); i += barinc) (void)printf("%c", cnf.gsymbol); (void)printf("}"); - for (j = i; j < 100; j += barinc) - (void)printf("\\-"); + for (; i < sperct; i += barinc) + (void)printf("\\- "); + + for (; i < 100; i += barinc) + (void)printf(" "); } } diff --git a/src/export/text.c b/src/export/text.c index 2c33321..89dbbde 100644 --- a/src/export/text.c +++ b/src/export/text.c @@ -52,7 +52,7 @@ static void text_disp_header(void); static void text_disp_sum(double stot, double utot, double ftot, double ifitot, double ifatot); -static void text_disp_bar(double perct); +static void text_disp_bar(double perct, double size, double max); static void text_disp_uat(double n, double perct, int req_width); static void text_disp_fs(const char *fsname); static void text_disp_type(const char *type); @@ -166,8 +166,15 @@ text_disp_sum(double stot, double atot, double utot, (void)printf("%-*s", width, _("SUM:")); reset_color(); - if (!bflag) - text_disp_bar(ptot); + if (!bflag) { + text_disp_bar(ptot, stot, maxfssize); + if (agflag) { + // Display everything after the bar in a new row, indented correctly: + int barsize = wflag ? GRAPHBAR_WIDE : GRAPHBAR_SHORT; + int gap = max.fsname + barsize; + (void)printf("\n%*c", gap, ' '); + } + } text_disp_perct(ptot); @@ -191,49 +198,65 @@ text_disp_sum(double stot, double atot, double utot, /* * Display the nice usage bar - * @perct: percentage value + * @perct: usage percentage + * @size: how much total space this volume has + * @gsize: how much total space the greatest volume has */ static void -text_disp_bar(double perct) +text_disp_bar(double perct, double size, double gsize) { - int i, j; - int barinc = 5; - - /* option to display a wider bar */ - if (wflag) { - barinc = 2; + int i; + double uperct, sperct; + if (agflag) { + // used percentage on the current volume: + uperct = perct * size / gsize; + // percentage of the current volume size on the greatest volume size: + sperct = size * 100 / gsize; + // one problem is that fs's with exactly 0.0 % usage are shown + // as empty (-) but fs's with something in between 0.0 % and 0.04 % + // are shown as full (=) because of the i < uperct check. + } else { + uperct = perct; + sperct = 100; } + int barinc = 100 / ((wflag ? GRAPHBAR_WIDE : GRAPHBAR_SHORT) - 2); /* used (*) */ (void)printf("["); if (!cflag) { - for (i = 0; i < perct; i += barinc) + for (i = 0; i < uperct; i += barinc) (void)printf("%c", cnf.gsymbol); - for (j = i; j < 100; j += barinc) + for (; i < sperct; i += barinc) (void)printf("-"); + + for (; i < 100; i += barinc) + (void)printf(" "); } else { /* color */ /* green */ (void)printf("\033[%d;%dm", cnf.font_type , cnf.clow); - for (i = 0; (i < cnf.gmedium) && (i < perct); i += barinc) + for (i = 0; (i < cnf.gmedium * sperct / 100) && (i < uperct); i += barinc) (void)printf("%c", cnf.gsymbol); /* yellow */ (void)printf("\033[%d;%dm", cnf.font_type , cnf.cmedium); - for (; (i < cnf.ghigh) && (i < perct); i += barinc) + for (; (i < cnf.ghigh * sperct / 100) && (i < uperct); i += barinc) (void)printf("%c", cnf.gsymbol); /* red */ (void)printf("\033[%d;%dm", cnf.font_type , cnf.chigh); - for (; (i < 100) && (i < perct); i += barinc) + for (; (i < sperct) && (i < uperct); i += barinc) (void)printf("%c", cnf.gsymbol); reset_color(); - for (j = i; j < 100; j += barinc) + for (; i < sperct; i += barinc) (void)printf("-"); + + for (; i < 100; i += barinc) + (void)printf(" "); } (void)printf("]"); diff --git a/src/extern.h b/src/extern.h index 210a0a5..84224aa 100644 --- a/src/extern.h +++ b/src/extern.h @@ -125,10 +125,11 @@ extern struct conf cnf; /* struct to store maximum required widths (useful only in text export mode) */ extern struct maxwidths max; +extern double maxfssize; /* set flags for options */ extern int aflag, bflag, cflag, dflag, eflag, fflag, hflag, iflag, lflag, mflag, - nflag, oflag, pflag, qflag, sflag, tflag, uflag, vflag, wflag; + nflag, oflag, pflag, qflag, sflag, tflag, uflag, vflag, wflag, agflag; extern int Mflag, Tflag, Wflag; /* flag that determines which unit is in use (Ko, Mo, etc.) */ diff --git a/src/util.c b/src/util.c index 2d889f2..033438c 100644 --- a/src/util.c +++ b/src/util.c @@ -85,6 +85,17 @@ imax(int a, int b) return (a > b ? a : b); } +/* + * Return the larger of the two floating-point numbers + * @a: first element to compare + * @b: second element to compare + */ +double +dmax(double a, double b) +{ + return (a > b ? a : b); +} + /* * trim withespaces from the input string and returns it * @str: string that needs to be trimmed @@ -518,6 +529,7 @@ init_maxwidths(void) max.avinodes = iflag ? (int)strlen(_("AV.INODES")) + 1 : 0; max.mntdir = Mflag ? 0 : (int)strlen(_("MOUNTED ON")) + 1; max.mntopts = oflag ? (int)strlen(_("MOUNT OPTIONS")) + 1: 0; + maxfssize = 0; } /* @@ -599,6 +611,8 @@ update_maxwidth(struct fsmntinfo *fmi) max.nbinodes = imax(2 + count_digit(fmi->files), max.nbinodes); max.avinodes = imax(3 + count_digit(fmi->ffree), max.avinodes); } + + maxfssize = dmax(fmi->total, maxfssize); } /* diff --git a/src/util.h b/src/util.h index c6f1130..690787b 100644 --- a/src/util.h +++ b/src/util.h @@ -44,6 +44,7 @@ /* function declaration */ int imax(int a, int b); +double dmax(double a, double b); char * strtrim(char *str); char * shortenstr(char *str, int len); char * sanitizestr(const char *str);