From 2e0fab5a26de47e30d4994e64c021e6c1257b87d Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 30 Sep 2014 21:21:59 +0900 Subject: [PATCH] make repl tty sensitive --- contrib/20.repl/CMakeLists.txt | 2 ++ contrib/20.repl/repl.c | 25 +++++++++++++++++++++++++ contrib/20.repl/repl.scm | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 contrib/20.repl/repl.c diff --git a/contrib/20.repl/CMakeLists.txt b/contrib/20.repl/CMakeLists.txt index c0a24065..91bec1b8 100644 --- a/contrib/20.repl/CMakeLists.txt +++ b/contrib/20.repl/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/contrib/20.repl/repl.c b/contrib/20.repl/repl.c new file mode 100644 index 00000000..bdc54e65 --- /dev/null +++ b/contrib/20.repl/repl.c @@ -0,0 +1,25 @@ +#include "picrin.h" +#include "picrin/data.h" +#include "picrin/pair.h" +#include "picrin/string.h" +#include "picrin/cont.h" + +#include + + +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); + } +} diff --git a/contrib/20.repl/repl.scm b/contrib/20.repl/repl.scm index 2b9d4812..bed94d0e 100644 --- a/contrib/20.repl/repl.scm +++ b/contrib/20.repl/repl.scm @@ -11,7 +11,7 @@ (else (begin (define (readline str) - (display str) + (if (tty?) (display str)) (read-line)) (define (add-history str) #f))))