Skip to content

Commit

Permalink
Fix MaskingHighlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Aug 25, 2024
1 parent c9db271 commit 64051e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/read_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ impl Highlighter for MaskingHighlighter {
) -> impl Iterator<Item = impl 'l + rustyline::highlight::StyledBlock> {
use unicode_width::UnicodeWidthStr;
if self.masking {
[(rustyline::highlight::AnsiStyle::default(), " ")]
.repeat(line.width())
.into_iter()
vec![(
rustyline::highlight::AnsiStyle::default(),
" ".repeat(line.width()),
)]
.into_iter()
} else {
vec![(rustyline::highlight::AnsiStyle::default(), line)].into_iter()
vec![(rustyline::highlight::AnsiStyle::default(), line.to_owned())].into_iter()
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ impl StyledBlock for (AnsiStyle, &str) {
&self.0
}
}
#[cfg(all(feature = "split-highlight", not(feature = "ansi-str")))]
impl StyledBlock for (AnsiStyle, String) {
type Style = AnsiStyle;

fn text(&self) -> &str {
&self.1
}

fn style(&self) -> &Self::Style {
&self.0
}
}

/// Syntax highlighter with [ANSI color](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters).
/// Rustyline will try to handle escape sequence for ANSI color on windows
Expand Down

0 comments on commit 64051e1

Please sign in to comment.