-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package chester.io | ||
|
||
import chester.repl.{ReadLineResult, TerminalInfo, TerminalInit} | ||
import typings.std.global.setTimeout | ||
import typings.xtermXterm.mod as xterm | ||
import typings.xtermReadline.mod.Readline | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.{Future, Promise} | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSExportTopLevel | ||
import scala.scalajs.js.Thenable.Implicits.* | ||
import scala.scalajs.js.JSConverters.* | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
|
||
def setTimeoutThen: Future[Unit] = { | ||
val promise = Promise[Unit]() | ||
setTimeout(() => promise.success(()), 0) | ||
promise.future | ||
} | ||
|
||
final class InXtermReadline(rl: Readline) extends InTerminalNoHistory[Future] { | ||
inline override def writeln(line: fansi.Str): Future[Unit] = { | ||
rl.println(line.render) | ||
setTimeoutThen | ||
} | ||
|
||
override inline def readALine(prompt: fansi.Str): Future[String] = { | ||
rl.read(prompt.render) | ||
} | ||
} | ||
|
||
case class XtermReadline(rl: Readline) extends Terminal[Future] { | ||
def runTerminal[T](init: TerminalInit, block: InTerminal[Future] ?=> Future[T]): Future[T] = { | ||
block(using InXtermReadline(rl)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters