aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/repl/InteractiveReader.scala
blob: 6ec6a046388283548081759784e50fa7297b27d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package dotty.tools
package dotc
package repl

import dotc.core.Contexts.Context

/** Reads lines from an input stream */
trait InteractiveReader {
  def readLine(prompt: String): String
  val interactive: Boolean
}

/** The current Scala REPL know how to do this flexibly.
 */
object InteractiveReader {
  /** Create an interactive reader.  Uses JLine if the
   *  library is available, but otherwise uses a
   *  SimpleReader. */
  def createDefault(in: Interpreter)(implicit ctx: Context): InteractiveReader = {
    try {
      new AmmoniteReader(in)
    } catch { case e =>
      //out.println("jline is not available: " + e) //debug
      e.printStackTrace()
      println("Could not use ammonite, falling back to simple reader")
      new SimpleReader()
    }
  }
}