0

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!

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
dstromberg
  • 6,954
  • 1
  • 26
  • 27
  • Here's an interesting example. It's not just an initial \" that has the problem. I'm also getting gg\\"h from g\" when g"h exists. And again, the display= is rendered the way I want. it's text= that has trouble. display= shows: g\"h/ – dstromberg Sep 01 '21 at 21:54

1 Answers1

0

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.

dstromberg
  • 6,954
  • 1
  • 26
  • 27