MCPcopy Index your code
hub / github.com/RustPython/RustPython / ReadlineAlikeReader

Class ReadlineAlikeReader

Lib/_pyrepl/readline.py:105–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104@dataclass(kw_only=True)
105class ReadlineAlikeReader(historical_reader.HistoricalReader, CompletingReader):
106 # Class fields
107 assume_immutable_completions = False
108 use_brackets = False
109 sort_in_column = True
110
111 # Instance fields
112 config: ReadlineConfig
113 more_lines: MoreLinesCallable | None = None
114 last_used_indentation: str | None = None
115
116 def __post_init__(self) -> None:
117 super().__post_init__()
118 self.commands["maybe_accept"] = maybe_accept
119 self.commands["maybe-accept"] = maybe_accept
120 self.commands["backspace_dedent"] = backspace_dedent
121 self.commands["backspace-dedent"] = backspace_dedent
122
123 def error(self, msg: str = "none") -> None:
124 pass # don't show error messages by default
125
126 def get_stem(self) -> str:
127 b = self.buffer
128 p = self.pos - 1
129 completer_delims = self.config.completer_delims
130 while p >= 0 and b[p] not in completer_delims:
131 p -= 1
132 return "".join(b[p + 1 : self.pos])
133
134 def get_completions(self, stem: str) -> list[str]:
135 if len(stem) == 0 and self.more_lines is not None:
136 b = self.buffer
137 p = self.pos
138 while p > 0 and b[p - 1] != "\n":
139 p -= 1
140 num_spaces = 4 - ((self.pos - p) % 4)
141 return [" " * num_spaces]
142 result = []
143 function = self.config.readline_completer
144 if function is not None:
145 try:
146 stem = str(stem) # rlcompleter.py seems to not like unicode
147 except UnicodeEncodeError:
148 pass # but feed unicode anyway if we have no choice
149 state = 0
150 while True:
151 try:
152 next = function(stem, state)
153 except Exception:
154 break
155 if not isinstance(next, str):
156 break
157 result.append(next)
158 state += 1
159 # emulate the behavior of the standard readline that sorts
160 # the completions before displaying them.
161 result.sort()
162 return result

Callers 1

get_readerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected