Skip to content

Commit

Permalink
Add high level API for input
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Apr 12, 2019
1 parent 58f7e27 commit ef1ef10
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/scala/jupyter-api/src/main/scala/almond/input/Input.scala
@@ -0,0 +1,38 @@
package almond.input

import almond.api.JupyterApi

final class Input private (
val prompt: String,
val password: Boolean
) {

private def copy(
prompt: String = prompt,
password: Boolean = password
): Input =
new Input(prompt, password)

def withPrompt(prompt: String): Input =
copy(prompt = prompt)
def withPassword(password: Boolean): Input =
copy(password = password)
def withPassword(): Input =
copy(password = true)

// TODO Also allow to return result via a future?
def request()(implicit api: JupyterApi): String =
api.stdin(prompt, password)

}

object Input {
def apply(): Input =
new Input("", password = false)
def apply(prompt: String): Input =
new Input(prompt, password = false)
def password(): Input =
new Input("", password = true)
def password(prompt: String): Input =
new Input(prompt, password = true)
}
Expand Up @@ -22,6 +22,7 @@ object AmmInterpreter {
|import almond.interpreter.api.DisplayData.DisplayDataSyntax
|import almond.display._
|import almond.display.Display.{markdown, html, latex, text, js, svg}
|import almond.input._
""".stripMargin

private[almond] val isAtLeast_2_12_7 = {
Expand Down

0 comments on commit ef1ef10

Please sign in to comment.