File tree Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 44import sys
55
66from ._version import __version__ as __version__
7+ from .ystdin import add_stdin as add_stdin
78from .yblob import YBlob as YBlob
89from .yfile import YFile as YFile
910from .ynotebook import YNotebook as YNotebook
Original file line number Diff line number Diff line change 1+ from pycrdt import Map , Text
2+
3+
4+ def add_stdin (cell : Map , prompt : str = "" , password : bool = False ) -> None :
5+ """
6+ Adds an stdin Map in the cell outputs.
7+
8+ Schema:
9+
10+ .. code-block:: json
11+
12+ {
13+ "state": Map[
14+ "pending": bool,
15+ "password": bool
16+ ],
17+ "prompt": str,
18+ "input": Text
19+ }
20+ """
21+ stdin = Map ({
22+ "output_type" : "stdin" ,
23+ "state" : {
24+ "pending" : True ,
25+ "password" : password ,
26+ },
27+ "prompt" : prompt ,
28+ "input" : Text (),
29+ })
30+ outputs = cell .get ("outputs" )
31+ outputs .append (stdin )
Original file line number Diff line number Diff line change 11# Copyright (c) Jupyter Development Team.
22# Distributed under the terms of the Modified BSD License.
33
4- from jupyter_ydoc import YBlob
4+ from jupyter_ydoc import YBlob , YNotebook , add_stdin
55
66
77def test_yblob ():
@@ -22,3 +22,32 @@ def callback(topic, event):
2222 assert topic == "source"
2323 assert event .keys ["bytes" ]["oldValue" ] == b"012"
2424 assert event .keys ["bytes" ]["newValue" ] == b"345"
25+
26+
27+ def test_stdin ():
28+ ynotebook = YNotebook ()
29+ ynotebook .append_cell ({
30+ "cell_type" : "code" ,
31+ "source" : "" ,
32+ })
33+ ycell = ynotebook .ycells [0 ]
34+ add_stdin (ycell )
35+ cell = ycell .to_py ()
36+ # cell ID is random, ignore that
37+ del cell ["id" ]
38+ assert cell == {
39+ "outputs" : [
40+ {
41+ "output_type" : "stdin" ,
42+ "input" : "" ,
43+ "prompt" : "" ,
44+ "state" : {
45+ "password" : False ,
46+ "pending" : True ,
47+ }
48+ }
49+ ],
50+ "source" : "" ,
51+ "metadata" : {},
52+ "cell_type" : "code" ,
53+ }
You can’t perform that action at this time.
0 commit comments