aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscgilardi <scgilardi@gmail.com>2008-12-30 18:10:50 +0000
committerscgilardi <scgilardi@gmail.com>2008-12-30 18:10:50 +0000
commit0beff6c7c6c8ac3fe1794aae6d8961908a37ec7a (patch)
treedf48cf409f1ea3e0882212b49792cba8ecf2e36b
parenta3565f1f25d44308081d182a8e9fda29de73330a (diff)
repl-ln: add stream-repl for convenient in, out, err stream overriding
-rw-r--r--src/clojure/contrib/repl_ln.clj18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/clojure/contrib/repl_ln.clj b/src/clojure/contrib/repl_ln.clj
index e70283c4..8041f515 100644
--- a/src/clojure/contrib/repl_ln.clj
+++ b/src/clojure/contrib/repl_ln.clj
@@ -15,6 +15,7 @@
(ns clojure.contrib.repl-ln
(:gen-class)
(:import (clojure.lang Compiler LineNumberingPushbackReader RT Var)
+ (java.io InputStreamReader OutputStreamWriter PrintWriter)
java.util.Date)
(:require clojure.main)
(:use [clojure.contrib.def
@@ -103,6 +104,23 @@
[args]
(set! *command-line-args* (process-inits args)))
+(defn stream-repl
+ "Repl entry point that provides convenient overriding of input, output,
+ and err streams via sequential keyword-value pairs. Default values
+ for :in, :out, and :err are streams associated with System/in,
+ System/out, and System/err using UTF-8 encoding. Also supports all the
+ options provided by clojure.contrib.repl-ln/repl."
+ [& options]
+ (let [enc RT/UTF8
+ {:keys [in out err]
+ :or {in (LineNumberingPushbackReader.
+ (InputStreamReader. System/in enc))
+ out (OutputStreamWriter. System/out enc)
+ err (PrintWriter. (OutputStreamWriter. System/err enc))}}
+ (apply hash-map options)]
+ (binding [*in* in *out* out *err* err]
+ (apply repl options))))
+
(defn- -main
"Main entry point, starts a repl enters the user namespace and processes
command line args."