use std::io::{self, Write};
pub struct DisplayRenderer;
impl DisplayRenderer {
pub fn render(prompt: &str, content: &str, cursor_pos: usize) {
let safe_cursor_pos = cursor_pos.min(content.len());
print!("\r\x1B[K{}{}", prompt, content);
print!("\x1B[{}G", prompt.len() + safe_cursor_pos + 1);
let _ = io::stdout().flush();
}
pub fn bell() {
print!("\x07");
let _ = io::stdout().flush();
}
pub fn boundary_marker() {
print!("\x1B[31m|\x1B[0m\x1B[1D \x1B[1D");
let _ = io::stdout().flush();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_render_does_not_panic() {
DisplayRenderer::render(">", "Hello", 3);
}
#[test]
fn test_bell_does_not_panic() {
DisplayRenderer::bell();
}
#[test]
fn test_boundary_marker_does_not_panic() {
DisplayRenderer::boundary_marker();
}
}