prompt_toolkit and extra backslash escapes

77 Views Asked by At

I'm working on a CPython project that uses prompt-toolkit for tab completion of almost-POSIXy folders in a hierarchical password store.

I'm finding that if I pass \"kl into Completion(text=n, display=n + '/', start_position=-len(name)) as text=n, then I get as output:

My Vault/cd-tests> cd \\"kl
\"kl/

It appears display= is doing what I want, but the first argument (text=n) is not. That is, I want to see cd \"kl - not cd \\"kl

Does prompt_toolkit add an additional layer of quoting to text somewhere? This prepending of the 2nd \ seems to be happening somewhere else entirely - like possibly inside of prompt-toolkit. If it does, is there a way of turning it off?

I'm developing on macOS 11.5.1 - but this needs to work on Windows and Linux too. I'm using prompt-toolkit==3.0.20, though ISTR I had a similar issue on an older version (2.x.x). I'm using CPython 3.9 at the moment (from homebrew), but this needs to run on 3.6+.

I googled quite a bit, and I looked over the help on prompt_toolkit.completion.Completion in a REPL, and I studied the prompt_toolkit source code and documentation more than a little, but I didn't find anything that looked relevant to this doubling of the backslash.

How can I get Completion(text=n) to display what I pass verbatim?

Thanks!

1

There are 1 best solutions below

0
On

It turned out this was because of a bad start_position argument. It gave the appearance of extra quoting, but that was just because in this case it was repeating the first character.