commit da455e1677ba34f44620a76213c5abce75d91572 from: Benjamin Stürz date: Fri Sep 01 09:45:22 2023 UTC Change output of -i option Signed-off-by: Benjamin Stürz commit - 4520a881d8164136ec55669256567eea65478182 commit + da455e1677ba34f44620a76213c5abce75d91572 blob - e5ee6dd39ffde161751e1ce10e4cc93924b7ffbe blob + eb3757e17e136bd774a8a29f8467381457ff5761 --- lsblk.c +++ lsblk.c @@ -41,6 +41,15 @@ #include #include +#define PREFIX0_ASCII "|-" +#define PREFIX0_UNICODE "├─" +#define PREFIX1_ASCII "`-" +#define PREFIX1_UNICODE "└─" +#define PREFIX2_ASCII "| `-" +#define PREFIX2_UNICODE "│ └─" + +static const char *prefix0, *prefix1, *prefix2; + static int diskcount (void) { const int mib[2] = { CTL_HW, HW_DISKCOUNT }; @@ -132,8 +141,7 @@ enum { enum { OPT_NOHEADER = 0x01, - OPT_NOUNICODE = 0x02, - OPT_NOBIO = 0x04, + OPT_NOBIO = 0x02, }; struct my_diskinfo; @@ -218,7 +226,7 @@ static void print_part ( const struct padding *p ) { if (fields & FIELD_NAME) { - const char *prefix = (options & OPT_NOUNICODE) ? " " : (last ? "└─" : "├─"); + const char *prefix = last ? prefix1 : prefix0; printf ( "%s%s%c%-*s ", prefix, @@ -278,7 +286,7 @@ static void print_disk ( const struct padding *p ) { if (fields & FIELD_NAME) { - const char *prefix = raidstatus ? (options & OPT_NOUNICODE ? " " : "│ └─") : ""; + const char *prefix = raidstatus ? prefix2 : ""; printf ( "%s%-*s ", @@ -579,6 +587,7 @@ int main (int argc, char *argv[]) int fields = FIELD_DEFAULT; int options = 0; int ret = 0; + bool ascii = false; if (unveil ("/dev", "r") == -1) err (1, "unveil(/dev)"); @@ -595,7 +604,7 @@ int main (int argc, char *argv[]) options |= OPT_NOBIO; break; case 'i': - options |= OPT_NOUNICODE; + ascii = true; break; case 'n': options |= OPT_NOHEADER; @@ -622,6 +631,10 @@ int main (int argc, char *argv[]) if (pledge ("stdio rpath disklabel", NULL) == -1) err (1, "pledge()"); + prefix0 = ascii ? PREFIX0_ASCII : PREFIX0_UNICODE; + prefix1 = ascii ? PREFIX1_ASCII : PREFIX1_UNICODE; + prefix2 = ascii ? PREFIX2_ASCII : PREFIX2_UNICODE; + size_t cap_disks; if (argc == 0) { const char *s = names; @@ -700,3 +713,5 @@ int main (int argc, char *argv[]) return ret; } + +/* vim: set tabstop=4 shiftwidth=4 expandtab: */