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 1/2] 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)))) From 086495706163a8db90d8511741212727c6c3030f Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 30 Sep 2014 21:23:22 +0900 Subject: [PATCH 2/2] cosmetic change --- contrib/20.repl/CMakeLists.txt | 2 +- contrib/20.repl/repl.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/20.repl/CMakeLists.txt b/contrib/20.repl/CMakeLists.txt index 91bec1b8..7fc3bf06 100644 --- a/contrib/20.repl/CMakeLists.txt +++ b/contrib/20.repl/CMakeLists.txt @@ -1,3 +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 +list(APPEND PICRIN_CONTRIB_INITS repl) diff --git a/contrib/20.repl/repl.c b/contrib/20.repl/repl.c index bdc54e65..1398a202 100644 --- a/contrib/20.repl/repl.c +++ b/contrib/20.repl/repl.c @@ -1,8 +1,4 @@ #include "picrin.h" -#include "picrin/data.h" -#include "picrin/pair.h" -#include "picrin/string.h" -#include "picrin/cont.h" #include