MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / highlight_args

Method highlight_args

cmd2/pt_utils.py:229–242  ·  view source on GitHub ↗

Highlight arguments in a string.

(text: str, tokens: list[tuple[str, str]])

Source from the content-addressed store, hash-verified

227 arg_pattern = re.compile(r'(\s+)|(--?[^\s\'"]+)|("[^"]*"?|\'[^\']*\'?)|([^\s\'"]+)')
228
229 def highlight_args(text: str, tokens: list[tuple[str, str]]) -> None:
230 """Highlight arguments in a string."""
231 for m in arg_pattern.finditer(text):
232 space, flag, quoted, word = m.groups()
233 match_text = m.group(0)
234
235 if space:
236 tokens.append(("", match_text))
237 elif flag:
238 tokens.append((self.flag_color, match_text))
239 elif (quoted or word) and match_text not in exclude_tokens:
240 tokens.append((self.argument_color, match_text))
241 else:
242 tokens.append(("", match_text))
243
244 def get_line(lineno: int) -> list[tuple[str, str]]:
245 """Return the tokens for the given line number."""

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected