diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-08-04 07:30:35 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-08-04 07:30:35 -0700 |
commit | 44e706df30069b463dc574a6ed39146a8d71634d (patch) | |
tree | 2669e868ad18430aecfb592d77dc8aea2199868d /src/library | |
parent | 12b04bb1fb8146097b01497ad0760f8a3a13eb5b (diff) | |
parent | f16e2c0874b4ecd4d5f0609f7a1c6a429d11c187 (diff) | |
download | scala-44e706df30069b463dc574a6ed39146a8d71634d.tar.gz scala-44e706df30069b463dc574a6ed39146a8d71634d.tar.bz2 scala-44e706df30069b463dc574a6ed39146a8d71634d.zip |
Merge pull request #1028 from odersky/topic/worksheet
Made worksheet output wrap around after custimizable # of output columns
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/runtime/WorksheetSupport.scala | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/library/scala/runtime/WorksheetSupport.scala b/src/library/scala/runtime/WorksheetSupport.scala index db6d6359a3..6f2a4d382d 100644 --- a/src/library/scala/runtime/WorksheetSupport.scala +++ b/src/library/scala/runtime/WorksheetSupport.scala @@ -14,9 +14,11 @@ object WorksheetSupport { * By default it is 30ms. */ private class FlushedOutputStream(out: OutputStream) extends OutputStream { + protected def flushInterval = 30000000L // interval between flushes, by default 30ms + protected def width = 80 // output width, by default 80 characters + protected def tabInc = 8 // tab increment, by default 8 characters private var lastFlush: Long = 0L - protected val flushInterval = 30000000L // 30ms - private var lastCh: Int = '\n' + private var col = -1 override def write(b: Array[Byte], off: Int, len: Int) = { for (idx <- off until (off + len min b.length)) writeOne(b(idx)) flush() @@ -33,14 +35,18 @@ object WorksheetSupport { } } def writeOne(c: Int) { - if (lastCh == '\n') { - lastCh = 0 + if (col < 0) { + col = 0 write((currentOffset+" ").getBytes) } out.write(c) - lastCh = c + col = + if (c == '\n') -1 + else if (c == '\t') (col / tabInc) * tabInc + tabInc + else col + 1 + if (col >= width) writeOne('\n') } - def ensureNewLine() = if (lastCh != '\n') writeOne('\n') + def ensureNewLine() = if (col > 0) writeOne('\n') } private val flushedOut = new FlushedOutputStream(System.out) @@ -69,7 +75,7 @@ object WorksheetSupport { try op catch { case ex: StopException => ; - case ex => ex.printStackTrace() + case ex: Throwable => ex.printStackTrace() } } |