зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 00:15:50 +03:00
report pattern error in title of search box in editor example
Этот коммит содержится в:
@@ -5,6 +5,7 @@ use crossterm::terminal::{
|
|||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::fmt::Display;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{BufRead, Write};
|
use std::io::{BufRead, Write};
|
||||||
@@ -76,6 +77,18 @@ impl<'a> SearchBox<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_error(&mut self, err: Option<impl Display>) {
|
||||||
|
let b = if let Some(err) = err {
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title(format!("Search: {}", err))
|
||||||
|
.style(Style::default().fg(Color::Red))
|
||||||
|
} else {
|
||||||
|
Block::default().borders(Borders::ALL).title("Search")
|
||||||
|
};
|
||||||
|
self.textarea.set_block(b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Buffer<'a> {
|
struct Buffer<'a> {
|
||||||
@@ -283,10 +296,8 @@ impl<'a> Editor<'a> {
|
|||||||
}
|
}
|
||||||
input => {
|
input => {
|
||||||
if let Some(query) = self.search.input(input) {
|
if let Some(query) = self.search.input(input) {
|
||||||
if let Err(err) = textarea.set_search_pattern(query) {
|
let maybe_err = textarea.set_search_pattern(query).err();
|
||||||
self.message =
|
self.search.set_error(maybe_err);
|
||||||
Some(format!("Invalid search pattern: {}", err).into());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user