]> code.citadel.org Git - citadel.git/commitdiff
work on sixel support master
authorArt Cancro <ajc@citadel.org>
Fri, 31 May 2024 17:00:10 +0000 (17:00 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 31 May 2024 17:00:10 +0000 (17:00 +0000)
libcitadel/lib/html_to_ascii.c
libcitadel/lib/libcitadel.h
textclient/citadel.c
textclient/citadel.rc
textclient/commands.c
textclient/messages.c

index 66c7a3b6c88a92d539cc8027ced6ad4132b054f4..47e0f0c8b7866dc7881b2cfd5fa48446eb4639fb 100644 (file)
@@ -16,9 +16,6 @@
 #include <time.h>
 #include "libcitadel.h"
 
 #include <time.h>
 #include "libcitadel.h"
 
-// silly but this shuts up the compiler warning about prototypes
-int u8_wc_toutf8(char *dest, u_int32_t ch);
-
 int u8_wc_toutf8(char *dest, u_int32_t ch) {
        if (ch < 0x80) {
                dest[0] = (char)ch;
 int u8_wc_toutf8(char *dest, u_int32_t ch) {
        if (ch < 0x80) {
                dest[0] = (char)ch;
@@ -46,6 +43,27 @@ int u8_wc_toutf8(char *dest, u_int32_t ch) {
 }
 
 
 }
 
 
+// Try to embed an image in the display stream.
+// out                 = the StrBuf to which we are writing the display stream
+// url                 = the URL of the image (warning: it might be a data: URL)
+// display_protocol    = currently only H2A_SIXEL is supported
+void h2a_embed_image(StrBuf *out, char *url, int display_protocol) {
+
+       char buf[4096];
+       snprintf(buf, sizeof(buf), "curl -s '%s' | img2sixel -", url);
+
+       FILE *cmd = popen(buf, "r");
+       if (!cmd) {
+               return;
+       }
+
+       size_t bytes;
+       while (bytes = fread(buf, 1, sizeof(buf), cmd), bytes>0) {
+               StrBufAppendBufPlain(out, buf, bytes, 0);
+       }
+       pclose(cmd);
+}
+
 
 // Convert HTML to plain text.
 //
 
 // Convert HTML to plain text.
 //
@@ -166,7 +184,11 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, unsigned
                                                                q2 = strchr(q1, '\'');
                                                        }
                                                        if (q1 && q1<q2 && q2<tag_end) {
                                                                q2 = strchr(q1, '\'');
                                                        }
                                                        if (q1 && q1<q2 && q2<tag_end) {
-                                                               // do something with the image url FIXME unfinished
+                                                               char url[SIZ];
+                                                               memcpy(url, q1, q2-q1);
+                                                               url[q2-q1] = 0;
+                                                               h2a_embed_image(out, url, H2A_SIXEL);           // try to display
+                                                               linelen = 0;
                                                        }
                                                }
                                        }
                                                        }
                                                }
                                        }
index 495d78da58448a027b92560a3754c0649f3d0ee0..9601f0dc10e65242c125e7ecf6fe974b5cc7eb60 100644 (file)
@@ -433,6 +433,8 @@ int is_msg_in_mset(const char *mset, long msgnum);
 int pattern2(char *search, char *patn);
 void LoadEntityList(char *FileName);
 void utf8ify_rfc822_string(char *buf);
 int pattern2(char *search, char *patn);
 void LoadEntityList(char *FileName);
 void utf8ify_rfc822_string(char *buf);
+int u8_wc_toutf8(char *dest, u_int32_t ch);
+void h2a_embed_image(StrBuf *out, char *url, int display_protocol);
 
 // flags for html_to_ascii
 #define H2A_ANSI       0x01            // it is acceptable to display ANSI graphics on this terminal
 
 // flags for html_to_ascii
 #define H2A_ANSI       0x01            // it is acceptable to display ANSI graphics on this terminal
index ba1be6cb3ce5ce958e1fdc893543fbba34ef943a..b5682cfb28dea9fd065d4ffc9a7c59dc8db23cd2 100644 (file)
@@ -52,6 +52,7 @@ int secure;                   /* Set to nonzero when wire is encrypted */
 
 extern char instant_msgs;      /* instant messages waiting! */
 extern int rc_ansi_color;      /* ansi color value from citadel.rc */
 
 extern char instant_msgs;      /* instant messages waiting! */
 extern int rc_ansi_color;      /* ansi color value from citadel.rc */
+extern int rc_sixel;           /* sixel graphics value from citadel.rc */
 extern int next_lazy_cmd;
 
 CtdlIPC *ipc_for_signal_handlers;      /* KLUDGE cover your eyes */
 extern int next_lazy_cmd;
 
 CtdlIPC *ipc_for_signal_handlers;      /* KLUDGE cover your eyes */
index 7f184dbcf4319fbc7309917d491a4443bc317006..263577e2b1faf2bfb838d3a8b33edcc8e208aa60 100644 (file)
@@ -36,6 +36,13 @@ encrypt=default
 #
 ansi_color=user
 
 #
 ansi_color=user
 
+# Sixel graphics support (experimental)
+# Set this to "on" to output images embedded in HTML messages to the terminal
+# in Sixel graphics format.  This obviously requires a terminal that has
+# support for Sixel.  It also requires the "curl" and "img2sixel" commands to
+# be available on your system.
+use_sixel=off
+
 # USE_BACKGROUND controls Citadel's use of the background.  If it is turned
 # off, then Citadel will set the background to black.  When it is turned on,
 # the background will be unchanged.  This is most useful with "transparent"
 # USE_BACKGROUND controls Citadel's use of the background.  If it is turned
 # off, then Citadel will set the background to black.  When it is turned on,
 # the background will be unchanged.  This is most useful with "transparent"
index c241f014d70a08c55c24e164cb0df6b889564044..6d39ca9b25b952f6ae48eaf7957529f1ac50c152 100644 (file)
@@ -423,6 +423,7 @@ int rc_display_message_numbers;
 int rc_force_mail_prompts;
 int rc_remember_passwords;
 int rc_ansi_color;
 int rc_force_mail_prompts;
 int rc_remember_passwords;
 int rc_ansi_color;
+int rc_sixel;
 int rc_color_use_bg;
 int rc_prompt_control = 0;
 time_t rc_idle_threshold = (time_t) 900;
 int rc_color_use_bg;
 int rc_prompt_control = 0;
 time_t rc_idle_threshold = (time_t) 900;
@@ -889,6 +890,7 @@ void load_command_set(void) {
        rc_display_message_numbers = 0;
        rc_force_mail_prompts = 0;
        rc_ansi_color = 0;
        rc_display_message_numbers = 0;
        rc_force_mail_prompts = 0;
        rc_ansi_color = 0;
+       rc_sixel = 0;
        rc_color_use_bg = 0;
        strcpy(rc_url_cmd, "");
        strcpy(rc_open_cmd, "");
        rc_color_use_bg = 0;
        strcpy(rc_url_cmd, "");
        strcpy(rc_open_cmd, "");
@@ -997,6 +999,10 @@ void load_command_set(void) {
                        if (!strncasecmp(&buf[12], "on", 2))
                                enable_status_line = 1;
                }
                        if (!strncasecmp(&buf[12], "on", 2))
                                enable_status_line = 1;
                }
+               if (!strncasecmp(buf, "use_sixel=", 10)) {
+                       if (!strncasecmp(&buf[10], "on", 2))
+                               rc_sixel = 1;
+               }
                if (!strncasecmp(buf, "use_background=", 15)) {
                        if (!strncasecmp(&buf[15], "on", 2))
                                rc_color_use_bg = 9;
                if (!strncasecmp(buf, "use_background=", 15)) {
                        if (!strncasecmp(&buf[15], "on", 2))
                                rc_color_use_bg = 9;
index 54779db0e75bf9785164c8ceeafaab4ff24187c4..183ed0f93db0b4caa0980c7757f1f08abb9c91e9 100644 (file)
@@ -53,6 +53,7 @@ extern char printcmd[];
 extern int rc_allow_attachments;
 extern int rc_display_message_numbers;
 extern int rc_force_mail_prompts;
 extern int rc_allow_attachments;
 extern int rc_display_message_numbers;
 extern int rc_force_mail_prompts;
+extern int rc_sixel;
 extern int editor_pid;
 extern CtdlIPC *ipc_for_signal_handlers;       // KLUDGE cover your eyes
 int num_urls = 0;
 extern int editor_pid;
 extern CtdlIPC *ipc_for_signal_handlers;       // KLUDGE cover your eyes
 int num_urls = 0;
@@ -587,7 +588,9 @@ int read_message(CtdlIPC *ipc,
 
        // Convert HTML to plain text, formatting for the actual width of the client screen.
        if (!strcasecmp(message->content_type, "text/html")) {
 
        // Convert HTML to plain text, formatting for the actual width of the client screen.
        if (!strcasecmp(message->content_type, "text/html")) {
-               converted_text = html_to_ascii(message->text, 0, screenwidth, (enable_color ? H2A_ANSI : 0));
+               converted_text = html_to_ascii(message->text, 0, screenwidth,
+                       ((enable_color ? H2A_ANSI : 0) | (rc_sixel ? H2A_SIXEL : 0))
+               );
                if (converted_text != NULL) {
                        free(message->text);
                        message->text = converted_text;
                if (converted_text != NULL) {
                        free(message->text);
                        message->text = converted_text;