aboutsummaryrefslogtreecommitdiff
path: root/dcs.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-21 20:53:23 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-21 20:53:23 +0000
commit9e3bfb1eab2c7b1c7a1ec6021331fddc57e8a266 (patch)
tree35d03f0099762cb82ca23e584d4bd4464d548332 /dcs.c
parentkeymap: tab: handle all modifiers (diff)
sixel: initial support
This implements basic parsing of sixel data. Lots of limitations and temporary solutions as this is still work-in-progress: * Maximum image size hardcoded to 800x800 * No HLS color format support * Image is always rendered at 0x0 in the terminal
Diffstat (limited to 'dcs.c')
-rw-r--r--dcs.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/dcs.c b/dcs.c
index 048cd62e..f9e3c10c 100644
--- a/dcs.c
+++ b/dcs.c
@@ -3,6 +3,7 @@
#define LOG_MODULE "dcs"
#define LOG_ENABLE_DBG 0
#include "log.h"
+#include "sixel.h"
#include "vt.h"
static void
@@ -35,9 +36,20 @@ dcs_hook(struct terminal *term, uint8_t final)
assert(term->vt.dcs.data == NULL);
assert(term->vt.dcs.size == 0);
+ assert(term->vt.dcs.put_handler == NULL);
assert(term->vt.dcs.unhook_handler == NULL);
switch (term->vt.private[0]) {
+ case 0:
+ switch (final) {
+ case 'q':
+ sixel_init(term);
+ term->vt.dcs.put_handler = &sixel_put;
+ term->vt.dcs.unhook_handler = &sixel_unhook;
+ break;
+ }
+ break;
+
case '=':
switch (final) {
case 's':
@@ -75,9 +87,13 @@ void
dcs_put(struct terminal *term, uint8_t c)
{
LOG_DBG("PUT: %c", c);
- if (!ensure_size(term, term->vt.dcs.idx + 1))
- return;
- term->vt.dcs.data[term->vt.dcs.idx++] = c;
+ if (term->vt.dcs.put_handler != NULL)
+ term->vt.dcs.put_handler(term, c);
+ else {
+ if (!ensure_size(term, term->vt.dcs.idx + 1))
+ return;
+ term->vt.dcs.data[term->vt.dcs.idx++] = c;
+ }
}
void
@@ -87,6 +103,7 @@ dcs_unhook(struct terminal *term)
term->vt.dcs.unhook_handler(term);
term->vt.dcs.unhook_handler = NULL;
+ term->vt.dcs.put_handler = NULL;
free(term->vt.dcs.data);
term->vt.dcs.data = NULL;