MCPcopy Index your code
hub / github.com/ipython/ipython / format_prompt_keys

Function format_prompt_keys

docs/autogen_shortcuts.py:144–180  ·  view source on GitHub ↗

Format prompt toolkit key with modifier into an RST representation.

(keys: str, add_alternatives=True)

Source from the content-addressed store, hash-verified

142
143
144def format_prompt_keys(keys: str, add_alternatives=True) -> str:
145 """Format prompt toolkit key with modifier into an RST representation."""
146
147 def to_rst(key):
148 escaped = key.replace("\\", "\\\\")
149 return f":kbd:`{escaped}`"
150
151 keys_to_press: List[str]
152
153 prefixes = {
154 "c-s-": [to_rst("ctrl"), to_rst("shift")],
155 "s-c-": [to_rst("ctrl"), to_rst("shift")],
156 "c-": [to_rst("ctrl")],
157 "s-": [to_rst("shift")],
158 }
159
160 for prefix, modifiers in prefixes.items():
161 if keys.startswith(prefix):
162 remainder = keys[len(prefix) :]
163 keys_to_press = [*modifiers, to_rst(remainder)]
164 break
165 else:
166 keys_to_press = [to_rst(keys)]
167
168 result = " + ".join(keys_to_press)
169
170 if keys in INDISTINGUISHABLE_KEYS and add_alternatives:
171 alternative = INDISTINGUISHABLE_KEYS[keys]
172
173 result = (
174 result
175 + " (or "
176 + format_prompt_keys(alternative, add_alternatives=False)
177 + ")"
178 )
179
180 return result
181
182
183if __name__ == "__main__":

Callers 1

Calls 1

to_rstFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…