commit - 4520a881d8164136ec55669256567eea65478182
commit + da455e1677ba34f44620a76213c5abce75d91572
blob - e5ee6dd39ffde161751e1ce10e4cc93924b7ffbe
blob + eb3757e17e136bd774a8a29f8467381457ff5761
--- lsblk.c
+++ lsblk.c
#include <util.h>
#include <err.h>
+#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 };
enum {
OPT_NOHEADER = 0x01,
- OPT_NOUNICODE = 0x02,
- OPT_NOBIO = 0x04,
+ OPT_NOBIO = 0x02,
};
struct my_diskinfo;
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,
const struct padding *p
) {
if (fields & FIELD_NAME) {
- const char *prefix = raidstatus ? (options & OPT_NOUNICODE ? " " : "│ └─") : "";
+ const char *prefix = raidstatus ? prefix2 : "";
printf (
"%s%-*s ",
int fields = FIELD_DEFAULT;
int options = 0;
int ret = 0;
+ bool ascii = false;
if (unveil ("/dev", "r") == -1)
err (1, "unveil(/dev)");
options |= OPT_NOBIO;
break;
case 'i':
- options |= OPT_NOUNICODE;
+ ascii = true;
break;
case 'n':
options |= OPT_NOHEADER;
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;
return ret;
}
+
+/* vim: set tabstop=4 shiftwidth=4 expandtab: */