Add term-init, term-exit builtins

This commit is contained in:
Lassi Kortela 2019-08-26 16:52:42 +03:00
parent 16d409c382
commit 83e64da945
3 changed files with 40 additions and 0 deletions

View File

@ -7,6 +7,9 @@ value_t builtin_user_effective_uid(value_t *args, uint32_t nargs);
value_t builtin_user_real_gid(value_t *args, uint32_t nargs);
value_t builtin_user_real_uid(value_t *args, uint32_t nargs);
value_t builtin_term_init(value_t *args, uint32_t nargs);
value_t builtin_term_exit(value_t *args, uint32_t nargs);
value_t builtin_spawn(value_t *args, uint32_t nargs);
value_t builtin_read_ini_file(value_t *args, uint32_t nargs);

View File

@ -98,6 +98,9 @@ static struct builtin_procedure builtin_procedures[] = {
{ "user-real-gid", builtin_user_real_gid, SRFI_170 | UP_2019 },
{ "user-real-uid", builtin_user_real_uid, SRFI_170 | UP_2019 },
{ "term-init", builtin_term_init, UP_2019 },
{ "term-exit", builtin_term_exit, UP_2019 },
{ "spawn", builtin_spawn, SRFI_170 | UP_2019 },
{ "color-name->rgb24", builtin_color_name_to_rgb24, UP_2019 },

View File

@ -13,6 +13,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "dtypes.h"
@ -126,3 +127,36 @@ void os_setenv(const char *name, const char *value)
}
}
}
// TODO: cleanup
static struct termios term_mode_orig;
static struct termios term_mode_raw;
static void term_mode_init(void)
{
static int done;
if (!done) {
done = 1;
tcgetattr(0, &term_mode_orig);
cfmakeraw(&term_mode_raw);
}
}
value_t builtin_term_init(value_t *args, uint32_t nargs)
{
(void)args;
argcount("term-init", nargs, 0);
term_mode_init();
tcsetattr(0, TCSAFLUSH, &term_mode_raw);
return FL_T;
}
value_t builtin_term_exit(value_t *args, uint32_t nargs)
{
(void)args;
argcount("term-exit", nargs, 0);
term_mode_init();
tcsetattr(0, TCSAFLUSH, &term_mode_orig);
return FL_T;
}