forked from wezterm/wezterm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
color: refactor docs, add a couple more methods
Moved the gradient function into the color module, but kept an alias under the old name. Gradients now return color objects. Converting colors to string now uses rgba format when alpha is not 100%.
- Loading branch information
Showing
30 changed files
with
338 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## `color:adjust_hue_fixed(degrees)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Adjust the hue angle by the specified number of degrees. | ||
|
||
180 degrees gives the complementary color. | ||
Three colors separated by 120 degrees form the triad. | ||
Four colors separated by 90 degrees form the square. | ||
|
||
See also [color:adjust_hue_fixed_ryb()](adjust_hue_fixed_ryb.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## `color:adjust_hue_fixed_ryb(degrees)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Adjust the hue angle by the specified number of degrees. | ||
|
||
This method uses the [RYB color | ||
model](https://en.wikipedia.org/wiki/RYB_color_model), which more | ||
closely matches how artists think of mixing colors and which is | ||
sometimes referred to as the "artist's color wheel". | ||
|
||
180 degrees gives the complementary color. | ||
Three colors separated by 120 degrees form the triad. | ||
Four colors separated by 90 degrees form the square. | ||
|
||
See also [color:adjust_hue_fixed()](adjust_hue_fixed.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## `color:complement()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Returns the complement of the color. The complement is computed | ||
by converting to HSL, rotating by 180 degrees and converting back | ||
to RGBA. | ||
|
||
See also: [color:complement_ryb()](complement_ryb.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## `color:complement_ryb()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Returns the complement of the color using the [RYB color | ||
model](https://en.wikipedia.org/wiki/RYB_color_model), which more closely | ||
matches how artists think of mixing colors. | ||
|
||
The complement is computed by converting to HSL, converting the | ||
hue angle to the equivalent RYB angle, rotating by 180 degrees and | ||
and then converting back to RGBA. | ||
|
||
See also: [color:complement()](complement.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
### `color:contrast_ratio(color)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Computes the contrast ratio between the two colors. | ||
|
||
```lua | ||
> wezterm.color.parse("red"):contrast_ratio(wezterm.color.parse("yellow")) | ||
1 | ||
> wezterm.color.parse("red"):contrast_ratio(wezterm.color.parse("navy")) | ||
1.8273614734023298 | ||
``` | ||
|
||
The contrast ratio is computed by first converting to HSL, taking the | ||
L components, and diving the lighter one by the darker one. | ||
|
||
A contrast ratio of 1 means no contrast. | ||
|
||
The maximum possible contrast ratio is 21: | ||
|
||
```lua | ||
> wezterm.color.parse("black"):contrast_ratio(wezterm.color.parse("white")) | ||
21 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## `color:darken(factor)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Scales the color towards the minimum lightness by the provided | ||
factor, which should be in the range `0.0` through `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## `color:darken_fixed(amount)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Decrease the lightness by amount, a value ranging from `0.0` to `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
### `color:delta_e(color)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Computes the CIEDE2000 DeltaE value representing the difference | ||
between the two colors. | ||
|
||
A value: | ||
|
||
* <= 1.0: difference is not perceptible by the human eye | ||
* 1-2: difference is perceptible through close observation | ||
* 2-10: difference is perceptible at a glance | ||
* 11-49: Colors are more similar than the opposite | ||
* 50-99: Colors are more opposite than similar | ||
* 100: Colors are exactly the opposite | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## `color:desaturate(factor)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Scales the color towards the minimum saturation by the provided factor, which | ||
should be in the range `0.0` through `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## `color:desaturate_fixed(amount)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Decrease the saturation by amount, a value ranging from `0.0` to `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## `color:hsla()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Converts the color to the HSL colorspace and returns those values + | ||
alpha: | ||
|
||
```lua | ||
local h, s, l, a = color:hsla() | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `Color` object | ||
|
||
Color objects can be created by calling | ||
[wezterm.color.parse()](../wezterm.color/parse.md) and may also be | ||
returned by various wezterm functions and methods. | ||
|
||
They represent a color that is internally stored in SRGBA. | ||
|
||
Color objects have a number of methods that are helpful to | ||
compare and compute other color values, which is helpful | ||
when programmatically generating color schemes. | ||
|
||
## Available methods | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
### `color:laba()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Converts the color to the LAB colorspace and returns those values + | ||
alpha: | ||
|
||
```lua | ||
local l, a, b, alpha = color:laba() | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## `color:lighten(factor)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Scales the color towards the maximum lightness by the provided | ||
factor, which should be in the range `0.0` through `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## `color:lighten_fixed(amount)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Increase the lightness by amount, a value ranging from `0.0` to `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## `color:linear_rgba()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Returns a tuple of the colors converted to linear RGBA and | ||
expressed as floating point numbers in the range `0.0-1.0`: | ||
|
||
```lua | ||
> r, g, b, a = wezterm.color.parse("purple"):linear_rgba() | ||
> print(r, g, b, a) | ||
07:32:17.734 INFO logging > lua: 0.2158605307340622 0 0.2158605307340622 1 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## `color:saturate(factor)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Scales the color towards the maximum saturation by the provided factor, which | ||
should be in the range `0.0` through `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## `color:saturate_fixed(amount)` | ||
|
||
*Since: nightly builds only* | ||
|
||
Increase the saturation by amount, a value ranging from `0.0` to `1.0`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## `color:square()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Returns the other three colors that form a square. The other colors | ||
are 90 degrees apart on the HSL color wheel. | ||
|
||
```lua | ||
local a, b, c = wezterm:color.parse("yellow"):square() | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## `color:srgba_u8()` | ||
|
||
*Since: nightly builds only* | ||
|
||
Returns a tuple of the internal SRGBA colors expressed | ||
as unsigned 8-bit integers in the range 0-255: | ||
|
||
```lua | ||
> r, g, b, a = wezterm.color.parse("purple"):srgba_u8() | ||
> print(r, g, b, a) | ||
07:30:20.045 INFO logging > lua: 128 0 128 255 | ||
``` |
Oops, something went wrong.