Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): update rust crate colorgrad to 0.7.0 #149

Merged
merged 2 commits into from
Aug 7, 2024
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lcat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default = ["clap"]
[dependencies]
bstr = "1.10.0"
clap = { version = "4.5.13", features = ["derive", "wrap_help"], optional = true }
colorgrad = { version = "0.6.2", default-features = false }
colorgrad = { version = "0.7.0", default-features = false, features = ["preset"] }
fastrand = "2.1.0"
unicode-segmentation = "1.11.0"
unicode-width = "0.1.13"
34 changes: 17 additions & 17 deletions lcat/src/rainbow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use unicode_width::UnicodeWidthChar;
use crate::ok::{Hsv, Lab, LinRgb, Rgb};

pub trait Grad {
fn color_at(&self, pos: f64) -> (u8, u8, u8);
fn color_at(&self, pos: f32) -> (u8, u8, u8);
}

impl Grad for colorgrad::Gradient {
fn color_at(&self, pos: f64) -> (u8, u8, u8) {
impl<T: colorgrad::Gradient> Grad for T {
fn color_at(&self, pos: f32) -> (u8, u8, u8) {
let [r, g, b, _] = self.at(pos).to_rgba8();
(r, g, b)
}
Expand All @@ -21,9 +21,9 @@ pub struct HsvGrad {}

impl Grad for HsvGrad {
#[allow(clippy::cast_possible_truncation)]
fn color_at(&self, pos: f64) -> (u8, u8, u8) {
fn color_at(&self, pos: f32) -> (u8, u8, u8) {
let Rgb { r, g, b } = Rgb::from(&LinRgb::from(&Lab::from(&Hsv {
h: pos as f32,
h: pos,
s: 1.0,
v: 1.0,
})));
Expand All @@ -34,9 +34,9 @@ impl Grad for HsvGrad {
pub struct Rainbow {
current_row: usize,
current_col: usize,
shift_col: f64,
shift_row: f64,
position: f64,
shift_col: f32,
shift_row: f32,
position: f32,
gradient: Box<dyn Grad>,
invert: bool,
}
Expand All @@ -45,9 +45,9 @@ impl Rainbow {
#[must_use]
pub fn new(
gradient: Box<dyn Grad>,
start: f64,
shift_col: f64,
shift_row: f64,
start: f32,
shift_col: f32,
shift_row: f32,
invert: bool,
) -> Self {
Self {
Expand All @@ -63,25 +63,25 @@ impl Rainbow {

pub fn step_row(&mut self, n_row: usize) {
self.current_row += n_row;
self.position += n_row as f64 * self.shift_row;
self.position += n_row as f32 * self.shift_row;
}

pub fn step_col(&mut self, n_col: usize) {
self.current_col += n_col;
self.position += n_col as f64 * self.shift_col;
self.position += n_col as f32 * self.shift_col;
}

pub fn reset_row(&mut self) {
self.position -= self.current_row as f64 * self.shift_row;
self.position -= self.current_row as f32 * self.shift_row;
self.current_row = 0;
}

pub fn reset_col(&mut self) {
self.position -= self.current_col as f64 * self.shift_col;
self.position -= self.current_col as f32 * self.shift_col;
self.current_col = 0;
}

fn get_position(&mut self) -> f64 {
fn get_position(&mut self) -> f32 {
if self.position < 0.0 || self.position > 1.0 {
self.position -= self.position.floor();
}
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
use super::*;

fn create_rb() -> Rainbow {
Rainbow::new(Box::new(colorgrad::rainbow()), 0.0, 0.1, 0.2, false)
Rainbow::new(Box::new(colorgrad::preset::rainbow()), 0.0, 0.1, 0.2, false)
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions lcat/src/rainbow_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ pub enum RainbowStyle {
pub struct RainbowCmd {
/// How many degrees to shift text color hue for every column
#[clap(short = 'C', long, default_value = "1.6")]
shift_col: f64,
shift_col: f32,

/// How many degrees to shift text color hue for every row
#[clap(short = 'R', long, default_value = "3.2")]
shift_row: f64,
shift_row: f32,

/// Don't randomize sign of col and row shift values
#[clap(short = 'n', long)]
shift_sign_no_random: bool,

/// Sets initial hue of text color in degress [default: random]
#[clap(short = 'H', long)]
hue: Option<f64>,
hue: Option<f32>,

/// Rainbow mode
#[clap(short, long, value_enum, default_value = "rainbow")]
Expand Down Expand Up @@ -58,11 +58,11 @@ impl From<RainbowCmd> for Rainbow {
-cmd.shift_row
} / 360.;

let start = cmd.hue.map_or_else(fastrand::f64, |hue| hue / 360.);
let start = cmd.hue.map_or_else(fastrand::f32, |hue| hue / 360.);

let grad: Box<dyn Grad> = match cmd.style {
RainbowStyle::Rainbow => Box::new(colorgrad::rainbow()),
RainbowStyle::Sinebow => Box::new(colorgrad::sinebow()),
RainbowStyle::Rainbow => Box::new(colorgrad::preset::rainbow()),
RainbowStyle::Sinebow => Box::new(colorgrad::preset::sinebow()),
RainbowStyle::OkHsv => Box::new(HsvGrad {}),
};

Expand Down