Skip to content
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

Add consoleOut and consoleErr in JupyterApi #1169

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package almond.api
import almond.interpreter.api.{CommHandler, DisplayData, OutputHandler}
import jupyter.{Displayer, Displayers}

import java.io.PrintStream
import java.util.concurrent.atomic.AtomicInteger
import java.util.{Locale, UUID}

Expand Down Expand Up @@ -55,6 +56,9 @@ abstract class JupyterApi { api =>

def addExecuteHook(hook: JupyterApi.ExecuteHook): Boolean
def removeExecuteHook(hook: JupyterApi.ExecuteHook): Boolean

def consoleOut: PrintStream
def consoleErr: PrintStream
}

object JupyterApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ final class Execute(
resultStream,
s => currentPublishOpt0.fold(Console.err.println(s))(_.stderr(s)),
s => currentPublishOpt0.fold(Console.err.println(s))(_.stderr(s)),
s => currentPublishOpt0.fold(println(s))(_.stdout(s))
// to stdout in notebooks, not to get a red background,
// but stderr in the console, not to pollute stdout
s => currentPublishOpt0.fold(Console.err.println(s))(_.stdout(s))
)

def history: History =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package almond

import java.io.ByteArrayOutputStream
import java.io.{ByteArrayOutputStream, PrintStream}
import java.nio.charset.StandardCharsets

import almond.api.{FullJupyterApi, JupyterApi}
Expand All @@ -21,7 +21,9 @@ final class JupyterApiImpl(
replApi: ReplApiImpl,
silent0: Ref[Boolean],
protected val allowVariableInspector: Option[Boolean],
val kernelClassLoader: ClassLoader
val kernelClassLoader: ClassLoader,
val consoleOut: PrintStream,
val consoleErr: PrintStream
) extends FullJupyterApi with VariableInspectorApiImpl {

protected def variableInspectorImplPPrinter() = replApi.pprinter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ final class ScalaInterpreter(
replApi,
silent0,
params.allowVariableInspector,
kernelClassLoader = Thread.currentThread().getContextClassLoader
kernelClassLoader = Thread.currentThread().getContextClassLoader,
consoleOut = System.out,
consoleErr = System.err
)

if (params.toreeMagics) {
Expand Down