Comments (12)
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.
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.
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:
- Build these other input types right into textinput
- Build them on top of
textinput
, withtextinput
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.
@obnoxiousnerd Yes! No timeline but it's definitely something we want to to get in.
from bubbles.
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.
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.
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 ofboolinput
, but cancelling is a state ofboolinput
, 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.
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.
Are there any plans for multiline input?
from bubbles.
@meowgorithm can we help somehow?
from bubbles.
I was thinking of ways to implement multiline input. The ideas were:
- Using multiple
textinput
s - 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.
Any updates on multiline-textinput
s?
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)
- Making multiple inputs blink HOT 2
- Extended Latin characters not supported in textinput on Windows HOT 11
- help: rendering issues when the text doesn't fit into the available width
- table: honor a column width set to 0 HOT 3
- List interface bug for downstream packages
- `Bug`: Pasting String Bypasses CharLimit in textarea HOT 2
- Table cell padding no longer works since 1ba1200 HOT 15
- Viewport may not scroll down to the end of large text inputs HOT 8
- feat: Add NumberInput in bubbles HOT 4
- textinput: add support for wrapping the prompt HOT 2
- How to define the color of a specified cell in a table
- List : list panel pushed into title/status panels by padding on items HOT 1
- Table cell selection
- table printing breaks in narrow windows HOT 2
- styled placeholders HOT 2
- Slim cursor HOT 2
- viewport: ANSI color information seems to be bleeding into surrounding text
- Running on Windows 7 results in an error. HOT 1
- textinput: when `Width` is larger than the capacity of the placeholder, it causes a panic
- table: SelectedStyle is not inherited for `StyleFunc`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bubbles.