prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.28k stars 715 forks source link

Long Names #909

Open mlucool opened 5 years ago

mlucool commented 5 years ago

Hi,

If I have a long name I am trying to autocomplete, this no longer is useful. Would it be possible to allow for one of the following:

  1. Allow the part already typed to not be included
  2. Ellipsis the start not the end of the string
  3. Allow for the text displayed in the UI to not be the text updates what is selected

While below is contrived, this happens with autocomplete of long chains of properties. Reproducer:

import random
import string

def randomString(stringLength=10):
    """Generate a random string of fixed length """
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for i in range(stringLength))

def my_completer(c, text):
    longstr = 'AUTO_COMPLETE_A_VERY_LONG_STRING_BECAUSE_SOMETIMES_THIS_HAPPENS'
    if text.startswith(longstr):
        return [(longstr + randomString()).decode('utf8') for x in range(150)]
    return []

get_ipython().set_custom_completer(my_completer, 0)

image

Python 2.7.15 IPython 5.8.0 PromptToolkit: 1.0.15

Please also let me know if this is available in a later version of prompt_toolkit.

jonathanslenders commented 5 years ago

Hi @mlucool,

This totally makes sense to have, but is unfortunately not yet available in prompt_toolkit. It can be done though, let's take this as a feature request.

utabe commented 5 years ago

@jonathanslenders I'm interested in this as well. Where in the code would a change need to be made to make this happen?

utabe commented 5 years ago

Would modifying _trim_formatted_text in prompt_toolkit\layout\menus.py work as a solution to option 2 listed above?

Ellipsis the start not the end of the string

quarl commented 5 years ago

(The original https://github.com/prompt-toolkit/python-prompt-toolkit/issues/909#issue-450548763 May30 request came from me.)

1. Allow the part already typed to not be included

Clarifying the above approach1: Suppose:

It would be nice for the prompt_toolkit completer to only show bar1, bar2, bar3; don't try to show foo1.foo2.foo3.foo4.foo5.foo6.bar1, foo1.foo2.foo3.foo4.foo5.foo6.bar2, foo1.foo2.foo3.foo4.foo5.foo6.bar3

We propose to show only the completion names, instead of repeating the entire input string.

This approach1 doesn't handle single names that are really long; that could still be handled by approach2 (ellipsis the start) in addition to approach1.

Carreau commented 4 years ago

Sidenote, the example at the top will not work on Py3, because it tries to decode a string (which Python 2 does because f casting)

Carreau commented 4 years ago

https://github.com/ipython/ipython/pull/12284 does some of that on the IPython side.