MCPcopy
hub / github.com/google/python-fire / _GetSearchCommand

Method _GetSearchCommand

fire/console/console_pager.py:128–157  ·  view source on GitHub ↗

Consumes a search command and returns the equivalent pager command. The search pattern is an RE that is pre-compiled and cached for subsequent / , ? , n, or N commands. Args: c: The search command char. Returns: The pager command char.

(self, c)

Source from the content-addressed store, hash-verified

126 self._out.write(s)
127
128 def _GetSearchCommand(self, c):
129 """Consumes a search command and returns the equivalent pager command.
130
131 The search pattern is an RE that is pre-compiled and cached for subsequent
132 /<newline>, ?<newline>, n, or N commands.
133
134 Args:
135 c: The search command char.
136
137 Returns:
138 The pager command char.
139 """
140 self._Write(c)
141 buf = ''
142 while True:
143 p = self._attr.GetRawKey()
144 if p in (None, '\n', '\r') or len(p) != 1:
145 break
146 self._Write(p)
147 buf += p
148 self._Write('\r' + ' ' * len(buf) + '\r')
149 if buf:
150 try:
151 self._search_pattern = re.compile(buf)
152 except re.error:
153 # Silently ignore pattern errors.
154 self._search_pattern = None
155 return ''
156 self._search_direction = 'n' if c == '/' else 'N'
157 return 'n'
158
159 def _Help(self):
160 """Print command help and wait for any character to continue."""

Callers 1

RunMethod · 0.95

Calls 2

_WriteMethod · 0.95
GetRawKeyMethod · 0.80

Tested by

no test coverage detected