From 80a1712f546eb0669c9e4130a32c78cdeeb5fdab Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 2 Sep 2013 10:54:30 +0200 Subject: fdisk: add -L to colorize output Signed-off-by: Karel Zak --- fdisks/fdisk.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'fdisks/fdisk.c') diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index 05f4ccb58..ec0c5447f 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -60,6 +60,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out) fputs(_(" -b sector size (512, 1024, 2048 or 4096)\n"), out); fputs(_(" -c[=] compatible mode: 'dos' or 'nondos' (default)\n"), out); fputs(_(" -h print this help text\n"), out); + fputs(_(" -c[=] compatible mode: 'dos' or 'nondos' (default)\n"), out); + fputs(_(" -L[=] colorize output (auto, always or never)\n"), out); fputs(_(" -u[=] display units: 'cylinders' or 'sectors' (default)\n"), out); fputs(_(" -v print program version\n"), out); fputs(_(" -C specify the number of cylinders\n"), out); @@ -341,6 +343,7 @@ enum { int main(int argc, char **argv) { int i, c, act = ACT_FDISK; + int colormode = UL_COLORMODE_AUTO; struct fdisk_context *cxt; setlocale(LC_ALL, ""); @@ -355,7 +358,7 @@ int main(int argc, char **argv) fdisk_context_set_ask(cxt, ask_callback, NULL); - while ((c = getopt(argc, argv, "b:c::C:hH:lsS:u::vV")) != -1) { + while ((c = getopt(argc, argv, "b:c::C:hH:lL::sS:u::vV")) != -1) { switch (c) { case 'b': { @@ -402,6 +405,11 @@ int main(int argc, char **argv) case 'l': act = ACT_LIST; break; + case 'L': + if (optarg) + colormode = colormode_or_err(optarg, + _("unsupported color mode")); + break; case 's': act = ACT_SHOWSIZE; break; @@ -454,13 +462,17 @@ int main(int argc, char **argv) if (argc-optind != 1) usage(stderr); + colors_init(colormode); + if (fdisk_context_assign_device(cxt, argv[optind], 0) != 0) err(EXIT_FAILURE, _("cannot open %s"), argv[optind]); /* Here starts interactive mode, use fdisk_{warn,info,..} functions */ - fdisk_info(cxt, _("Welcome to fdisk (%s).\n\n" - "Changes will remain in memory only, until you decide to write them.\n" - "Be careful before using the write command.\n"), PACKAGE_STRING); + color_enable(UL_COLOR_GREEN); + fdisk_info(cxt, _("Welcome to fdisk (%s).\n"), PACKAGE_STRING); + color_disable(); + fdisk_info(cxt, _("Changes will remain in memory only, until you decide to write them.\n" + "Be careful before using the write command.\n")); fflush(stdout); if (!fdisk_dev_has_disklabel(cxt)) { -- cgit v1.2.3-55-g7522