mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
terminal: Make rgb_for_index
take a u8
instead of a &u8
(#8726)
This PR makes the `rgb_for_index` take a `u8` instead of a `&u8`. `u8` is `Copy` and is only 1 byte, so there really isn't any reason to pass a reference to it. Release Notes: - N/A
This commit is contained in:
parent
4b81b15cad
commit
12440d5e0d
@ -1503,7 +1503,7 @@ pub fn get_color_at_index(index: usize, theme: &Theme) -> Hsla {
|
||||
15 => colors.terminal_ansi_bright_white,
|
||||
// 16-231 are mapped to their RGB colors on a 0-5 range per channel
|
||||
16..=231 => {
|
||||
let (r, g, b) = rgb_for_index(&(index as u8)); // Split the index into its ANSI-RGB components
|
||||
let (r, g, b) = rgb_for_index(index as u8); // Split the index into its ANSI-RGB components
|
||||
let step = (u8::MAX as f32 / 5.).floor() as u8; // Split the RGB range into 5 chunks, with floor so no overflow
|
||||
rgba_color(r * step, g * step, b * step) // Map the ANSI-RGB components to an RGB color
|
||||
}
|
||||
@ -1542,8 +1542,8 @@ pub fn get_color_at_index(index: usize, theme: &Theme) -> Hsla {
|
||||
/// ```
|
||||
///
|
||||
/// This function does the reverse, calculating the `r`, `g`, and `b` components from a given index.
|
||||
fn rgb_for_index(i: &u8) -> (u8, u8, u8) {
|
||||
debug_assert!((&16..=&231).contains(&i));
|
||||
fn rgb_for_index(i: u8) -> (u8, u8, u8) {
|
||||
debug_assert!((16..=231).contains(&i));
|
||||
let i = i - 16;
|
||||
let r = (i - (i % 36)) / 36;
|
||||
let g = ((i % 36) - (i % 6)) / 6;
|
||||
@ -1578,7 +1578,7 @@ mod tests {
|
||||
fn test_rgb_for_index() {
|
||||
// Test every possible value in the color cube.
|
||||
for i in 16..=231 {
|
||||
let (r, g, b) = rgb_for_index(&i);
|
||||
let (r, g, b) = rgb_for_index(i);
|
||||
assert_eq!(i, 16 + 36 * r + 6 * g + b);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user