Skip to content

Commit

Permalink
Partly revert 84d4854 (#923)
Browse files Browse the repository at this point in the history
This partly reverts some changes of 84d4854, by saving / restoring tty
stuff right before and after reading input. This basically runs
processes right before and after reading input, which incurs a perf cost
- just like before 84d4854.

One can see it by starting an Ammonite session, waiting for it to be
fully started, then repeatedly entering Enter. There's a small delay
between each prompt. 84d4854 addressed that, but breaking a few stuff
along the way (#920, #922).
  • Loading branch information
alexarchambault committed Jan 25, 2019
1 parent 1f14d3e commit 5ad9ae5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
19 changes: 3 additions & 16 deletions amm/repl/src/main/scala/ammonite/repl/Repl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,7 @@ class Repl(input: InputStream,


def run(): Any = {

val initialConfigOpt =
if (scala.util.Properties.isWin)
None
else
Some(ammonite.terminal.TTY.init())

welcomeBanner.foreach(printer.outStream.println)
@tailrec def loop(): Any = {
val actionResult = action()
remoteLogger.foreach(_.apply("Action"))
Expand All @@ -208,15 +202,8 @@ class Repl(input: InputStream,
case Some(value) => value
}
}

try {
welcomeBanner.foreach(printer.outStream.println)
loop()
} finally {
for (config <- initialConfigOpt)
ammonite.terminal.TTY.stty(config)
}
}
loop()
}

def beforeExit(exitValue: Any): Any = {
Function.chain(interp.beforeExitHooks)(exitValue)
Expand Down
13 changes: 13 additions & 0 deletions terminal/src/main/scala/ammonite/terminal/Terminal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@ object Terminal {
filters: Filter,
displayTransform: (Vector[Char], Int) => (fansi.Str, Int) = LineReader.noTransform)
: Option[String] = {


val initialConfig = TTY.init()
try {
new LineReader(ConsoleDim.width(), prompt, reader, writer, filters, displayTransform)
.readChar(TermState(LazyList.continually(reader.read()), Vector.empty, 0, ""), 0)
}finally{

// Don't close these! Closing these closes stdin/stdout,
// which seems to kill the entire program

// reader.close()
// writer.close()
TTY.stty(initialConfig)
}
}
}

0 comments on commit 5ad9ae5

Please sign in to comment.