1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 14:26:17 +03:00
Этот коммит содержится в:
rhysd
2022-06-10 00:07:35 +09:00
родитель d847061951
Коммит bac44ae105

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

@@ -13,6 +13,7 @@ pub struct TextArea<'a> {
cursor: (usize, usize), // 0-base
tab: &'a str,
history: EditHistory,
cursor_line_style: Style,
}
impl<'a> Default for TextArea<'a> {
@@ -24,6 +25,7 @@ impl<'a> Default for TextArea<'a> {
cursor: (0, 0),
tab: " ",
history: EditHistory::new(50),
cursor_line_style: Style::default().add_modifier(Modifier::UNDERLINED),
}
}
}
@@ -194,9 +196,9 @@ impl<'a> TextArea<'a> {
.unwrap_or((l.len() - 1, ' '));
let j = i + c.len_utf8();
lines.push(Spans::from(vec![
Span::from(&l[..i]),
Span::styled(&l[..i], self.cursor_line_style),
Span::styled(&l[i..j], Style::default().add_modifier(Modifier::REVERSED)),
Span::from(&l[j..]),
Span::styled(&l[j..], self.cursor_line_style),
]));
} else {
lines.push(Spans::from(l.as_str()));
@@ -234,6 +236,10 @@ impl<'a> TextArea<'a> {
self.history = EditHistory::new(max);
}
pub fn set_cursor_line_style(&mut self, style: Style) {
self.cursor_line_style = style;
}
pub fn lines(&'a self) -> impl Iterator<Item = &'a str> {
self.lines.iter().map(|l| &l[..l.len() - 1]) // Trim last whitespace
}