| Crates.io | promkit-derive |
| lib.rs | promkit-derive |
| version | 0.2.0 |
| created_at | 2025-03-17 14:42:49.932022+00 |
| updated_at | 2025-07-15 11:01:34.578794+00 |
| description | A derive macro for promkit |
| homepage | |
| repository | https://github.com/ynqa/promkit |
| max_upload_size | |
| id | 1595563 |
| size | 38,693 |
Macro for promkit derives.
promkit-derive provides a Derive macro that simplifies interactive form input.
By applying the #[derive(Promkit)] attribute to a struct,
you can automatically generate interactive forms that populate your struct fields with user input.
#[derive(Promkit)] macro automatically creates
interactive form fields based on your struct definitionuse promkit::crossterm::style::{Color, ContentStyle};
use promkit_derive::Promkit;
#[derive(Default, Debug, Promkit)]
struct Profile {
#[form(
label = "What is your name?",
label_style = ContentStyle {
foreground_color: Some(Color::DarkCyan),
..Default::default()
},
)]
name: String,
#[form(default)]
hobby: Option<String>,
#[form(label = "How old are you?", ignore_invalid_attr = "nothing")]
age: usize,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut ret = Profile::default();
ret.build()?;
dbg!(ret);
Ok(())
}
The #[form(...)] attribute supports the following options:
label: Text label for the form fieldlabel_style: Style settings for the labelactive_char_style: Style for active charactersinactive_char_style: Style for inactive charactersmask: Masking character for password inputsedit_mode: Edit mode settingsword_break_chars: Word break character settingsdefault: Use default settings (no options)String, usize, i32, etc.)Option<T> types (becomes None if input is invalid)The #[derive(Promkit)] macro implements a build() method on your struct that:
#[form] attributeThis allows you to create interactive form inputs with minimal code, simply by defining your struct and its fields.