OILS / builtin / method_io.py View on Github | oilshell.org

87 lines, 43 significant
1"""Methods on IO type"""
2from __future__ import print_function
3
4from _devbuild.gen.value_asdl import value, value_t
5
6from core import error
7from core import vm
8from mycpp.mylib import log
9from osh import prompt
10
11from typing import cast, TYPE_CHECKING
12if TYPE_CHECKING:
13 from frontend import typed_args
14
15_ = log
16
17
18class Eval(vm._Callable):
19
20 def __init__(self):
21 # type: () -> None
22 pass
23
24 def Call(self, rd):
25 # type: (typed_args.Reader) -> value_t
26 return value.Null
27
28
29class CaptureStdout(vm._Callable):
30
31 def __init__(self):
32 # type: () -> None
33 pass
34
35 def Call(self, rd):
36 # type: (typed_args.Reader) -> value_t
37 return value.Null
38
39
40class PromptVal(vm._Callable):
41 """
42 _io->promptVal('$') is like \$
43 It expands to $ or # when root
44 """
45
46 def __init__(self):
47 # type: () -> None
48 pass
49
50 def Call(self, rd):
51 # type: (typed_args.Reader) -> value_t
52
53 # "self" param is guaranteed to succeed
54 io = rd.PosIO()
55 what = rd.PosStr()
56 rd.Done() # no more args
57
58 # Bug fix: protect against crash later in PromptVal()
59 if len(what) != 1:
60 raise error.Expr(
61 'promptVal() expected a single char, got %r' % what,
62 rd.LeftParenToken())
63
64 prompt_ev = cast(prompt.Evaluator, io.prompt_ev)
65 return value.Str(prompt_ev.PromptVal(what))
66
67
68class Time(vm._Callable):
69
70 def __init__(self):
71 # type: () -> None
72 pass
73
74 def Call(self, rd):
75 # type: (typed_args.Reader) -> value_t
76 return value.Null
77
78
79class Strftime(vm._Callable):
80
81 def __init__(self):
82 # type: () -> None
83 pass
84
85 def Call(self, rd):
86 # type: (typed_args.Reader) -> value_t
87 return value.Null