app/status: factor out escape chars logic
Make use of the new `glnx_stdout_is_console ()` rather than caching our own result of `isatty()`. Add helper functions in `libbuiltin.h` to retrieve escape characters. Prep for using them from other files. Update submodule: libglnx Closes: #1196 Approved by: cgwalters
This commit is contained in:
parent
c80a4168de
commit
778a78bb9f
2
libglnx
2
libglnx
@ -1 +1 @@
|
||||
Subproject commit 96b1fd9578b3d6ff2d8e0707068f5ef450eba98c
|
||||
Subproject commit 6f1ee5db1400b13a9a0fa0b2274ae34e8710c1aa
|
@ -28,6 +28,7 @@
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "rpmostree-builtins.h"
|
||||
#include "rpmostree-libbuiltin.h"
|
||||
#include "rpmostree-dbus-helpers.h"
|
||||
#include "rpmostree-util.h"
|
||||
#include "rpmostree-rpm-util.h"
|
||||
@ -206,11 +207,6 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
|
||||
{
|
||||
GVariantIter iter;
|
||||
gboolean first = TRUE;
|
||||
const int is_tty = isatty (1);
|
||||
const char *bold_prefix = is_tty ? "\x1b[1m" : "";
|
||||
const char *bold_suffix = is_tty ? "\x1b[0m" : "";
|
||||
const char *red_prefix = is_tty ? "\x1b[31m" : "";
|
||||
const char *red_suffix = is_tty ? "\x1b[22m" : "";
|
||||
|
||||
/* First, gather global state */
|
||||
gboolean have_any_live_overlay = FALSE;
|
||||
@ -380,8 +376,8 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
|
||||
if (version_string)
|
||||
{
|
||||
g_autofree char *version_time
|
||||
= g_strdup_printf ("%s%s%s (%s)", bold_prefix, version_string,
|
||||
bold_suffix, timestamp_string);
|
||||
= g_strdup_printf ("%s%s%s (%s)", get_bold_start (), version_string,
|
||||
get_bold_end (), timestamp_string);
|
||||
print_kv ("Version", max_key_len, version_time);
|
||||
}
|
||||
else
|
||||
@ -415,18 +411,18 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
|
||||
if (live_inprogress)
|
||||
{
|
||||
if (is_booted)
|
||||
g_print ("%s%s", red_prefix, bold_prefix);
|
||||
g_print ("%s%s", get_red_start (), get_bold_start ());
|
||||
print_kv ("InterruptedLiveCommit", max_key_len, live_inprogress);
|
||||
if (is_booted)
|
||||
g_print ("%s%s", bold_suffix, red_suffix);
|
||||
g_print ("%s%s", get_bold_end (), get_red_end ());
|
||||
}
|
||||
if (live_replaced)
|
||||
{
|
||||
if (is_booted)
|
||||
g_print ("%s%s", red_prefix, bold_prefix);
|
||||
g_print ("%s%s", get_red_start (), get_bold_start ());
|
||||
print_kv ("LiveCommit", max_key_len, live_replaced);
|
||||
if (is_booted)
|
||||
g_print ("%s%s", bold_suffix, red_suffix);
|
||||
g_print ("%s%s", get_bold_end (), get_red_end ());
|
||||
}
|
||||
|
||||
/* Show any difference between the baseref vs head, but only for the
|
||||
@ -635,9 +631,9 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
|
||||
|
||||
if (unlocked && g_strcmp0 (unlocked, "none") != 0)
|
||||
{
|
||||
g_print ("%s%s", red_prefix, bold_prefix);
|
||||
g_print ("%s%s", get_red_start (), get_bold_start ());
|
||||
print_kv ("Unlocked", max_key_len, unlocked);
|
||||
g_print ("%s%s", bold_suffix, red_suffix);
|
||||
g_print ("%s%s", get_bold_end (), get_red_end ());
|
||||
}
|
||||
const char *end_of_life_string = NULL;
|
||||
/* look for endoflife attribute in the deployment */
|
||||
@ -645,9 +641,9 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
|
||||
|
||||
if (end_of_life_string)
|
||||
{
|
||||
g_print ("%s%s", red_prefix, bold_prefix);
|
||||
g_print ("%s%s", get_red_start (), get_bold_start ());
|
||||
print_kv ("EndOfLife", max_key_len, end_of_life_string);
|
||||
g_print ("%s%s", bold_suffix, red_suffix);
|
||||
g_print ("%s%s", get_bold_end (), get_red_end ());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,26 @@
|
||||
|
||||
#include <ostree.h>
|
||||
|
||||
#include "libglnx.h"
|
||||
|
||||
#include "rpm-ostreed-generated.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define TERM_ESCAPE_SEQUENCE(type,seq) \
|
||||
static inline const char* get_##type (void) { \
|
||||
if (glnx_stdout_is_tty ()) \
|
||||
return seq; \
|
||||
return ""; \
|
||||
}
|
||||
|
||||
TERM_ESCAPE_SEQUENCE(red_start, "\x1b[31m")
|
||||
TERM_ESCAPE_SEQUENCE(red_end, "\x1b[22m")
|
||||
TERM_ESCAPE_SEQUENCE(bold_start, "\x1b[1m")
|
||||
TERM_ESCAPE_SEQUENCE(bold_end, "\x1b[0m")
|
||||
|
||||
#undef TERM_ESCAPE_SEQUENCE
|
||||
|
||||
void
|
||||
rpmostree_usage_error (GOptionContext *context,
|
||||
const char *message,
|
||||
|
Loading…
Reference in New Issue
Block a user