add base fn for render: new, init, set_rez, set_pos, frame, but this have more code
This commit is contained in:
1 parent
b6f74c160c
commit
d0c051c7b1
1 file changed
+81
@@ -0,0 +1,81 @@
|
|||||||
|
use std::{
|
||||||
|
io::{Stdout, Write, stdout},
|
||||||
|
process::Output,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crossterm::{
|
||||||
|
cursor::MoveTo,
|
||||||
|
execute, queue,
|
||||||
|
style::{Color, Print, ResetColor, SetBackgroundColor},
|
||||||
|
terminal::{Clear, ClearType},
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
use std::io::{Write, stdout};
|
||||||
|
pub fn render_init() {
|
||||||
|
let mut out = stdout();
|
||||||
|
queue!(out, Clear(ClearType::All), MoveTo(0, 0));
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render_str(a: &str) {
|
||||||
|
let mut out = stdout();
|
||||||
|
execute!(out, Print(a));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub struct Render {
|
||||||
|
out: Stdout,
|
||||||
|
rez: (usize, usize),
|
||||||
|
pos: (f32, f32),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Render {
|
||||||
|
out: stdout(),
|
||||||
|
rez: (10, 10),
|
||||||
|
pos: (0.0, 0.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn init(&mut self) {
|
||||||
|
execute!(self.out, Clear(ClearType::All), MoveTo(0, 0));
|
||||||
|
}
|
||||||
|
pub fn set_rez(&self, a: usize, b: usize) -> Self {
|
||||||
|
Render {
|
||||||
|
out: stdout(),
|
||||||
|
rez: (a, b),
|
||||||
|
pos: self.pos,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn set_pos(&self, a: f32, b: f32) -> Self {
|
||||||
|
Render {
|
||||||
|
out: stdout(),
|
||||||
|
rez: self.rez,
|
||||||
|
pos: (a, b),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn r_str(&mut self, output_str: &str) {
|
||||||
|
execute!(self.out, Print(output_str));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn frame(&mut self) {
|
||||||
|
for _i in 0..self.rez.0 {
|
||||||
|
for _j in 0..self.rez.1 {
|
||||||
|
queue!(
|
||||||
|
self.out,
|
||||||
|
SetBackgroundColor(Color::Rgb {
|
||||||
|
r: 200,
|
||||||
|
g: 30,
|
||||||
|
b: 170
|
||||||
|
}),
|
||||||
|
Print("0"),
|
||||||
|
ResetColor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
queue!(self.out, Print("\r\n"));
|
||||||
|
}
|
||||||
|
self.out.flush().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user