Coder Social home page Coder Social logo

Feat: More input types about bubbles HOT 12 CLOSED

charmbracelet avatar charmbracelet commented on August 20, 2024 1
Feat: More input types

from bubbles.

Comments (12)

muesli avatar muesli commented on August 20, 2024 3

I'd fancy a Validate function that gets called before input gets accepted by a textinput. We could provide a few common validators (bool, int, ...), but you could also implement one yourself that only accepts very specific inputs.

from bubbles.

maaslalani avatar maaslalani commented on August 20, 2024 3

Hey @kiyonlin @cakir-enes @quenbyako @retronav happy to share that these features are now possible :)

Multiline input was just added as a new textarea bubble in master

And what I want most is boolinput, which can only let user input y | n | yes | no | t | f | 0 | 1 | true | false etc.

This is now possible with Validate on the textinput which was included in the latest release: https://github.com/charmbracelet/bubbles/releases/v0.12.0

func boolValidator(s string) error {
  if s == "y" || s == "n"|| s == "t" || s == "0" || s == "1" {
    return nil
  }
  for _, v := range []string{"yes", "no", "true", "false"} {
    if strings.HasPrefix(v, s) {
      return nil
    }
  }
  return errors.New("invalid input")
}

textinput.Validate = boolValidator

from bubbles.

meowgorithm avatar meowgorithm commented on August 20, 2024 2

It makes sense to add these. Because of all the complexities of textinput like nice cursor blinking and horizontal scrolling it makes the most sense to either:

  1. Build these other input types right into textinput
  2. Build them on top of textinput, with textinput embedded in the model

I think building them on top of textinput makes the most sense so the individual implementations are very isolated and clear.

Btw, all input should know if itself is canceled which is different from zero value(like empty string), because some programs should be terminated if user cancel a prompt

The notion of cancelling is probably outside the scope of pure text input, but there could be a prompt that handles that. What do you think?


Question about boolinput: does it need to be text-based? What I usually do is prompt the user with something like:

Continue (y/N)

And then I listen for y to confirm, and all other keys to cancel. If it's a sensitive operation I'll confirm a true response with:

Are you sure (y/N)

Just a general thought, though. We can still support a text-based bool input.

from bubbles.

meowgorithm avatar meowgorithm commented on August 20, 2024 1

@obnoxiousnerd Yes! No timeline but it's definitely something we want to to get in.

from bubbles.

meowgorithm avatar meowgorithm commented on August 20, 2024 1

It'll probably make the most sense to add a multiline option to the existing textinput because of all the subtleties already handled in there. More than likely a viewport will be the most practical way to handle vertical overflow.

We'd prefer to do this one internally because of the significance that textinput bears on the Bubble Tea ecosystem, however we can't offer a timeline just yet.

from bubbles.

kiyonlin avatar kiyonlin commented on August 20, 2024

I think building them on top of textinput makes the most sense so the individual implementations are very isolated and clear.

@meowgorithm Agree

The notion of cancelling is probably outside the scope of pure text input, but there could be a prompt that handles that. What do you think?

The similar case in web is that users use esc(or click cancel button) to cancel a prompt, but they may input something before cancelling it. I don't understand there could be a prompt that handles that, could you please elaborate that?

And then I listen for y to confirm, and all other keys to cancel.

I think y/N is the value of boolinput, but cancelling is a state of boolinput, means "I don't want to answer it".

from bubbles.

meowgorithm avatar meowgorithm commented on August 20, 2024

I don't understand there could be a prompt that handles that, could you please elaborate that?

I'm not sure if canceling or accepting the value of a textinput belongs in textinput itself (here’s an example of how I'd implement it on top of textinput). But maybe it makes sense to just put cancel/confirm inside of textinput. Totally open to any thoughts on how you might want to do it.

I think y/N is the value of boolinput, but cancelling is a state of boolinput, means "I don't want to answer it".

That make sense. You could also prompt with yes/no/cancel, but regardless we can add a boolean textinput too.

from bubbles.

kiyonlin avatar kiyonlin commented on August 20, 2024

But maybe it makes sense to just put cancel/confirm inside of textinput.

Bubbletea textinput is a prompt "dialog" in a sense imo. So I prefer to put the state inside of textinput like you said.

from bubbles.

retronav avatar retronav commented on August 20, 2024

Are there any plans for multiline input?

from bubbles.

quenbyako avatar quenbyako commented on August 20, 2024

@meowgorithm can we help somehow?

from bubbles.

retronav avatar retronav commented on August 20, 2024

I was thinking of ways to implement multiline input. The ideas were:

  1. Using multiple textinputs
  2. Creating a separate component with textinput as the base with newlines as delimiter for cursor position in the y direction with overflow handling

What do you guys think? @meowgorithm @quenbyako

from bubbles.

cakir-enes avatar cakir-enes commented on August 20, 2024

Any updates on multiline-textinputs?
Using multiple textinput could work until user tries to paste stuff I think. A proper component would be much better.

from bubbles.

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.