#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;
}
+// 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.
//
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;
}
}
}
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
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 */
#
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"
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;
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, "");
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;
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;
// 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;