about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorswirl <swurl@swurl.xyz>2022-05-27 15:45:38 -0400
committerMichael Vetter <jubalh@iodoru.org>2022-05-30 18:04:42 +0200
commitd64cb38240bd6db10135b6007f42dab6851ca559 (patch)
tree5534bb1af11c9c1d8e4a6feb850dea26ab4813fb /src/ui
parent9a9a97868d0366408d7a310de3fa7158a294854e (diff)
downloadprofani-tty-d64cb38240bd6db10135b6007f42dab6851ca559.tar.gz
Reverse QR code colors and add padding
All QR scanners should be able to recognize this, as it is now the
correct color with some padding to prevent blending.

Signed-off-by: swirl <swurl@swurl.xyz>
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/console.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index e0b0fa4d..89c3cf29 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -871,24 +871,37 @@ cons_show_omemo_qrcode(const char* const text)
 {
 #ifdef HAVE_QRENCODE
     static const size_t ZOOM_SIZE = 10;
-    QRcode *qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
+    QRcode* qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
 
     int width = (qrcode->width * ZOOM_SIZE);
-    unsigned char *data = qrcode->data;
+    unsigned char* data = qrcode->data;
 
     ProfWin* console = wins_get_console();
 
     char buf[(width * 4) + 1];
     memset(buf, 0, sizeof buf);
-    for (size_t y = 0; y < width; y+=ZOOM_SIZE) {
-        for (size_t x = 0; x < width; x+=ZOOM_SIZE) {
-            strcat(buf, (*data & 1) ? "\u2588\u2588" : "\u2800\u2800");
+
+    char tmp[(width * 4) + 5];
+    memset(tmp, 0, sizeof tmp);
+
+    for (int i = 0; i < width + 2 * ZOOM_SIZE; i += ZOOM_SIZE) {
+        strcat(tmp, "\u2588\u2588");
+    }
+
+    win_println(console, THEME_DEFAULT, "", tmp);
+    for (size_t y = 0; y < width; y += ZOOM_SIZE) {
+        for (size_t x = 0; x < width; x += ZOOM_SIZE) {
+            strcat(buf, !(*data & 1) ? "\u2588\u2588" : "\u2800\u2800");
 
             data++;
         }
-        win_println(console, THEME_DEFAULT, "", "%s", buf);
+
+        // The extra squares are for padding, so that the QR code doesn't
+        // "blend in" with the rest of the terminal window.
+        win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf);
         memset(buf, 0, sizeof buf);
     }
+    win_println(console, THEME_DEFAULT, "", "%s", tmp);
 
     QRcode_free(qrcode);
 #endif
@@ -2926,4 +2939,3 @@ cons_remove_alert(ProfWin* window)
     g_list_free_full(item, g_free);
     free(win_name);
 }
-