rustyline/prompt.rs
1/// Provide two versions of the prompt:
2/// - the `raw` version used when `stdout` is not a tty, or when the terminal is
3/// not supported or in `NO_COLOR` mode
4/// - the `styled` version
5pub trait Prompt {
6 /// No style, no ANSI escape sequence
7 fn raw(&self) -> &str;
8 /// With style(s), ANSI escape sequences
9 ///
10 /// Currently, the styled version *must* have the same display width as
11 /// the raw version.
12 ///
13 /// By default, returns the raw string.
14 fn styled(&self) -> &str {
15 self.raw()
16 }
17}
18
19impl Prompt for str {
20 fn raw(&self) -> &str {
21 self
22 }
23}
24impl Prompt for String {
25 fn raw(&self) -> &str {
26 self.as_str()
27 }
28}
29impl<Raw: AsRef<str>, Styled: AsRef<str>> Prompt for (Raw, Styled) {
30 fn raw(&self) -> &str {
31 self.0.as_ref()
32 }
33
34 fn styled(&self) -> &str {
35 self.1.as_ref()
36 }
37}