add, function print err
This commit is contained in:
1 parent
d0c051c7b1
commit
6534ed18b4
1 file changed
+21
-36
+21
-36
@@ -6,24 +6,10 @@ use std::{
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor::MoveTo,
|
cursor::MoveTo,
|
||||||
execute, queue,
|
execute, queue,
|
||||||
style::{Color, Print, ResetColor, SetBackgroundColor},
|
style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor},
|
||||||
terminal::{Clear, ClearType},
|
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 {
|
pub struct Render {
|
||||||
out: Stdout,
|
out: Stdout,
|
||||||
rez: (usize, usize),
|
rez: (usize, usize),
|
||||||
@@ -38,44 +24,43 @@ impl Render {
|
|||||||
pos: (0.0, 0.0),
|
pos: (0.0, 0.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_rez(&mut self, a: usize, b: usize) {
|
||||||
|
self.rez = (a, b);
|
||||||
|
}
|
||||||
|
pub fn set_pos(&mut self, a: f32, b: f32) {
|
||||||
|
self.pos = (a, b);
|
||||||
|
}
|
||||||
pub fn init(&mut self) {
|
pub fn init(&mut self) {
|
||||||
execute!(self.out, Clear(ClearType::All), MoveTo(0, 0));
|
execute!(self.out, Clear(ClearType::All), MoveTo(0, 0));
|
||||||
}
|
}
|
||||||
pub fn set_rez(&self, a: usize, b: usize) -> Self {
|
pub fn print(&mut self, out_str: &str) {
|
||||||
Render {
|
execute!(self.out, Print(out_str));
|
||||||
out: stdout(),
|
|
||||||
rez: (a, b),
|
|
||||||
pos: self.pos,
|
|
||||||
}
|
}
|
||||||
|
pub fn print_err(&mut self, out_err: &str) {
|
||||||
|
execute!(
|
||||||
|
self.out,
|
||||||
|
SetForegroundColor(Color::Red),
|
||||||
|
Print(out_err),
|
||||||
|
Print("\n"),
|
||||||
|
ResetColor
|
||||||
|
);
|
||||||
}
|
}
|
||||||
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) {
|
pub fn frame(&mut self) {
|
||||||
for _i in 0..self.rez.0 {
|
for _i in 0..self.rez.0 {
|
||||||
for _j in 0..self.rez.1 {
|
for _j in 0..self.rez.1 {
|
||||||
queue!(
|
queue!(
|
||||||
self.out,
|
self.out,
|
||||||
SetBackgroundColor(Color::Rgb {
|
SetBackgroundColor(Color::Rgb {
|
||||||
r: 200,
|
r: 100,
|
||||||
g: 30,
|
g: 30,
|
||||||
b: 170
|
b: 90
|
||||||
}),
|
}),
|
||||||
Print("0"),
|
Print(" "),
|
||||||
ResetColor
|
ResetColor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
queue!(self.out, Print("\r\n"));
|
queue!(self.out, Print("\r\n"));
|
||||||
}
|
}
|
||||||
self.out.flush().unwrap();
|
self.out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user