minicrossterm/examples/program_examples/snake/src/variables.rs
Timon Post b717d306c3 Putted Screen behind an Option. Now when you call the functions: color, cursor, terminal, input you won't need to provide a Screen anymore.
When you want to work with the 'alternate screen' you can call the following functions: terminal::from_screen etc. Which will give you an instance to the back of the module you are calling it in.

So instead of:

let color = color(Screen::default());
let cursor = cursor(Screen::default());
let input = input(Screen::default());
let terminal = terminal(Screen::default());

You can do:

let color = color();
let cursor = cursor();
let input = input();
let terminal = terminal();
2018-11-21 07:54:16 -08:00

61 lines
1.1 KiB
Rust

extern crate crossterm;
use self::crossterm::terminal::{self, ClearType};
use self::crossterm::style::{Color, StyledObject, ObjectStyle, style };
use self::crossterm::cursor;
use self::crossterm::Screen;
use std::fmt::Debug;
use std::fmt;
#[derive(Copy, Clone,Debug)]
pub enum Direction
{
Up = 0,
Down = 1,
Left = 2,
Right = 3
}
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
pub struct Position
{
pub x: usize,
pub y: usize
}
impl Position
{
pub fn new(x: usize, y: usize) -> Position
{
Position { x, y }
}
pub fn draw(&self, val: &str, screen: &Screen)
{
cursor::from_screen(screen).goto(self.x as u16, self.y as u16);
style(val).with(Color::Red).paint(&screen);
screen.stdout.flush();
}
pub fn remove(&self, screen: &Screen)
{
cursor::from_screen(screen).goto(self.x as u16, self.y as u16);
terminal::from_screen(&screen).write(" ");
}
}
#[derive(Copy, Clone)]
pub struct Size
{
pub width: usize,
pub height: usize
}
impl Size
{
pub fn new(width: usize, height: usize) -> Size
{
Size {width,height}
}
}