Closed
Description
Could we have an option so that prompt
only accepts a single line, even when pasting some text ?
Currently, even when multiline
is set to False, you can paste multi-line text in it.
Code: Here's the code i am using:
PROMPT_TOOLKIT_HISTORY = prompt_toolkit.history.FileHistory(conf.histfile)
# ScapyCompleter is a quite basic completer, returning all matching content as a shell would do
_completer = ScapyCompleter()
from prompt_toolkit.token import Token
prompts_style = prompt_toolkit.styles.style_from_dict({
Token.Prompt: "#2E64FE",
})
def readLineScapy(prompt):
result = ""
end = False
while not end :
if not end and result != "":
line = prompt_toolkit.prompt(u"... ", completer=_completer, history=PROMPT_TOOLKIT_HISTORY)
else:
line = prompt_toolkit.prompt(u">>> ", completer=_completer, style=prompts_style, history=PROMPT_TOOLKIT_HISTORY)
if line.strip()[-1:] in [":", "(", ",", "\\"]:
end = False
elif result == "":
end = True
if line.strip() == "":
end = True
result = result + "\n" + line
result = result.replace("\\\n", "")
return str(result)
# Run console with python_toolkit
code.interact(banner="hello, this is a great shell", readfunc=readLineScapy)
The goal of this code is to emulate a shell. In that way, we need to print "..." or ">>>" on each line. readlinescapy
is using prompt_toolkit.prompt
to get the same input as in a shell...
When one copy multi-line, the prompt
function takes all the lines, so ...
is not printed.
Metadata
Metadata
Assignees
Labels
No labels