Skip to content

Add org.jline as module to component directory #8496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions engine/runner/src/main/scala/org/enso/runner/Repl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ case class SimpleReplIO(in: InputStream, out: OutputStream) extends ReplIO {
/** An implementation of [[ReplIO]] using system terminal capabilities.
*/
case class TerminalIO(historyFilePath: Path) extends ReplIO {
// jline uses the class loader from `Thread.currentThread().getContextClassLoader()` to
// load services. We need to override the context class loader to be `IsolatedClassLoader`
// from the runner.jar class loader.
private val prevClassLoader = Thread.currentThread().getContextClassLoader
Thread
.currentThread()
.setContextClassLoader(classOf[TerminalIO].getClassLoader)
private val terminal: Terminal =
TerminalBuilder.builder().system(true).build()
private val parser: DefaultParser = new DefaultParser()
Expand All @@ -109,6 +116,7 @@ case class TerminalIO(historyFilePath: Path) extends ReplIO {
.history(history)
.terminal(terminal)
.build()
Thread.currentThread().setContextClassLoader(prevClassLoader)

Runtime.getRuntime.addShutdownHook(new Thread() {
override def run(): Unit = {
Expand Down