use crate::Value;
use crate::modules::repl::render::short_type_name;
use std::io::{Write, Stdout};
use crossterm::style::{SetForegroundColor, ResetColor, Color};
use crossterm::queue;

pub fn print_pretty_value(out: &mut Stdout, val: &Value) {
    queue!(out, crossterm::cursor::MoveToColumn(0)).ok();
    queue!(out, SetForegroundColor(Color::DarkRed)).ok();
    write!(out, "{}", crate::value_to_string(val)).ok();
    queue!(out, ResetColor).ok();
    let tname = short_type_name(val);
    queue!(out, SetForegroundColor(Color::DarkMagenta)).ok();
    write!(out, " ({})", tname).ok();
    queue!(out, ResetColor).ok();
    writeln!(out).ok();
    out.flush().ok();
}

pub fn print_colored_message(out: &mut Stdout, msg: &str, color: Color) {
    queue!(out, SetForegroundColor(color)).ok();
    write!(out, "{}", msg).ok();
    queue!(out, ResetColor).ok();
    writeln!(out).ok();
    out.flush().ok();
}
