From b7dd708d309d86625e3d6cb2f479bed5e5b55ee1 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 29 Jun 2016 12:51:39 +0100 Subject: [PATCH] p2v: Colourize kernel-conversion status messages from virt-p2v. The messages that come "through" from virt-v2v are already colourized. However the other messages are not. This colourizes the ones generated during kernel-mode conversions. Note that because of the way journal/syslog works we have to write the ansi_restore before the end of line, thus code like this: ansi_magenta (stdout); printf ("%s: %s", guestfs_int_program_name, data); ansi_restore (stdout); putchar ('\n'); This also adds a "Conversion finished successfully" message (in green). Thanks: Ming Xie (cherry picked from commit b15b6e69e37cb3b6520d301442a67b9971ae8d51) --- p2v/kernel.c | 23 +++++++++++++++++++---- p2v/launch-virt-p2v.in | 4 ++-- p2v/main.c | 12 ++++++++++++ p2v/p2v.h | 3 +++ p2v/virt-p2v.pod | 9 +++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/p2v/kernel.c b/p2v/kernel.c index 6d9388b..6914ab5 100644 --- a/p2v/kernel.c +++ b/p2v/kernel.c @@ -250,6 +250,11 @@ kernel_conversion (struct config *config, char **cmdline, int cmdline_source) exit (EXIT_FAILURE); } + ansi_green (stdout); + printf ("Conversion finished successfully."); + ansi_restore (stdout); + putchar ('\n'); + p = get_cmdline_key (cmdline, "p2v.post"); if (!p) { if (geteuid () == 0 && cmdline_source == CMDLINE_SOURCE_PROC_CMDLINE) @@ -264,8 +269,12 @@ notify_ui_callback (int type, const char *data) { switch (type) { case NOTIFY_LOG_DIR: - printf ("%s: remote log directory location: %s\n", - guestfs_int_program_name, data); + ansi_magenta (stdout); + printf ("%s: remote log directory location: ", guestfs_int_program_name); + ansi_red (stdout); + fputs (data, stdout); + ansi_restore (stdout); + putchar ('\n'); break; case NOTIFY_REMOTE_MESSAGE: @@ -273,12 +282,18 @@ notify_ui_callback (int type, const char *data) break; case NOTIFY_STATUS: - printf ("%s: %s\n", guestfs_int_program_name, data); + ansi_magenta (stdout); + printf ("%s: %s", guestfs_int_program_name, data); + ansi_restore (stdout); + putchar ('\n'); break; default: - printf ("%s: unknown message during conversion: type=%d data=%s\n", + ansi_red (stdout); + printf ("%s: unknown message during conversion: type=%d data=%s", guestfs_int_program_name, type, data); + ansi_restore (stdout); + putchar ('\n'); } fflush (stdout); diff --git a/p2v/launch-virt-p2v.in b/p2v/launch-virt-p2v.in index 3e4f1f9..ca971a0 100755 --- a/p2v/launch-virt-p2v.in +++ b/p2v/launch-virt-p2v.in @@ -23,7 +23,7 @@ cmdline=$(, parse the string parameter C. +=item B<--colors> + +=item B<--colours> + +Use ANSI colour sequences to colourize messages. This is the default +when the output is a tty. If the output of the program is redirected +to a file, ANSI colour sequences are disabled unless you use this +option. + =item B<--iso> This flag is passed to virt-p2v when it is launched inside the -- 2.7.4