use std::io::Write;

use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttribute, SetForegroundColor};

pub fn queue_dim_text<W: Write>(writer: &mut W, text: &str) -> std::io::Result<()> {
  crossterm::queue!(
    writer,
    SetForegroundColor(Color::DarkGrey),
    SetAttribute(Attribute::Dim),
    Print(text),
    SetAttribute(Attribute::Reset),
    ResetColor
  )
}

pub fn queue_prompt_marker<W: Write>(writer: &mut W) -> std::io::Result<()> {
  crossterm::queue!(
    writer,
    SetForegroundColor(Color::Cyan),
    SetAttribute(Attribute::Bold),
    Print(">"),
    SetAttribute(Attribute::Reset),
    ResetColor
  )
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn dim_text_writes_text() {
    let mut buffer = Vec::new();

    queue_dim_text(&mut buffer, "(default)").unwrap();
    let output = String::from_utf8(buffer).unwrap();

    assert!(output.contains("(default)"));
  }

  #[test]
  fn prompt_marker_writes_marker() {
    let mut buffer = Vec::new();

    queue_prompt_marker(&mut buffer).unwrap();
    let output = String::from_utf8(buffer).unwrap();

    assert!(output.contains(">"));
  }
}
