]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: improve info output
authorKarel Zak <kzak@redhat.com>
Fri, 30 Aug 2013 14:12:16 +0000 (16:12 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:09 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk-ask.c
fdisks/fdisk.c

index ad96ab1f2c3c47f4c6cd018ad8dacc565244b4a5..6c10a48c3461cb77d5d170cd481a2043a62b487b 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "fdisk.h"
 
+static unsigned int info_count;
+
 int get_user_reply(struct fdisk_context *cxt, const char *prompt,
                          char *buf, size_t bufsz)
 {
@@ -190,6 +192,14 @@ static int ask_offset(struct fdisk_context *cxt,
        return -1;
 }
 
+static void fputs_info(const char *msg, FILE *out)
+{
+       if (info_count == 1)
+               fputc('\n', out);
+       fputs(msg, out);
+       fputc('\n', out);
+}
+
 int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
                    void *data __attribute__((__unused__)))
 {
@@ -199,14 +209,17 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
        assert(cxt);
        assert(ask);
 
+       if (fdisk_ask_get_type(ask) != FDISK_ASKTYPE_INFO)
+               info_count = 0;
+
        switch(fdisk_ask_get_type(ask)) {
        case FDISK_ASKTYPE_NUMBER:
                return ask_number(cxt, ask, buf, sizeof(buf));
        case FDISK_ASKTYPE_OFFSET:
                return ask_offset(cxt, ask, buf, sizeof(buf));
        case FDISK_ASKTYPE_INFO:
-               fputs(fdisk_ask_print_get_mesg(ask), stdout);
-               fputc('\n', stdout);
+               info_count++;
+               fputs_info(fdisk_ask_print_get_mesg(ask), stdout);
                break;
        case FDISK_ASKTYPE_WARNX:
                fputs(fdisk_ask_print_get_mesg(ask), stderr);
@@ -226,6 +239,7 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
                DBG(ASK, dbgprint("yes-no ask: reply '%s' [rc=%d]", buf, rc));
                break;
        case FDISK_ASKTYPE_TABLE:
+               fputc('\n', stdout);
                tt_print_table(fdisk_ask_get_table(ask));
                break;
        case FDISK_ASKTYPE_STRING:
index 3fe7d1906d449befcdfa2aa2b1a5e8e04f1d4811..05f4ccb584ef5249879db70fd40fc8588f3de3f7 100644 (file)
@@ -201,7 +201,7 @@ void list_disk_geometry(struct fdisk_context *cxt)
        char *strsz = size_to_human_string(SIZE_SUFFIX_SPACE
                                           | SIZE_SUFFIX_3LETTER, bytes);
 
-       fdisk_info(cxt, _("\nDisk %s: %s, %llu bytes, %llu sectors"),
+       fdisk_info(cxt, _("Disk %s: %s, %llu bytes, %llu sectors"),
                        cxt->dev_path, strsz, bytes, cxt->total_sectors);
        free(strsz);
 
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
                        err(EXIT_FAILURE, _("cannot open %s"), argv[optind]);
 
                /* Here starts interactive mode, use fdisk_{warn,info,..} functions */
-               fdisk_info(cxt, _("\nWelcome to fdisk (%s).\n\n"
+               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);
                fflush(stdout);