-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
password mode #29
password mode #29
Conversation
Could this possibly use text::Masked introduced in ratatui/ratatui#168? |
I had not seen that, let me check it out |
the most obvious thing is that its only ratatui. My vote would be to drop support of tui since this will increasingly be an issue |
Ah yeah. Makes sense. |
@joshka - well its a simple change to make it use Masked (less code), but then, as I said, it now gets complicated. I either have 2 implementations, or I make it a 'feature' that depends on ratatui. Neither seems a good choice. I will post an issue about dropping tui support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest adding unit tests, doc comments, and considering how this interacts with the other features. Does this break line numbering, placeholders, ...?
// big enough for the largest line I can imagine | ||
const STARS: &str = "******************************\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not a good idea as things can be longer than you'd imagine ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its per line. And thats 180 chars. I could not imagine a line longer than that, the UI still works in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line numbers and placeholder works fine (I admit i did not test it till just now , which is dumb since i wrote the placeholder feature)
lines.push(self.0.line_spans(line.as_str(), top_row + i, lnum_len)); | ||
let mut thisline = line.as_str(); | ||
if self.0.password_mode { | ||
let count = thisline.chars().count(); | ||
thisline = &STARS[0..cmp::min(count, STARSLEN)]; | ||
} | ||
lines.push(self.0.line_spans(thisline, top_row + i, lnum_len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider perhaps:
let line = if self.0.password_mode {
"*".repeat(line.len())
} else {
line
};
Note: this probably should do unicode width()
rather than len()
, but I don't see that in the library already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I tried that. But the returned Text object is marshalling &str
s. So the strings must persist after the function returns. FYI - see here. https://stackoverflow.com/questions/77269247/trying-to-subsitiute-text-of-variable-size
WIll redo as a conditional feature depending on ratatui |
A new feature, password mode. This masks the input with *****. Sample added