Add macros for common ANSI tty escape codes

tingping/wmclass
Alexander Larsson 2017-05-03 11:17:41 +02:00
parent 52be2e86c6
commit fb6695e9a4
6 changed files with 16 additions and 10 deletions

View File

@ -129,8 +129,8 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError *
if (flatpak_fancy_output ())
{
on = "\x1b[1m"; /* bold on */
off = "\x1b[22m"; /* bold off */
on = FLATPAK_ANSI_BOLD_ON;
off = FLATPAK_ANSI_BOLD_OFF; /* bold off */
}
parts = g_strsplit (ref, "/", 0);

View File

@ -485,8 +485,8 @@ main (int argc,
const char *suffix = "";
if (flatpak_fancy_output ())
{
prefix = "\x1b[31m\x1b[1m"; /* red, bold */
suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
prefix = FLATPAK_ANSI_RED FLATPAK_ANSI_BOLD_ON;
suffix = FLATPAK_ANSI_BOLD_OFF FLATPAK_ANSI_COLOR_RESET;
}
g_printerr ("%s%s %s%s\n", prefix, _("error:"), suffix, error->message);
g_error_free (error);

View File

@ -208,14 +208,14 @@ flatpak_table_printer_print (FlatpakTablePrinter *printer)
if (flatpak_fancy_output () && printer->titles->len > 0)
{
g_print ("\x1b[1m"); /* bold on */
g_print (FLATPAK_ANSI_BOLD_ON);
for (i = 0; i < printer->titles->len; i++)
{
char *title = g_ptr_array_index (printer->titles, i);
g_print ("%s%-*s", (i == 0) ? "" : " ", widths[i], title);
}
g_print ("\x1b[0m"); /* bold off */
g_print (FLATPAK_ANSI_BOLD_OFF);
g_print ("\n");
}

View File

@ -39,6 +39,12 @@ typedef enum {
typedef void (*FlatpakLoadUriProgress) (guint64 downloaded_bytes,
gpointer user_data);
#define FLATPAK_ANSI_BOLD_ON "\x1b[1m"
#define FLATPAK_ANSI_BOLD_OFF "\x1b[22m"
#define FLATPAK_ANSI_RED "\x1b[31m"
#define FLATPAK_ANSI_COLOR_RESET "\x1b[0m"
/* https://bugzilla.gnome.org/show_bug.cgi?id=766370 */
#if !GLIB_CHECK_VERSION(2, 49, 3)
#define FLATPAK_VARIANT_BUILDER_INITIALIZER {{0,}}

View File

@ -1053,8 +1053,8 @@ printerr_handler (const gchar *string)
const char *suffix = "";
if (flatpak_fancy_output ())
{
prefix = "\x1b[31m\x1b[1m"; /* red, bold */
suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
prefix = FLATPAK_ANSI_RED FLATPAK_ANSI_BOLD_ON;
suffix = FLATPAK_ANSI_BOLD_OFF FLATPAK_ANSI_COLOR_RESET;
}
fprintf (stderr, "%serror: %s%s\n", prefix, suffix, string);
}

View File

@ -83,8 +83,8 @@ printerr_handler (const gchar *string)
const char *suffix = "";
if (flatpak_fancy_output ())
{
prefix = "\x1b[31m\x1b[1m"; /* red, bold */
suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
prefix = FLATPAK_ANSI_RED FLATPAK_ANSI_BOLD_ON;
suffix = FLATPAK_ANSI_BOLD_OFF FLATPAK_ANSI_COLOR_RESET;
}
fprintf (stderr, "%serror: %s%s\n", prefix, suffix, string);
}