Skip to content

Problems understanding PipeInput #411

Open
@fspegni

Description

@fspegni

Hi. I'm studying your library since a while, but didn't find a proper way of fixing my issue.

In brief: I have a customized app, eventloop, and cli. I want the user to pass a custom input (let's say a PipeInput) to the cli.

I send 4 \n separated lines on the PipeInput, but it looks to me the prompt doesn't process three commands.

A minimal script is:

import prompt_toolkit as pt


def my_prompt(prompt_in):
    """
    Inspired by prompt_toolkit.shortcuts.prompt()
    """

    line = None

    try:
        app = pt.shortcuts.create_prompt_application(
            erase_when_done=True,
        )
        el = pt.shortcuts.create_eventloop()
        cli = pt.interface.CommandLineInterface(
            application=app,
            input=prompt_in,
            eventloop=el,
            output=pt.shortcuts.create_output(true_color=False)
        )
        patch_context = pt.utils.DummyContext()

        with patch_context:
            doc = cli.run(reset_current_buffer=True)

            if doc:
                line = doc.text.strip()

    except EOFError:
        line = None

    return line

# setup the input
prompt_in = pt.input.PipeInput()
prompt_in.send("foo\nfie\nfoo\nfie\n")

# start the interpretation loop

while True:

    try:

        line = my_prompt(prompt_in)

        if line is None:
            break

        print "[%s]" % line
    except KeyboardInterrupt:
        print "Goodbye"
        break
    except Exception, e:
        print "Error: %s" % e
        break

The output is:

user@host:wd$ python example.py  
foo
[foo]
^[[23;1R^[[23;9R

I can't understand what those strange sequences of characters mean, and how to debug this problem.

Hope you can shed some light :) Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions