1use std::io::Write;
2
3use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttribute, SetForegroundColor};
4
5pub fn queue_dim_text<W: Write>(writer: &mut W, text: &str) -> std::io::Result<()> {
6 crossterm::queue!(
7 writer,
8 SetForegroundColor(Color::DarkGrey),
9 SetAttribute(Attribute::Dim),
10 Print(text),
11 SetAttribute(Attribute::Reset),
12 ResetColor
13 )
14}
15
16pub fn queue_prompt_marker<W: Write>(writer: &mut W) -> std::io::Result<()> {
17 crossterm::queue!(
18 writer,
19 SetForegroundColor(Color::Cyan),
20 SetAttribute(Attribute::Bold),
21 Print(">"),
22 SetAttribute(Attribute::Reset),
23 ResetColor
24 )
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 fn dim_text_writes_text() {
33 let mut buffer = Vec::new();
34
35 queue_dim_text(&mut buffer, "(default)").unwrap();
36 let output = String::from_utf8(buffer).unwrap();
37
38 assert!(output.contains("(default)"));
39 }
40
41 #[test]
42 fn prompt_marker_writes_marker() {
43 let mut buffer = Vec::new();
44
45 queue_prompt_marker(&mut buffer).unwrap();
46 let output = String::from_utf8(buffer).unwrap();
47
48 assert!(output.contains(">"));
49 }
50}