aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_marshal_input.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-19 23:06:02 +0100
committerMattias Andrée <m@maandree.se>2025-02-19 23:06:02 +0100
commit24ebd3c309c5d6cad63bbf1b40de8c17aead0366 (patch)
tree7deab3ddadf241ccfaefc31e65916b6036689285 /libterminput_marshal_input.c
parentAdd tests for new escape sequences (diff)
downloadlibterminput-24ebd3c309c5d6cad63bbf1b40de8c17aead0366.tar.gz
libterminput-24ebd3c309c5d6cad63bbf1b40de8c17aead0366.tar.bz2
libterminput-24ebd3c309c5d6cad63bbf1b40de8c17aead0366.tar.xz
Add state marshalling and unmarshalling functions
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r--libterminput_marshal_input.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libterminput_marshal_input.c b/libterminput_marshal_input.c
new file mode 100644
index 0000000..9949838
--- /dev/null
+++ b/libterminput_marshal_input.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libterminput_marshal_input(struct libterminput_marshaller *how, const union libterminput_input *what) /* TODO test */
+{
+ enum libterminput_type type = what->type;
+ if (how->store(how, &type, sizeof(type)))
+ return -1;
+ if (type == LIBTERMINPUT_NONE) {
+ if (what->keypress.key == LIBTERMINPUT_SYMBOL)
+ type = LIBTERMINPUT_KEYPRESS;
+ if (how->store(how, &type, sizeof(type)))
+ return -1;
+ }
+ if (type == LIBTERMINPUT_KEYPRESS)
+ return libterminput_marshal_keypress__(how, &what->keypress);
+ else if (type == LIBTERMINPUT_TEXT)
+ return libterminput_marshal_text__(how, &what->text);
+ else if (type == LIBTERMINPUT_MOUSEEVENT)
+ return libterminput_marshal_mouseevent__(how, &what->mouseevent);
+ else if (type == LIBTERMINPUT_CURSOR_POSITION)
+ return libterminput_marshal_position__(how, &what->position);
+ else
+ return 0;
+}