Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: cargo fmt --check

- name: Lint
run: cargo clippy
run: cargo clippy --all-targets -- -D warnings

- name: Check
run: cargo check
Expand Down
2 changes: 1 addition & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Action {
pub fn handle_events() -> std::io::Result<Action> {
match crossterm::event::read()? {
crossterm::event::Event::Key(event) if event.kind == KeyEventKind::Press => {
return Ok(handle_key_event(event))
return Ok(handle_key_event(event));
}
_ => (),
}
Expand Down
25 changes: 12 additions & 13 deletions src/helpers/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ impl FromStr for RGBColor {

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.starts_with('#') {
return RGBColor::from_hex_str(s);
RGBColor::from_hex_str(s)
} else if s.contains(',') {
return RGBColor::from_rgb_str(s);
RGBColor::from_rgb_str(s)
} else {
return RGBColor::from_named_color(s);
RGBColor::from_named_color(s)
}
}
}
Expand All @@ -60,9 +60,9 @@ impl RGBColor {
let parts: Vec<&str> = s.split(',').map(|part| part.trim()).collect();
if parts.len() == 3 {
if let (Ok(r), Ok(g), Ok(b)) = (parts[0].parse(), parts[1].parse(), parts[2].parse()) {
return Ok(Self(r, g, b));
Ok(Self(r, g, b))
} else {
return Err(ParseErrorKind::InvalidFormat(s.to_string()));
Err(ParseErrorKind::InvalidFormat(s.to_string()))
}
} else {
Err(ParseErrorKind::InvalidFormat(s.to_string()))
Expand Down Expand Up @@ -90,9 +90,9 @@ impl std::ops::Mul<f32> for RGBColor {

fn mul(self, rhs: f32) -> Self::Output {
RGBColor(
(self.r() as f32 * rhs).min(255.0).max(0.0) as u8,
(self.g() as f32 * rhs).min(255.0).max(0.0) as u8,
(self.b() as f32 * rhs).min(255.0).max(0.0) as u8,
(self.r() as f32 * rhs).clamp(0.0, 255.0) as u8,
(self.g() as f32 * rhs).clamp(0.0, 255.0) as u8,
(self.b() as f32 * rhs).clamp(0.0, 255.0) as u8,
)
}
}
Expand All @@ -106,6 +106,7 @@ pub struct LinearGradient {
end: RGBColor,
}

#[allow(dead_code)]
pub struct LinearGradientSteps<'a> {
gradient: &'a LinearGradient,
current: usize,
Expand Down Expand Up @@ -143,7 +144,7 @@ impl LinearGradient {
/// Interpolate between two colors. The factor has to be between 0 and 1
pub fn interpolate(&self, factor: f32) -> RGBColor {
assert!(
factor >= 0.0 && factor <= 1.0,
(0.0..=1.0).contains(&factor),
"The factor value must be between 0 and 1"
);
let delta = self.delta();
Expand Down Expand Up @@ -225,10 +226,8 @@ mod tests {
assert_eq!(RGBColor::from_hex_str("#00FF00"), Ok(RGBColor(0, 255, 0)));
assert_eq!(RGBColor::from_hex_str("#0000FF"), Ok(RGBColor(0, 0, 255)));
assert!(
RGBColor::from_hex_str("#GGGGGG").is_err_and(|x| match x {
ParseErrorKind::InvalidHexValue(_) => true,
_ => false,
}),
RGBColor::from_hex_str("#GGGGGG")
.is_err_and(|x| { matches!(x, ParseErrorKind::InvalidHexValue(_)) }),
"Invalid Hex Format"
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn ansi_rgb(s: &char, color: colors::RGBColor) -> String {
color.r(),
color.g(),
color.b(),
s.to_string()
s
)
}

Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::io::Write;

use clap::Parser;
use crossterm::{
cursor,
style::{style, Stylize},
terminal, QueueableCommand,
QueueableCommand, cursor,
style::{Stylize, style},
terminal,
};

mod config;
Expand Down Expand Up @@ -40,7 +40,7 @@ fn run(config: &config::Config) -> std::io::Result<()> {
let (columns, rows) = terminal::size()?;

// Instantiate the matrix streams
let mut matrix = matrix::Matrix::new(rows, columns, &config);
let mut matrix = matrix::Matrix::new(rows, columns, config);

// Setup the terminal before running the application
setup(&mut stdout)?;
Expand All @@ -51,13 +51,13 @@ fn run(config: &config::Config) -> std::io::Result<()> {
// Render the Matrix-Rain on screen
loop {
// Render each stream
matrix.render(&config, &mut stdout)?;
matrix.render(config, &mut stdout)?;

// Handle events
if crossterm::event::poll(std::time::Duration::from_millis(1000 / config.fps as u64))? {
if let events::Action::Exit = events::handle_events()? {
break;
}
if crossterm::event::poll(std::time::Duration::from_millis(1000 / config.fps as u64))?
&& let events::Action::Exit = events::handle_events()?
{
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/matrix/entity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crossterm::QueueableCommand;
use crossterm::cursor;
use crossterm::style::Print;
use crossterm::QueueableCommand;

use crate::config;
use crate::helpers::{colors, utils};
Expand Down Expand Up @@ -84,7 +84,7 @@ impl Entity {
/// If the `frame_count` has exceeded `switch_interval` switch the [Entity] symbol to
/// another one from the character set.
fn switch_symbol(&mut self) {
if self.frame_count % self.switch_interval == 0 {
if self.frame_count.is_multiple_of(self.switch_interval) {
self.set_symbol();
}
self.frame_count += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/matrix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ mod entity;
mod stream;

use crossterm::{
QueueableCommand,
cursor::{self, MoveToNextLine},
style::Print,
QueueableCommand,
};
use stream::Stream;

Expand Down Expand Up @@ -106,7 +106,7 @@ impl Matrix {
}

// Return the instance
return ret;
ret
}

/// The setup function is called once before the draw loop starts
Expand Down
8 changes: 4 additions & 4 deletions src/matrix/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crossterm::QueueableCommand;
use crossterm::cursor;
use crossterm::style::Print;
use crossterm::QueueableCommand;

use crate::config;
use crate::helpers::{colors, direction::Direction, utils};
Expand Down Expand Up @@ -39,7 +39,7 @@ impl Stream {
count: 10,
};
stream.generate_entities(config);
return stream;
stream
}

/// Generate the entities that constitute the stream
Expand Down Expand Up @@ -77,8 +77,8 @@ impl Stream {

// Create the color gradient for the stream
let gradient = colors::LinearGradient::new(
colors::RGBColor::from(config.stream_color),
colors::RGBColor::from(config.stream_color) * config.stream_color_gradient_factor, // Overloaded Operator for Scalar Multiplication
config.stream_color,
config.stream_color * config.stream_color_gradient_factor, // Overloaded Operator for Scalar Multiplication
);

// Create the following entities
Expand Down
22 changes: 11 additions & 11 deletions src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Symbols {
/// Decimal Numbers: From 0 to 9
Decimal,
/// ASCII Symbols: Printable characters from 33 to 126 (0x21 to 0x7E). (from '!' to '~', including A-Z, a-z, 0-9 etc.)
ASCII,
Ascii,
/// Mathematical Symbols: Various mathematical characters like: ∐, ∑, ≠, →
Math,
/// Braille Symbols: Unicode range from 0x2840 to 0x2840 + 63 (64 Braille patterns) (e.g ⠇, ⠾, ⣿)
Expand All @@ -36,7 +36,7 @@ impl FromStr for Symbols {
"binary" | "bin" => Ok(Self::Binary),
"decimal" | "numbers" | "digits" => Ok(Self::Decimal),
"maths" | "math" | "mathematics" => Ok(Self::Math),
"ascii" | "text" | "english" => Ok(Self::ASCII),
"ascii" | "text" | "english" => Ok(Self::Ascii),
"braille" | "dots" => Ok(Self::Braille),
"emoji" | "cursed" => Ok(Self::Cursed),
x => Ok(Self::Custom(x.to_string())),
Expand All @@ -58,22 +58,22 @@ impl Symbols {
match self {
Self::Original => {
let r = utils::random_between(0x30a0, 0x30a0 + 96) as u32;
return std::char::from_u32(r).unwrap_or('0');
std::char::from_u32(r).unwrap_or('0')
}

Self::Binary => {
let r = utils::random_between(0, 2);
return if r == 0 { '0' } else { '1' };
if r == 0 { '0' } else { '1' }
}

Self::Decimal => {
let r = utils::random_between(0, 10);
return std::char::from_digit(r, 10).unwrap_or('0');
std::char::from_digit(r, 10).unwrap_or('0')
}

Self::ASCII => {
Self::Ascii => {
let r = utils::random_between(33, 127) as u32;
return std::char::from_u32(r).unwrap_or('0');
std::char::from_u32(r).unwrap_or('0')
}

Self::Math => {
Expand All @@ -85,22 +85,22 @@ impl Symbols {
2 => utils::random_between(0x2190, 0x21FF) as u32, // Arrows
_ => utils::random_between(0x27C0, 0x27EF) as u32, // Miscellaneous Mathematical Symbols
};
return std::char::from_u32(r).unwrap_or('0');
std::char::from_u32(r).unwrap_or('0')
}

Self::Braille => {
let r = utils::random_between(0x2840, 0x2840 + 63) as u32;
return std::char::from_u32(r).unwrap_or('0');
std::char::from_u32(r).unwrap_or('0')
}

Self::Cursed => {
let r = utils::random_between(0x1f300, 0x1f3f0) as u32;
return std::char::from_u32(r).unwrap_or('0');
std::char::from_u32(r).unwrap_or('0')
}

Self::Custom(s) => {
let r = utils::random_between(0, s.len());
return s.chars().nth(r).unwrap_or('0');
s.chars().nth(r).unwrap_or('0')
}
}
}
Expand Down