Giter VIP home page Giter VIP logo

Comments (5)

mikaelmello avatar mikaelmello commented on May 30, 2024 1

@fribeau v0.3.0-alpha-2 is now up :)

from inquire.

mikaelmello avatar mikaelmello commented on May 30, 2024

Hey @fribeau.

Actually, we don't have the tab assigned to anything on this prompt. What I believe you're seeing in the demo was that I pressed down arrow to move the cursor to the first suggestion, then the prompt auto-updated the text field to the highlighted suggestion.

You bring a very good point on usability though, the tab key is widely known as associated to auto-completion, so I think it is a usability problem for us to not use it. I'm thinking of assigning tab to either use the first suggestion in the list, if none are selected, or update text field to the current highlighted suggestion, which would basically remove other suggestions.

from inquire.

fribeau avatar fribeau commented on May 30, 2024

Thanks for this quick reply and for this awesome crate 😉

I also think handling tab would be really a great feature.

Regarding the tab assignment you proposing, I know that for my use case it would not work as expected. I am trying to implement a path autocomplete so I am trying to reproduce the same behavior I am getting in the terminal (with bash for example).

If I have the following directory structure and the input is /bar/f I would expect /bar/foo when the user press the tab key, but not necessary the first result (/bar/foo1).

/bar
  /foo1
  /foo2

Another approach could be:

  • if only 1 suggestion remain -> complete with it
  • if many -> complete with the longest prefix available

But maybe my use case it too specific

from inquire.

mikaelmello avatar mikaelmello commented on May 30, 2024

Yeah I think that's a little too specific for the library.

The suggestion-er behavior is implemented by the user, which means that if we hard-coded the completion process to something implementation-specific, it would break other use-cases, for example fuzzy searching and searching by substrings instead of prefixes, from the top of my mind.

What we could do instead is to have a default implementation (complete with the first option), but then provide the ability for the user to provide a hook, e.g. "auto_complete(cur_input: &str) -> String". Then you could do:

auto_complete = |cur_input| {
  // return string with longest prefix that matches input
}

Then, the prompt would call your method, get what auto-completion string and replace the current input with your completion.

There are still a few details on how to make this works seamlessly with the current "suggestion" system, but it is a direction forward :)

from inquire.

fribeau avatar fribeau commented on May 30, 2024

Hey @mikaelmello

I have tried several implementations trying to come up with a good solution to this problem. I finally ended up with the solution you proposed 😉 It is a good one because it is really simple so it can really be customized to the user needs.

I opened a PR to showcase this feature. You're welcome to criticize, I am completely open to suggestions.

from inquire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.