aboutsummaryrefslogtreecommitdiff
path: root/vterm-module.c
diff options
context:
space:
mode:
Diffstat (limited to 'vterm-module.c')
-rw-r--r--vterm-module.c108
1 files changed, 1 insertions, 107 deletions
diff --git a/vterm-module.c b/vterm-module.c
index d320f41..1b7e2de 100644
--- a/vterm-module.c
+++ b/vterm-module.c
@@ -1,4 +1,5 @@
#include "vterm-module.h"
+#include "elisp.h"
#include <fcntl.h>
#ifdef __APPLE__
#include <util.h>
@@ -8,7 +9,6 @@
#include "utf8.h"
#include <pthread.h>
#include <signal.h>
-#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/select.h>
@@ -20,112 +20,6 @@
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
-/* Bind NAME to FUN. */
-static void bind_function(emacs_env *env, const char *name, emacs_value Sfun) {
- /* Set the function cell of the symbol named NAME to SFUN using
- the 'fset' function. */
-
- /* Convert the strings to symbols by interning them */
- emacs_value Qfset = env->intern(env, "fset");
- emacs_value Qsym = env->intern(env, name);
-
- /* Prepare the arguments array */
- emacs_value args[] = {Qsym, Sfun};
-
- /* Make the call (2 == nb of arguments) */
- env->funcall(env, Qfset, 2, args);
-}
-
-/* Provide FEATURE to Emacs. */
-static void provide(emacs_env *env, const char *feature) {
- /* call 'provide' with FEATURE converted to a symbol */
-
- emacs_value Qfeat = env->intern(env, feature);
- emacs_value Qprovide = env->intern(env, "provide");
- emacs_value args[] = {Qfeat};
-
- env->funcall(env, Qprovide, 1, args);
-}
-
-static int string_bytes(emacs_env *env, emacs_value string) {
- ptrdiff_t size = 0;
- env->copy_string_contents(env, string, NULL, &size);
- return size;
-}
-
-static emacs_value string_length(emacs_env *env, emacs_value string) {
- return env->funcall(env, Flength, 1, (emacs_value[]){string});
-}
-
-static emacs_value list(emacs_env *env, emacs_value *elements, ptrdiff_t len) {
- return env->funcall(env, Flist, len, elements);
-}
-
-static void put_text_property(emacs_env *env, emacs_value string,
- emacs_value property, emacs_value value) {
- emacs_value start = env->make_integer(env, 0);
- emacs_value end = string_length(env, string);
-
- env->funcall(env, Fput_text_property, 5,
- (emacs_value[]){start, end, property, value, string});
-}
-
-/*
- * Color must be a string #RGB
- */
-static emacs_value render_text(emacs_env *env, char *buffer, int len,
- VTermScreenCell *cell) {
- emacs_value text = env->make_string(env, buffer, len);
-
- emacs_value foreground = color_to_rgb_string(env, cell->fg);
- emacs_value background = color_to_rgb_string(env, cell->bg);
- emacs_value bold = cell->attrs.bold ? Qbold : Qnormal;
- emacs_value underline = cell->attrs.underline ? Qt : Qnil;
- emacs_value italic = cell->attrs.italic ? Qitalic : Qnormal;
- emacs_value reverse = cell->attrs.reverse ? Qt : Qnil;
- emacs_value strike = cell->attrs.strike ? Qt : Qnil;
-
- // TODO: Blink, font, dwl, dhl is missing
- emacs_value properties =
- list(env,
- (emacs_value[]){Qforeground, foreground, Qbackground, background,
- Qweight, bold, Qunderline, underline, Qslant, italic,
- Qreverse, reverse, Qstrike, strike},
- 14);
-
- put_text_property(env, text, Qface, properties);
-
- return text;
-}
-
-static void byte_to_hex(uint8_t byte, char *hex) {
- snprintf(hex, 3, "%.2X", byte);
-}
-
-static emacs_value color_to_rgb_string(emacs_env *env, VTermColor color) {
- char buffer[8];
- buffer[0] = '#';
- buffer[7] = '\0';
- byte_to_hex(color.red, buffer + 1);
- byte_to_hex(color.green, buffer + 3);
- byte_to_hex(color.blue, buffer + 5);
-
- return env->make_string(env, buffer, 7);
-};
-
-static void erase_buffer(emacs_env *env) {
- env->funcall(env, Ferase_buffer, 0, NULL);
-}
-
-static void insert(emacs_env *env, emacs_value string) {
- env->funcall(env, Finsert, 1, (emacs_value[]){string});
-}
-
-static void goto_char(emacs_env *env, int pos) {
- emacs_value point = env->make_integer(env, pos);
- env->funcall(env, Fgoto_char, 1, (emacs_value[]){point});
-}
-
static void vterm_put_caret(VTerm *vt, emacs_env *env, int row, int col,
int offset) {
int rows, cols;