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 4
4
import sys
5
5
6
6
from ._version import __version__ as __version__
7
+ from .ystdin import add_stdin as add_stdin
7
8
from .yblob import YBlob as YBlob
8
9
from .yfile import YFile as YFile
9
10
from .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 1
1
# Copyright (c) Jupyter Development Team.
2
2
# Distributed under the terms of the Modified BSD License.
3
3
4
- from jupyter_ydoc import YBlob
4
+ from jupyter_ydoc import YBlob , YNotebook , add_stdin
5
5
6
6
7
7
def test_yblob ():
@@ -22,3 +22,32 @@ def callback(topic, event):
22
22
assert topic == "source"
23
23
assert event .keys ["bytes" ]["oldValue" ] == b"012"
24
24
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