Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7067e3985c |
No files matched your search
@@ -1,71 +0,0 @@
|
|||||||
use std::{
|
|
||||||
error,
|
|
||||||
io::{Stdout, Write, stdout},
|
|
||||||
process::Output,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crossterm::{
|
|
||||||
cursor::MoveTo,
|
|
||||||
execute, queue,
|
|
||||||
style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor},
|
|
||||||
terminal::{Clear, ClearType},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Render {
|
|
||||||
out: Stdout,
|
|
||||||
rez: (usize, usize),
|
|
||||||
pos: (usize, usize),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Render {
|
|
||||||
out: stdout(),
|
|
||||||
rez: (10, 10),
|
|
||||||
pos: (0, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn set_rez(&mut self, a: usize, b: usize) -> Result<(), String> {
|
|
||||||
if a == 0 || b == 0 {
|
|
||||||
return Err("Invalid resolution\n".to_string());
|
|
||||||
}
|
|
||||||
self.rez = (a, b);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub fn set_pos(&mut self, a: usize, b: usize) {
|
|
||||||
self.pos = (a, b);
|
|
||||||
}
|
|
||||||
pub fn init(&mut self) {
|
|
||||||
execute!(self.out, Clear(ClearType::All), MoveTo(0, 0));
|
|
||||||
}
|
|
||||||
pub fn print(&mut self, out_str: &str) {
|
|
||||||
execute!(self.out, Print(out_str));
|
|
||||||
}
|
|
||||||
pub fn print_err(&mut self, out_err: &str) {
|
|
||||||
execute!(
|
|
||||||
self.out,
|
|
||||||
SetForegroundColor(Color::Red),
|
|
||||||
Print(out_err),
|
|
||||||
Print("\n"),
|
|
||||||
ResetColor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
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: 100,
|
|
||||||
g: 30,
|
|
||||||
b: 90
|
|
||||||
}),
|
|
||||||
Print(" "),
|
|
||||||
ResetColor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
queue!(self.out, Print("\r\n"));
|
|
||||||
}
|
|
||||||
self.out.flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, dev!");
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user