prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.2k stars 277 forks source link

Dynamic prompt with newline. #244

Open nasyxx opened 6 years ago

nasyxx commented 6 years ago

When I custom a dynamic prompt with newlines in it, I mean '\n' in it, the width will be incorrect.

For example, if my custom prompt defines like this:

class CustomPrompt(PromptStyle):
    def in_tokens(self, cli):
        return [
            (Token.In, 'Something\n'),
            (Token.In, 'In ['),
            (Token.In.Number, '%s' % repl.current_statement_index),
            (Token.In, ']: '),
        ]

the excepted output should be:

Something
In [1]: print("hello")

but the fact is:

screen shot 2018-06-02 at 2 51 58 pm
Something        print("Hello")
In [1]:

Could you show me where I should change to let this 'prompt' start from the second line In [1]:.

jonathanslenders commented 6 years ago

Your code is fine here, this needs to be fixed in ptpython. It probably requires the prompt_toolkit line-prefixes branch to be merged, and then the layout needs to be rewritten so that it uses the same approach as prompt_toolkit.shortcuts.prompt for rendering the prompt. It's not a little undertaking, but hopefully this will be possible soon.

nasyxx commented 6 years ago

Thank you