make repl tty sensitive

This commit is contained in:
Sunrim KIM (keen) 2014-09-30 21:21:59 +09:00
parent b7fca32f61
commit 2e0fab5a26
3 changed files with 28 additions and 1 deletions

View File

@ -1 +1,3 @@
list(APPEND PICLIB_CONTRIB_LIBS ${PROJECT_SOURCE_DIR}/contrib/20.repl/repl.scm)
list(APPEND PICRIN_CONTRIB_SOURCES ${PROJECT_SOURCE_DIR}/contrib/20.repl/repl.c)
list(APPEND PICRIN_CONTRIB_INITS repl)

25
contrib/20.repl/repl.c Normal file
View File

@ -0,0 +1,25 @@
#include "picrin.h"
#include "picrin/data.h"
#include "picrin/pair.h"
#include "picrin/string.h"
#include "picrin/cont.h"
#include <unistd.h>
static pic_value
pic_repl_tty_p(pic_state *pic)
{
pic_get_args(pic, "");
return pic_bool_value((isatty(STDIN_FILENO)));
}
void
pic_init_repl(pic_state *pic)
{
pic_deflibrary (pic, "(picrin repl)") {
pic_defun(pic, "tty?", pic_repl_tty_p);
}
}

View File

@ -11,7 +11,7 @@
(else
(begin
(define (readline str)
(display str)
(if (tty?) (display str))
(read-line))
(define (add-history str)
#f))))