From 7df01aa56feb5f5d447a77728e4c2f5c26790d4a Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Tue, 30 May 2023 12:57:42 -0500 Subject: [PATCH] edited: use cleanup --- src/cells.rs | 18 +++++++++++------- src/graphics/map.rs | 26 ++++++++++++++++---------- src/graphics/point.rs | 1 + 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/cells.rs b/src/cells.rs index 366dddc..8ca6808 100644 --- a/src/cells.rs +++ b/src/cells.rs @@ -1,5 +1,9 @@ use crate::{Map, Mask, Point}; -use crossterm::style::{Attribute, Color}; +use crossterm::style::{ + Attribute, Attributes, + Color::{Black, Green, Grey}, + Colors, +}; use ndarray::Array2; use rand::{thread_rng, Rng}; use std::{cell::Cell, ops::Deref}; @@ -88,16 +92,16 @@ impl Map> for World { ('●', '◌') } - fn fg_colors(&self) -> (Color, Color) { - (Color::Green, Color::Grey) + fn on_colors(&self) -> Colors { + Colors::new(Green, Black) } - fn bg_colors(&self) -> (Color, Color) { - (Color::Black, Color::Black) + fn off_colors(&self) -> Colors { + Colors::new(Grey, Black) } - fn styles(&self) -> (Attribute, Attribute) { - (Attribute::Bold, Attribute::Reset) + fn styles(&self) -> (Attributes, Attributes) { + (Attribute::Bold.into(), Attribute::Reset.into()) } fn try_point(&self, point: Point) -> bool { diff --git a/src/graphics/map.rs b/src/graphics/map.rs index 6748e15..3491ceb 100644 --- a/src/graphics/map.rs +++ b/src/graphics/map.rs @@ -1,5 +1,9 @@ use crate::Point; -use crossterm::style::{Attribute, Color}; +use crossterm::style::{ + Attribute, Attributes, + Color::{Black, Grey, White}, + Colors, +}; use ndarray::Array2; use std::ops::Deref; @@ -9,9 +13,9 @@ pub trait Map { fn x_size(&self) -> usize; fn y_size(&self) -> usize; fn characters(&self) -> (char, char); - fn fg_colors(&self) -> (Color, Color); - fn bg_colors(&self) -> (Color, Color); - fn styles(&self) -> (Attribute, Attribute); + fn on_colors(&self) -> Colors; + fn off_colors(&self) -> Colors; + fn styles(&self) -> (Attributes, Attributes); fn update(&mut self); } @@ -55,16 +59,18 @@ impl Map for Mask { ('■', '□') } - fn fg_colors(&self) -> (Color, Color) { - (Color::White, Color::Grey) + fn on_colors(&self) -> Colors { + Colors::new(White, Black) } - fn bg_colors(&self) -> (Color, Color) { - (Color::Black, Color::Black) + fn off_colors(&self) -> Colors { + Colors::new(Grey, Black) } - fn styles(&self) -> (Attribute, Attribute) { - (Attribute::Bold, Attribute::Reset) + fn styles(&self) -> (Attributes, Attributes) { + let on = Attributes::from(Attribute::Bold); + let off = Attributes::from(Attribute::Reset); + (on, off) } fn update(&mut self) {} diff --git a/src/graphics/point.rs b/src/graphics/point.rs index 3af27b3..0acc247 100644 --- a/src/graphics/point.rs +++ b/src/graphics/point.rs @@ -2,6 +2,7 @@ use crossterm::style::{Attribute, Color}; use eyre::Result; use std::ops::{Add, Div, Mul, Sub}; +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Pixel { pub location: Point, pub value: char, -- 2.45.2