bubbletea_widgets/textinput/
types.rs

1//! Core types for the textinput component.
2
3use bubbletea_rs::Msg;
4
5/// Internal messages for clipboard operations.
6/// Matches Go's pasteMsg and pasteErrMsg types.
7/// Clipboard paste message carrying raw text.
8#[derive(Debug, Clone)]
9pub struct PasteMsg(pub String);
10
11/// Clipboard paste error message.
12#[derive(Debug, Clone)]
13pub struct PasteErrMsg(pub String);
14
15/// EchoMode sets the input behavior of the text input field.
16/// Matches Go's EchoMode enum exactly.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum EchoMode {
19    /// EchoNormal displays text as is. This is the default behavior.
20    EchoNormal,
21    /// EchoPassword displays the EchoCharacter mask instead of actual characters.
22    /// This is commonly used for password fields.
23    EchoPassword,
24    /// EchoNone displays nothing as characters are entered. This is commonly
25    /// seen for password fields on the command line.
26    EchoNone,
27}
28
29/// ValidateFunc is a function that returns an error if the input is invalid.
30/// Add Send to satisfy bubbletea-rs Model:Send bound transitively.
31pub type ValidateFunc = Box<dyn Fn(&str) -> Result<(), String> + Send>;
32
33impl From<PasteMsg> for Msg {
34    fn from(msg: PasteMsg) -> Self {
35        Box::new(msg) as Msg
36    }
37}
38
39impl From<PasteErrMsg> for Msg {
40    fn from(msg: PasteErrMsg) -> Self {
41        Box::new(msg) as Msg
42    }
43}