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.37k stars 716 forks source link

History search matching anywhere #532

Open ahundt opened 7 years ago

ahundt commented 7 years ago

I believe the current history search matches from the start of the string. Could it be updated with an option for matching anywhere in the string?

The enable_history_search could perhaps be updated where the current True and False settings do as they have done, but now there are additional options for enable_history_search=:

I may not understand the classes right, but I'm looking at making the change... my thoughts are below:

The actual string search part at each line is hopefully easy, assuming basic python strings are actually used internally:

>>> "King" in "King's landing"
True

>>> "Jon Snow" in "King's landing"
False
decentral1se commented 6 years ago

Hi @ahundt, from https://github.com/jonathanslenders/python-prompt-toolkit/pull/534#issuecomment-322538767, I can see that the idea of the change should go in, which is cool :+1:

I am not sure about your changes in https://github.com/ahundt/python-prompt-toolkit/commit/e62d188ac311695192b3fb1495f8e5d4ddd619df. It seems like the purpose of enable_history_search is to enable the functionality, not to configure the functionality. What do you think about adding a different optional argument, perhaps a callable (which might reduce having to specify explicitly all the keywords) that configures the searching? The default would then be the existing functionality.

This seems like a better API to me. Just some thoughts from a passing issue gardener :)

ahundt commented 6 years ago

I'll defer to you on design. I think python prompt toolkit 2 has a completely different design so this PR may no longer be useful.

Please note that this is a code base I'm not familiar with, so I just tried to implement it with the fewest possible modifications.

ahundt commented 6 years ago

@jonathanslenders Is this now possible to do in 2.0.x? If so, could you explain how & then this issue can likely be closed.