This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
[Work in Progress] Add interactive TextInput widget, Interaction* types for interactive widgets #639
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
TextInput
- a single-line stateful widgetInteractionHandler
whencrossterm
is usedInteractiveWidget
for indicating that the widget is interactiveInteractiveWidget
is added soFrame
can be passed in by mut reference to the widget's render function. This is used for drawing the cursor for widgets which would like to do such a thing. A new trait is needed, or else backwards compatibility would be broken if the existingWidget
orStatefulWidget
traits are changed.The
InteractionHandler
trait depends on crossterm types, and is thus gated behind the crossterm feature. Widget state objects that want to process user input events take an event (state objects indicate if they're are focused, analogous to Dear imgui'sWantCaptureKeyboard
), and will return if they consumed the event or not (e.g. should the input be forwarded to the rest of the application).The
TextInput
widget and demo is a concise example of how the above Interaction* types are used. It implements a single-line text input field, which responds to a subset ofreadline
(think bash) keyboard shortcuts.Shortcuts implemented:
My hope is that
TextInput
can provide the user a simpler and more feature-rich option than the example provided inuser_input.rs
. While theuser_input
example is very cool (and indeed what inspired this!), the lack of keyboard controls is intuitive, and it requires the user to implement state tracking.Consider this a work in progress, as I'd like to get your input on if this would be a good contribution to the project. If so, I'd be happy to spend the time to go add comprehensive docs + doc tests.
Image / Recording
Testing guidelines
termion
cargo test
cargo run --example text_input
- touches most featuresChecklist