show-status: fold two bool flags function arguments into a flags

parameter
This commit is contained in:
Lennart Poettering 2018-11-23 17:18:48 +01:00
parent a0ee3d93bb
commit a885727a64
4 changed files with 16 additions and 11 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
@ -94,9 +94,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 +104,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;

View File

@ -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);