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
1 parent
58f7e27
commit ef1ef10
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
modules/scala/jupyter-api/src/main/scala/almond/input/Input.scala
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 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) | ||
} |
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