Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@chshersh
Copy link
Collaborator

@chshersh chshersh commented Feb 2, 2025

Closes #2

Added a function to parse the RGB constructor from a hex color string.

A few notes:

  1. The function returns option instead of a more detailed error. I'm not a fan of exceptions and since there could be too many possibilities to fail, I decided that a detailed error message is not needed.
  2. I implemented all hex parsing functions locally inside the new function to avoid polluting a global namespace, since I'm not sure they're relevant anywhere else.

Happy to make any changes!


Checked in utop that it works:

image

Copy link
Owner

@qexat qexat left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

I have nothing to add, great job as usual ♡

@qexat qexat merged commit a420493 into qexat:experimental/token-term Feb 2, 2025
@qexat qexat linked an issue Feb 3, 2025 that may be closed by this pull request
@chshersh chshersh deleted the chshersh/hex branch February 3, 2025 07:11
qexat added a commit that referenced this pull request Feb 3, 2025
# 0.2.0

## Features

- Add color functions `luminance` and `best_for_contrast`. (by @chshersh in #5)
- Add styling functions `fg`, `bg`, `bold`, `dim`, `italic`, `underlined`. (by @chshersh in #6)
- Add styling composition with `&`. (by @chshersh in #6)
- Add function `make_rgb_hex` to parse hexadecimal codes into RGB colors. (by @chshersh in #7)

## Breaking Changes

- `Color.t` and `Color.Ground.t` are now polymorphic variants. (by @chshersh in #5)

## Removed

- `Util.parenthesize_if` which is deemed unuseful and is kind of a duplicate of `Tree.parenthesize_if` in `Formatting`.
qexat added a commit to qexat/opam-repository that referenced this pull request Feb 3, 2025
CHANGES:

## Features

- Add color functions `luminance` and `best_for_contrast`. (by @chshersh in qexat/ansifmt#5)
- Add styling functions `fg`, `bg`, `bold`, `dim`, `italic`, `underlined`. (by @chshersh in qexat/ansifmt#6)
- Add styling composition with `&`. (by @chshersh in qexat/ansifmt#6)
- Add function `make_rgb_hex` to parse hexadecimal codes into RGB colors. (by @chshersh in qexat/ansifmt#7)

## Breaking Changes

- `Color.t` and `Color.Ground.t` are now polymorphic variants. (by @chshersh in qexat/ansifmt#5)

## Removed

- `Util.parenthesize_if` which is deemed unuseful and is kind of a duplicate of `Tree.parenthesize_if` in `Formatting`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse RGB color from hex code

2 participants