-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add a new text input widget - command input uses text input component - autocompletion and state of content of input lives in widgets::text_input::TextInputState - history logic still lives in old command input field
- Loading branch information
1 parent
20d6f41
commit ce8651a
Showing
8 changed files
with
231 additions
and
98 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
pub mod alert_modal; | ||
pub mod boolean_modal; | ||
pub mod command_input; | ||
pub mod footer; | ||
pub mod header; | ||
pub mod help; | ||
pub mod input_field; | ||
pub mod resize_notice; | ||
pub mod text_input_wrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use color_eyre::eyre::Result; | ||
|
||
use crate::{ | ||
events::{message::MessageResponse, Key}, | ||
traits::Component, | ||
widgets::text_input::{Autocomplete, TextInput, TextInputState}, | ||
}; | ||
|
||
/// Component which TextInput widget providing baked in keyboard input handling | ||
#[derive(Debug)] | ||
pub struct TextInputWrapper { | ||
prompt: String, | ||
state: TextInputState, | ||
} | ||
|
||
impl TextInputWrapper { | ||
pub fn new(prompt: String, autocomplete: Option<Autocomplete<'static>>) -> Self { | ||
let state = TextInputState::new(autocomplete); | ||
Self { prompt, state } | ||
} | ||
|
||
pub fn reset(&mut self) { | ||
self.state.reset() | ||
} | ||
|
||
pub fn update(&mut self, message: Key) -> Result<MessageResponse> { | ||
match message { | ||
Key::Char(c) => self.state.push_character(c), | ||
Key::Tab => self.state.accept_autocomplete_candidate(), | ||
Key::Backspace => { | ||
self.state.pop_character(); | ||
} | ||
_ => return Ok(MessageResponse::NotConsumed), | ||
} | ||
|
||
Ok(MessageResponse::Consumed) | ||
} | ||
|
||
pub fn get_value(&mut self) -> String { | ||
self.state.get_value().clone() | ||
} | ||
|
||
pub fn set_input(&mut self, value: String) { | ||
self.state.set_input(value); | ||
} | ||
} | ||
|
||
impl Component for TextInputWrapper { | ||
fn draw(&mut self, f: &mut ratatui::Frame<'_>, area: ratatui::prelude::Rect) { | ||
let text_input = TextInput::new(Some(self.prompt.clone())); | ||
f.render_stateful_widget(text_input, area, &mut self.state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod autocomplete; | ||
pub mod callbacks; | ||
pub mod components; | ||
pub mod config; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod modal; | ||
pub mod text_input; |
Oops, something went wrong.