Skip to content

Add support for gradients#277

Open
jgrund wants to merge 1 commit intoconsole-rs:mainfrom
jgrund:jgrund/gradient
Open

Add support for gradients#277
jgrund wants to merge 1 commit intoconsole-rs:mainfrom
jgrund:jgrund/gradient

Conversation

@jgrund
Copy link
Copy Markdown

@jgrund jgrund commented Dec 5, 2025

This PR adds support for fg / bg gradients. It tries to utilize existing structure and expand on it.

Screenshot from example:

image

@jgrund jgrund force-pushed the jgrund/gradient branch 6 times, most recently from cba9042 to 4d0ebeb Compare December 7, 2025 18:50
@jgrund jgrund marked this pull request as ready for review December 7, 2025 18:52
@jgrund
Copy link
Copy Markdown
Author

jgrund commented Dec 11, 2025

Hi @djc,

Can I get some feedback on this?

@djc
Copy link
Copy Markdown
Member

djc commented Dec 11, 2025

It's on my list but it's not very high priority right now (unless your org can fund the work).

@jgrund
Copy link
Copy Markdown
Author

jgrund commented Dec 12, 2025

Ok, no rush. When you get a chance please kick off workflows so I can make sure tests are passing.

@djc
Copy link
Copy Markdown
Member

djc commented Dec 12, 2025

Changed the settings to allow workflows to run without my approval.

@jgrund jgrund force-pushed the jgrund/gradient branch 2 times, most recently from 852a47d to 9d7ed15 Compare December 16, 2025 15:18
Signed-off-by: Joe Grund <grundjoseph@gmail.com>
@jgrund jgrund force-pushed the jgrund/gradient branch from 9d7ed15 to aeb1d5f Compare April 3, 2026 19:29
}

/// Parses a hex color string like "#ff0000" into a (r, g, b) tuple.
fn parse_hex_color(s: &str) -> Option<(u8, u8, u8)> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd like a separate prefix commit (or PR) that extracts this.

}

#[inline]
const fn get_fg_gradient(&self) -> Option<FgGradient> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prefer to avoid get_() prefixes per the API guidelines.

self.fg(Color::Black)
}
#[inline]
pub const fn black_end(self) -> Self {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer not to have separate methods for each color _end().


#[inline]
const fn get_fg_gradient(&self) -> Option<FgGradient> {
let Some(start) = self.fg else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: suggest spelling this as

match (self.fg, self.fg_end) {
     (Some(start), Some(end)) => Some(FgGradient { start, end }),
     _ => None,
}

impl_fmt!(UpperExp);
impl_fmt!(UpperHex);

struct Gradient {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding a little more structure here, along the lines of:

struct Gradients {
     fg: Gradient,
     bg: Gradient,
}

impl Gradients {
      // attach `fmt_gradient()` here, or turn it into a `Display` impl for `Gradients`?
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants