goto cleanup;
}
- r = print_qrcode_full(stream, "Scan the QR code", message, qr_code_start_row, qr_code_start_column, w.ws_col, w.ws_row);
+ r = print_qrcode_full(stream, "Scan the QR code",
+ message, qr_code_start_row, qr_code_start_column, w.ws_col, w.ws_row,
+ /* check_tty= */ false);
if (r < 0)
log_warning_errno(r, "QR code could not be printed, ignoring: %m");
fflush(output);
}
-int print_qrcode_full(FILE *out, const char *header, const char *string, unsigned row, unsigned column, unsigned tty_width, unsigned tty_height) {
+int print_qrcode_full(
+ FILE *out,
+ const char *header,
+ const char *string,
+ unsigned row,
+ unsigned column,
+ unsigned tty_width,
+ unsigned tty_height,
+ bool check_tty) {
+
QRcode* qr;
int r;
* codes */
if (!is_locale_utf8())
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not an UTF-8 system, cannot print qrcode");
- if (!colors_enabled())
+ if (check_tty && !colors_enabled())
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Colors are disabled, cannot print qrcode");
r = dlopen_qrencode();
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
#pragma once
+
+#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#if HAVE_QRENCODE
int dlopen_qrencode(void);
-int print_qrcode_full(FILE *out, const char *header, const char *string, unsigned row, unsigned column, unsigned tty_width, unsigned tty_height);
-static inline int print_qrcode(FILE *out, const char *header, const char *string) {
- return print_qrcode_full(out, header, string, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
-}
+int print_qrcode_full(
+ FILE *out,
+ const char *header,
+ const char *string,
+ unsigned row,
+ unsigned column,
+ unsigned tty_width,
+ unsigned tty_height,
+ bool check_tty);
#else
-static inline int print_qrcode_full(FILE *out, const char *header, const char *string, unsigned row, unsigned column, unsigned tty_width, unsigned tty_height) {
+static inline int print_qrcode_full(
+ FILE *out,
+ const char *header,
+ const char *string,
+ unsigned row,
+ unsigned column,
+ unsigned tty_width,
+ unsigned tty_height,
+ bool check_tty) {
return -EOPNOTSUPP;
}
+#endif
+
static inline int print_qrcode(FILE *out, const char *header, const char *string) {
- return -EOPNOTSUPP;
+ return print_qrcode_full(out, header, string, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, true);
}
-#endif