use std::fmt::{Formatter, Result};
use r3bl_rs_utils_core::*;
use crate::*;
pub struct CrosstermDebugFormatRenderOp;
impl DebugFormatRenderOp for CrosstermDebugFormatRenderOp {
fn debug_format(&self, this: &RenderOp, f: &mut Formatter<'_>) -> Result {
write!(
f,
"{}",
match this {
RenderOp::Noop => "Noop".into(),
RenderOp::EnterRawMode => "EnterRawMode".into(),
RenderOp::ExitRawMode => "ExitRawMode".into(),
RenderOp::MoveCursorPositionAbs(pos) => format!("MoveCursorPositionAbs({:?})", pos),
RenderOp::MoveCursorPositionRelTo(box_origin_pos, content_rel_pos) => format!(
"MoveCursorPositionRelTo({:?}, {:?})",
box_origin_pos, content_rel_pos
),
RenderOp::ClearScreen => "ClearScreen".into(),
RenderOp::SetFgColor(fg_color) => format!("SetFgColor({:?})", fg_color),
RenderOp::SetBgColor(bg_color) => format!("SetBgColor({:?})", bg_color),
RenderOp::ResetColor => "ResetColor".into(),
RenderOp::ApplyColors(maybe_style) => match maybe_style {
Some(style) => format!("ApplyColors({:?})", style),
None => "ApplyColors(None)".into(),
},
RenderOp::PrintTextWithAttributes(text, maybe_style) => {
match ANSIText::try_strip_ansi(text) {
Some(plain_text) => {
match maybe_style {
Some(style) => format!("PrintTextWithAttributes(\"{}\", {:?})", plain_text, style),
None => format!("PrintTextWithAttributes(\"{}\", None)", plain_text),
}
}
None => {
match maybe_style {
Some(style) => {
format!("PrintTextWithAttributes({} bytes, {:?})", text.len(), style)
}
None => format!("PrintTextWithAttributes({} bytes, None)", text.len()),
}
}
}
}
RenderOp::CursorShow => "CursorShow".into(),
RenderOp::CursorHide => "CursorHide".into(),
RenderOp::RequestShowCaretAtPositionAbs(pos) => format!("ShowCursorAtPosition({:?})", pos),
RenderOp::RequestShowCaretAtPositionRelTo(box_origin_pos, content_rel_pos) => format!(
"ShowCursorAtPosition({:?}, {:?})",
box_origin_pos, content_rel_pos
),
}
)
}
}