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

pass mask character on creating LineHighlighter instance

Этот коммит содержится в:
rhysd
2023-10-21 13:38:17 +09:00
родитель 4bdf55a1f6
Коммит 784ad655dc
2 изменённых файлов: 7 добавлений и 4 удалений

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

@@ -94,10 +94,11 @@ pub struct LineHighlighter<'a> {
cursor_at_end: bool, cursor_at_end: bool,
cursor_style: Style, cursor_style: Style,
tab_len: u8, tab_len: u8,
mask: Option<char>,
} }
impl<'a> LineHighlighter<'a> { impl<'a> LineHighlighter<'a> {
pub fn new(line: &'a str, cursor_style: Style, tab_len: u8) -> Self { pub fn new(line: &'a str, cursor_style: Style, tab_len: u8, mask: Option<char>) -> Self {
Self { Self {
line, line,
spans: vec![], spans: vec![],
@@ -106,6 +107,7 @@ impl<'a> LineHighlighter<'a> {
cursor_at_end: false, cursor_at_end: false,
cursor_style, cursor_style,
tab_len, tab_len,
mask,
} }
} }
@@ -136,7 +138,7 @@ impl<'a> LineHighlighter<'a> {
} }
} }
pub fn into_spans(self, mask: Option<char>) -> Spans<'a> { pub fn into_spans(self) -> Spans<'a> {
let Self { let Self {
line, line,
mut spans, mut spans,
@@ -145,6 +147,7 @@ impl<'a> LineHighlighter<'a> {
style_begin, style_begin,
cursor_style, cursor_style,
cursor_at_end, cursor_at_end,
mask,
} = self; } = self;
if boundaries.is_empty() { if boundaries.is_empty() {

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

@@ -1011,7 +1011,7 @@ impl<'a> TextArea<'a> {
} }
pub(crate) fn line_spans<'b>(&'b self, line: &'b str, row: usize, lnum_len: u8) -> Spans<'b> { pub(crate) fn line_spans<'b>(&'b self, line: &'b str, row: usize, lnum_len: u8) -> Spans<'b> {
let mut hl = LineHighlighter::new(line, self.cursor_style, self.tab_len); let mut hl = LineHighlighter::new(line, self.cursor_style, self.tab_len, self.mask);
if let Some(style) = self.line_number_style { if let Some(style) = self.line_number_style {
hl.line_number(row, lnum_len, style); hl.line_number(row, lnum_len, style);
@@ -1026,7 +1026,7 @@ impl<'a> TextArea<'a> {
hl.search(matches, self.search.style); hl.search(matches, self.search.style);
} }
hl.into_spans(self.mask) hl.into_spans()
} }
/// Build a tui-rs widget to render the current state of the textarea. The widget instance returned from this /// Build a tui-rs widget to render the current state of the textarea. The widget instance returned from this