diff options
author | Philipp Haller <hallerp@gmail.com> | 2009-08-24 16:42:58 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2009-08-24 16:42:58 +0000 |
commit | 241dc55e6cab2b6b201aedc5a063827e489c3bd5 (patch) | |
tree | 0d8137274c6521faaf17ad15fef1afb512bd2453 /src/library | |
parent | 7f757333f92181ee0b25b1f762450526d64a7dad (diff) | |
download | scala-241dc55e6cab2b6b201aedc5a063827e489c3bd5.tar.gz scala-241dc55e6cab2b6b201aedc5a063827e489c3bd5.tar.bz2 scala-241dc55e6cab2b6b201aedc5a063827e489c3bd5.zip |
Added Console.setErr and Console.withErr methods.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Console.scala | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/library/scala/Console.scala b/src/library/scala/Console.scala index bbef8aa3ce..933986a2ba 100644 --- a/src/library/scala/Console.scala +++ b/src/library/scala/Console.scala @@ -58,14 +58,14 @@ object Console { final val INVISIBLE = "\033[8m" private val outVar = new DynamicVariable[PrintStream](java.lang.System.out) + private val errVar = new DynamicVariable[PrintStream](java.lang.System.err) private val inVar = new DynamicVariable[BufferedReader]( new BufferedReader(new InputStreamReader(java.lang.System.in))) def out = outVar.value + def err = errVar.value def in = inVar.value - val err = java.lang.System.err - /** Set the default output stream. * * @param out the new output stream. @@ -102,6 +102,42 @@ object Console { withOut(new PrintStream(out))(thunk) + /** Set the default error stream. + * + * @param err the new error stream. + */ + def setErr(err: PrintStream) { errVar.value = err } + + /** Set the default error stream for the duration + * of execution of one thunk. + * + * @param err the new error stream. + * @param thunk the code to execute with + * the new error stream active + * @return ... + */ + def withErr[T](err: PrintStream)(thunk: =>T): T = + errVar.withValue(err)(thunk) + + /** Set the default error stream. + * + * @param err the new error stream. + */ + def setErr(err: OutputStream): Unit = + setErr(new PrintStream(err)) + + /** Set the default error stream for the duration + * of execution of one thunk. + * + * @param err the new error stream. + * @param thunk the code to execute with + * the new error stream active + * @return ... + */ + def withErr[T](err: OutputStream)(thunk: =>T): T = + withErr(new PrintStream(err))(thunk) + + /** Set the default input stream. * * @param reader specifies the new input stream. @@ -117,8 +153,8 @@ object Console { * @param thunk the code to execute with * the new input stream active */ - def withIn[T](reader: Reader)(thunk: =>T): T = - inVar.withValue(new BufferedReader(reader))(thunk) + def withIn[T](reader: Reader)(thunk: =>T): T = + inVar.withValue(new BufferedReader(reader))(thunk) /** Set the default input stream. |