mirror of
https://github.com/perk11/runwhenidle.git
synced 2026-01-09 13:48:01 -05:00
Simplify logic in fprintf_error
This commit is contained in:
16
tty_utils.c
16
tty_utils.c
@@ -4,16 +4,12 @@
|
||||
#include <stdbool.h>
|
||||
#include "tty_utils.h"
|
||||
|
||||
void print_colored_prefix(FILE *stream, const char *color, bool is_tty) {
|
||||
if (is_tty) {
|
||||
fprintf(stream, "\033[%sm", color);
|
||||
}
|
||||
void print_colored_prefix(FILE *stream, const char *color) {
|
||||
fprintf(stream, "\033[%sm", color);
|
||||
}
|
||||
|
||||
void print_colored_suffix(FILE *stream, bool is_tty) {
|
||||
if (is_tty) {
|
||||
fprintf(stream, "\033[0m");
|
||||
}
|
||||
void print_colored_suffix(FILE *stream) {
|
||||
fprintf(stream, "\033[0m");
|
||||
}
|
||||
|
||||
void fprintf_error(const char *format, ...) {
|
||||
@@ -21,9 +17,9 @@ void fprintf_error(const char *format, ...) {
|
||||
va_start(args, format);
|
||||
|
||||
bool is_tty = isatty(fileno(stderr));
|
||||
print_colored_prefix(stderr, "31", is_tty);
|
||||
if (is_tty) print_colored_prefix(stderr, "31");
|
||||
vfprintf(stderr, format, args);
|
||||
print_colored_suffix(stderr, is_tty);
|
||||
if (is_tty) print_colored_suffix(stderr);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
Reference in New Issue
Block a user