From 63a864061b4a81c536d9f0c6eec66c986792c74f Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 16 Oct 2024 20:43:48 +0200 Subject: [PATCH] updated structure --- src/utils.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/utils.rs diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..f0ec35a --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,28 @@ +use std::io::{stdout, Write}; + +use crate::Component; + +pub fn render_to_frame(width: usize, frame: &mut Vec, component: &mut Component) { + for (i, line) in (component.render)(component).split('\n').enumerate() { + if (component.y + i) < frame.len() { + let frame_line = frame.get_mut(component.y + i).unwrap(); + // *frame_line = (&line[..line.len().saturating_sub(width)]).to_string(); + *frame_line = line.to_string(); + } + } +} + +pub fn clear() { + print!("\x1b[2J\x1b[0;0H"); + stdout().flush().unwrap(); +} + +pub fn hide_cursor() { + print!("\x1b[?25l"); + stdout().flush().unwrap(); +} + +pub fn show_cursor() { + print!("\x1b[?25H"); + stdout().flush().unwrap(); +}