Merge pull request #10902 from poettering/highlight-status
Highlight status
This commit is contained in:
commit
6fa158f55c
|
@ -1371,12 +1371,12 @@ static int status_welcome(void) {
|
|||
"Failed to read os-release file, ignoring: %m");
|
||||
|
||||
if (log_get_show_color())
|
||||
return status_printf(NULL, false, false,
|
||||
return status_printf(NULL, 0,
|
||||
"\nWelcome to \x1B[%sm%s\x1B[0m!\n",
|
||||
isempty(ansi_color) ? "1" : ansi_color,
|
||||
isempty(pretty_name) ? "Linux" : pretty_name);
|
||||
else
|
||||
return status_printf(NULL, false, false,
|
||||
return status_printf(NULL, 0,
|
||||
"\nWelcome to %s!\n",
|
||||
isempty(pretty_name) ? "Linux" : pretty_name);
|
||||
}
|
||||
|
|
|
@ -4156,7 +4156,7 @@ void manager_status_printf(Manager *m, StatusType type, const char *status, cons
|
|||
return;
|
||||
|
||||
va_start(ap, format);
|
||||
status_vprintf(status, true, type == STATUS_TYPE_EPHEMERAL, format, ap);
|
||||
status_vprintf(status, SHOW_STATUS_ELLIPSIZE|(type == STATUS_TYPE_EPHEMERAL ? SHOW_STATUS_EPHEMERAL : 0), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ int parse_show_status(const char *v, ShowStatus *ret) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) {
|
||||
int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
|
||||
static const char status_indent[] = " "; /* "[" STATUS "] " */
|
||||
_cleanup_free_ char *s = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
@ -57,7 +57,7 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
|
|||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
if (ellipse) {
|
||||
if (FLAGS_SET(flags, SHOW_STATUS_ELLIPSIZE)) {
|
||||
char *e;
|
||||
size_t emax, sl;
|
||||
int c;
|
||||
|
@ -73,10 +73,8 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
|
|||
emax = 3;
|
||||
|
||||
e = ellipsize(s, emax, 50);
|
||||
if (e) {
|
||||
free(s);
|
||||
s = e;
|
||||
}
|
||||
if (e)
|
||||
free_and_replace(s, e);
|
||||
}
|
||||
|
||||
if (prev_ephemeral)
|
||||
|
@ -94,9 +92,9 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
|
|||
iovec[n++] = IOVEC_MAKE_STRING(s);
|
||||
iovec[n++] = IOVEC_MAKE_STRING("\n");
|
||||
|
||||
if (prev_ephemeral && !ephemeral)
|
||||
if (prev_ephemeral && !FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL))
|
||||
iovec[n++] = IOVEC_MAKE_STRING(ANSI_ERASE_TO_END_OF_LINE);
|
||||
prev_ephemeral = ephemeral;
|
||||
prev_ephemeral = FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL) ;
|
||||
|
||||
if (writev(fd, iovec, n) < 0)
|
||||
return -errno;
|
||||
|
@ -104,14 +102,14 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
|
|||
return 0;
|
||||
}
|
||||
|
||||
int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) {
|
||||
int status_printf(const char *status, ShowStatusFlags flags, const char *format, ...) {
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
assert(format);
|
||||
|
||||
va_start(ap, format);
|
||||
r = status_vprintf(status, ellipse, ephemeral, format, ap);
|
||||
r = status_vprintf(status, flags, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return r;
|
||||
|
|
|
@ -16,9 +16,14 @@ typedef enum ShowStatus {
|
|||
_SHOW_STATUS_INVALID = -1,
|
||||
} ShowStatus;
|
||||
|
||||
typedef enum ShowStatusFlags {
|
||||
SHOW_STATUS_ELLIPSIZE = 1 << 0,
|
||||
SHOW_STATUS_EPHEMERAL = 1 << 1,
|
||||
} ShowStatusFlags;
|
||||
|
||||
ShowStatus show_status_from_string(const char *v) _const_;
|
||||
const char* show_status_to_string(ShowStatus s) _pure_;
|
||||
int parse_show_status(const char *v, ShowStatus *ret);
|
||||
|
||||
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
|
||||
int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
|
||||
int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) _printf_(3,0);
|
||||
int status_printf(const char *status, ShowStatusFlags flags, const char *format, ...) _printf_(3,4);
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "umask-util.h"
|
||||
#include "unit-name.h"
|
||||
#include "unit.h"
|
||||
|
@ -1644,12 +1645,17 @@ static bool unit_assert_test(Unit *u) {
|
|||
}
|
||||
|
||||
void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) {
|
||||
const char *d;
|
||||
|
||||
d = unit_description(u);
|
||||
if (log_get_show_color())
|
||||
d = strjoina(ANSI_HIGHLIGHT, d, ANSI_NORMAL);
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
manager_status_printf(u->manager, STATUS_TYPE_NORMAL, status, unit_status_msg_format, unit_description(u));
|
||||
manager_status_printf(u->manager, STATUS_TYPE_NORMAL, status, unit_status_msg_format, d);
|
||||
REENABLE_WARNING;
|
||||
}
|
||||
|
||||
|
||||
int unit_start_limit_test(Unit *u) {
|
||||
const char *reason;
|
||||
|
||||
|
|
Loading…
Reference in a new issue