diff --git a/c/builtins.h b/c/builtins.h index 904ce65..a22fe93 100644 --- a/c/builtins.h +++ b/c/builtins.h @@ -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); diff --git a/c/libraries.c b/c/libraries.c index bbd31fa..4e17855 100644 --- a/c/libraries.c +++ b/c/libraries.c @@ -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 }, diff --git a/c/os_unix.c b/c/os_unix.c index 90aeffa..5fd3c57 100644 --- a/c/os_unix.c +++ b/c/os_unix.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #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; +}