1 | """Methods on IO type"""
|
2 | from __future__ import print_function
|
3 |
|
4 | from _devbuild.gen.value_asdl import value, value_t
|
5 |
|
6 | from core import error
|
7 | from core import vm
|
8 | from mycpp.mylib import log
|
9 | from osh import prompt
|
10 |
|
11 | from typing import cast, TYPE_CHECKING
|
12 | if TYPE_CHECKING:
|
13 | from frontend import typed_args
|
14 |
|
15 | _ = log
|
16 |
|
17 |
|
18 | class 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 |
|
29 | class 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 |
|
40 | class 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 |
|
68 | class 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 |
|
79 | class 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
|