зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-08-28 11:36:17 +03:00
refactor password example and the example screencast in readme
Этот коммит содержится в:
10
README.md
10
README.md
@@ -101,6 +101,16 @@ Popup textarea with a placeholder text.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/rhysd/ss/master/tui-textarea/placepop.gif" width=539 height=220 alt="popup textarea with placeholder example">
|
||||
|
||||
### [`password`](./examples/password.rs)
|
||||
|
||||
```sh
|
||||
cargo run --example password
|
||||
```
|
||||
|
||||
Password input form with masking text with ●.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/rhysd/ss/master/tui-textarea/password.gif" width=589 height=92 alt="password example">
|
||||
|
||||
### Examples for [ratatui][] support
|
||||
|
||||
All above examples use [tui-rs][], but some examples provide [ratatui][] version. Try `ratatui_` prefix. In these cases,
|
||||
|
||||
@@ -23,10 +23,11 @@ fn main() -> io::Result<()> {
|
||||
textarea.set_cursor_line_style(Style::default());
|
||||
textarea.set_mask_char('\u{2022}'); //U+2022 BULLET (•)
|
||||
textarea.set_placeholder_text("Please enter your password");
|
||||
let layout =
|
||||
Layout::default().constraints([Constraint::Length(3), Constraint::Min(1)].as_slice());
|
||||
let constraints = [Constraint::Length(3), Constraint::Min(1)].as_slice();
|
||||
let layout = Layout::default().constraints(constraints);
|
||||
textarea.set_style(Style::default().fg(Color::LightGreen));
|
||||
textarea.set_block(Block::default().borders(Borders::ALL).title("Password"));
|
||||
|
||||
loop {
|
||||
term.draw(|f| {
|
||||
let chunks = layout.split(f.size());
|
||||
@@ -35,15 +36,13 @@ fn main() -> io::Result<()> {
|
||||
})?;
|
||||
|
||||
match crossterm::event::read()?.into() {
|
||||
Input { key: Key::Esc, .. } => break,
|
||||
Input {
|
||||
key: Key::Enter, ..
|
||||
key: Key::Esc | Key::Enter,
|
||||
..
|
||||
} => break,
|
||||
|
||||
input => {
|
||||
// TextArea::input returns if the input modified its text
|
||||
if textarea.input(input) {
|
||||
// is_valid = validate(&mut textarea);
|
||||
// When the input modified its text, validate the text content
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +52,7 @@ fn main() -> io::Result<()> {
|
||||
crossterm::execute!(
|
||||
term.backend_mut(),
|
||||
LeaveAlternateScreen,
|
||||
DisableMouseCapture
|
||||
DisableMouseCapture,
|
||||
)?;
|
||||
term.show_cursor()?;
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user