Skip to content

Commit

Permalink
pass mask character on creating LineHighlighter instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 21, 2023
1 parent 4bdf55a commit 784ad65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ pub struct LineHighlighter<'a> {
cursor_at_end: bool,
cursor_style: Style,
tab_len: u8,
mask: Option<char>,
}

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 {
line,
spans: vec![],
Expand All @@ -106,6 +107,7 @@ impl<'a> LineHighlighter<'a> {
cursor_at_end: false,
cursor_style,
tab_len,
mask,
}
}

Expand Down Expand Up @@ -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 {
line,
mut spans,
Expand All @@ -145,6 +147,7 @@ impl<'a> LineHighlighter<'a> {
style_begin,
cursor_style,
cursor_at_end,
mask,
} = self;

if boundaries.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions src/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
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 {
hl.line_number(row, lnum_len, style);
Expand All @@ -1026,7 +1026,7 @@ impl<'a> TextArea<'a> {
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
Expand Down

0 comments on commit 784ad65

Please sign in to comment.