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 PromptVal(vm._Callable):
|
19 | """
|
20 | _io->promptVal('$') is like \$
|
21 | It expands to $ or # when root
|
22 | """
|
23 |
|
24 | def __init__(self):
|
25 | # type: () -> None
|
26 | pass
|
27 |
|
28 | def Call(self, rd):
|
29 | # type: (typed_args.Reader) -> value_t
|
30 |
|
31 | # "self" param is guaranteed to succeed
|
32 | io = rd.PosIO()
|
33 | what = rd.PosStr()
|
34 | rd.Done() # no more args
|
35 |
|
36 | # Bug fix: protect against crash later in PromptVal()
|
37 | if len(what) != 1:
|
38 | raise error.Expr(
|
39 | 'promptVal() expected a single char, got %r' % what,
|
40 | rd.LeftParenToken())
|
41 |
|
42 | prompt_ev = cast(prompt.Evaluator, io.prompt_ev)
|
43 | return value.Str(prompt_ev.PromptVal(what))
|