22
33import sys
44
5- from ..hooks .use_stdin import _StdinHandle
5+ from ..hooks .use_stdin import (
6+ _StdinHandle ,
7+ create_default_stdin_context_value ,
8+ create_stdin_context_value ,
9+ create_stdin_runtime ,
10+ get_stdin_handle ,
11+ get_stdin_runtime ,
12+ )
613from ..packages .react_context import createContext
714
815PublicProps = dict
916Props = dict
1017
1118
12- def create_stdin_context_value (
19+ def create_stdin_handle (
1320 * ,
1421 stdin = sys .stdin ,
22+ output_stream = None ,
1523 is_raw_mode_supported : bool = False ,
1624 exit_on_ctrl_c : bool = True ,
1725 internal_event_emitter = None ,
1826 on_exit = None ,
1927):
20- return _StdinHandle (
28+ return get_stdin_handle (
29+ create_stdin_context_value (
30+ stream = stdin ,
31+ output_stream = output_stream ,
32+ is_raw_mode_supported = is_raw_mode_supported ,
33+ exit_on_ctrl_c = exit_on_ctrl_c ,
34+ internal_event_emitter = internal_event_emitter ,
35+ on_exit = on_exit ,
36+ )
37+ )
38+
39+
40+ def create_stdin_runtime_bridge (
41+ handle : _StdinHandle ,
42+ * ,
43+ exit_on_ctrl_c : bool = True ,
44+ on_exit = None ,
45+ ):
46+ return create_stdin_runtime (
47+ handle ,
48+ exit_on_ctrl_c = exit_on_ctrl_c ,
49+ on_exit = on_exit ,
50+ )
51+
52+
53+ def build_stdin_context_value (
54+ * ,
55+ handle : _StdinHandle | None = None ,
56+ runtime = None ,
57+ stdin = sys .stdin ,
58+ output_stream = None ,
59+ is_raw_mode_supported : bool = False ,
60+ exit_on_ctrl_c : bool = True ,
61+ internal_event_emitter = None ,
62+ on_exit = None ,
63+ ):
64+ if handle is not None :
65+ return create_stdin_context_value (
66+ handle = handle ,
67+ runtime = runtime
68+ or create_stdin_runtime_bridge (
69+ handle ,
70+ exit_on_ctrl_c = exit_on_ctrl_c ,
71+ on_exit = on_exit ,
72+ ),
73+ )
74+ return create_stdin_context_value (
2175 stream = stdin ,
76+ output_stream = output_stream ,
2277 is_raw_mode_supported = is_raw_mode_supported ,
2378 exit_on_ctrl_c = exit_on_ctrl_c ,
2479 internal_event_emitter = internal_event_emitter ,
2580 on_exit = on_exit ,
2681 )
2782
2883
29- StdinContext = createContext (create_stdin_context_value ())
84+ StdinContext = createContext (create_default_stdin_context_value ())
3085StdinContext .displayName = "InternalStdinContext"
3186
3287
3388def set_stdin_context_value (
3489 * ,
90+ handle : _StdinHandle | None = None ,
91+ runtime = None ,
3592 stdin = sys .stdin ,
93+ output_stream = None ,
3694 is_raw_mode_supported : bool = False ,
3795 exit_on_ctrl_c : bool = True ,
3896 internal_event_emitter = None ,
3997 on_exit = None ,
4098):
41- value = create_stdin_context_value (
99+ value = build_stdin_context_value (
100+ handle = handle ,
101+ runtime = runtime ,
42102 stdin = stdin ,
103+ output_stream = output_stream ,
43104 is_raw_mode_supported = is_raw_mode_supported ,
44105 exit_on_ctrl_c = exit_on_ctrl_c ,
45106 internal_event_emitter = internal_event_emitter ,
@@ -48,4 +109,10 @@ def set_stdin_context_value(
48109 StdinContext .current_value = value
49110 return value
50111
51- __all__ = ["StdinContext" ]
112+ __all__ = [
113+ "StdinContext" ,
114+ "build_stdin_context_value" ,
115+ "create_stdin_handle" ,
116+ "create_stdin_runtime_bridge" ,
117+ "set_stdin_context_value" ,
118+ ]
0 commit comments