-
Notifications
You must be signed in to change notification settings - Fork 17
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
e0b747a
commit c0eaa85
Showing
2 changed files
with
22 additions
and
18 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 |
---|---|---|
@@ -1,36 +1,39 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from uuid import uuid4 | ||
|
||
from pycrdt import Map, Text | ||
|
||
|
||
def add_stdin(cell: Map, prompt: str = "", password: bool = False) -> None: | ||
def add_stdin(cell: Map, prompt: str = "", password: bool = False) -> str: | ||
""" | ||
Adds an stdin Map in the cell outputs. | ||
Adds an stdin Map in the cell outputs, and returns its ID. | ||
Schema: | ||
.. code-block:: json | ||
{ | ||
"state": Map[ | ||
"pending": bool, | ||
"password": bool | ||
], | ||
"output_type": "stdin", | ||
"id": str, | ||
"submitted": bool, | ||
"password": bool | ||
"prompt": str, | ||
"input": Text | ||
} | ||
""" | ||
idx = uuid4().hex | ||
stdin = Map( | ||
{ | ||
"output_type": "stdin", | ||
"state": { | ||
"pending": True, | ||
"password": password, | ||
}, | ||
"id": idx, | ||
"submitted": False, | ||
"password": password, | ||
"prompt": prompt, | ||
"input": Text(), | ||
} | ||
) | ||
outputs = cell.get("outputs") | ||
outputs.append(stdin) | ||
return idx |
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