1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-07 07:55:50 +03:00

refactor password example and the example screencast in readme

Этот коммит содержится в:
rhysd
2023-10-20 22:02:04 +09:00
родитель 4fa7a16b72
Коммит d9dd1a168c
2 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@@ -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"> <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 ### Examples for [ratatui][] support
All above examples use [tui-rs][], but some examples provide [ratatui][] version. Try `ratatui_` prefix. In these cases, 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_cursor_line_style(Style::default());
textarea.set_mask_char('\u{2022}'); //U+2022 BULLET (•) textarea.set_mask_char('\u{2022}'); //U+2022 BULLET (•)
textarea.set_placeholder_text("Please enter your password"); textarea.set_placeholder_text("Please enter your password");
let layout = let constraints = [Constraint::Length(3), Constraint::Min(1)].as_slice();
Layout::default().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_style(Style::default().fg(Color::LightGreen));
textarea.set_block(Block::default().borders(Borders::ALL).title("Password")); textarea.set_block(Block::default().borders(Borders::ALL).title("Password"));
loop { loop {
term.draw(|f| { term.draw(|f| {
let chunks = layout.split(f.size()); let chunks = layout.split(f.size());
@@ -35,15 +36,13 @@ fn main() -> io::Result<()> {
})?; })?;
match crossterm::event::read()?.into() { match crossterm::event::read()?.into() {
Input { key: Key::Esc, .. } => break,
Input { Input {
key: Key::Enter, .. key: Key::Esc | Key::Enter,
..
} => break, } => break,
input => { input => {
// TextArea::input returns if the input modified its text
if textarea.input(input) { 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!( crossterm::execute!(
term.backend_mut(), term.backend_mut(),
LeaveAlternateScreen, LeaveAlternateScreen,
DisableMouseCapture DisableMouseCapture,
)?; )?;
term.show_cursor()?; term.show_cursor()?;