From 158061421ce54d67262daad10e87951ecc65da59 Mon Sep 17 00:00:00 2001 From: brettkolodny Date: Mon, 12 Aug 2024 17:21:03 -0400 Subject: [PATCH] fix: use more widely available color for pink instead of hex --- src/gleam_community/ansi.gleam | 33 ++++++++++------------------ test/gleam_community_ansi_test.gleam | 8 +++---- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/gleam_community/ansi.gleam b/src/gleam_community/ansi.gleam index 3dc7305..e99d0ab 100644 --- a/src/gleam_community/ansi.gleam +++ b/src/gleam_community/ansi.gleam @@ -97,8 +97,8 @@ import gleam/int import gleam/list -import gleam/string import gleam/regex +import gleam/string import gleam_community/colour.{type Colour} as gc_colour // CONSTS --------------------------------------------------------------------- @@ -119,18 +119,9 @@ fn code(open: List(Int), close: Int) -> Code { let open_strs = list.map(open, int.to_string) Code( - open: asci_escape_character - <> "[" - <> string.join(open_strs, ";") - <> "m", - close: asci_escape_character - <> "[" - <> close_str - <> "m", - regexp: asci_escape_character - <> "[" - <> close_str - <> "m", + open: asci_escape_character <> "[" <> string.join(open_strs, ";") <> "m", + close: asci_escape_character <> "[" <> close_str <> "m", + regexp: asci_escape_character <> "[" <> close_str <> "m", ) } @@ -1265,7 +1256,7 @@ pub fn bright_white(text: String) -> String { /// /// fn example() { /// ansi.pink("lucy") -/// // => "\x1B[38;2;255;175;243mlucy\x1B[39m" +/// // => "\x1B[38;5;219mlucy\x1B[39m" /// } /// ``` /// @@ -1298,7 +1289,7 @@ pub fn bright_white(text: String) -> String { /// /// pub fn pink(text: String) -> String { - hex(text, 0xffaff3) + run(text, code([38, 5, 219], 39)) } /// Colour the given text the given colour represented by a hex `Int`. @@ -1357,9 +1348,9 @@ pub fn hex(text: String, colour: Int) -> String { 38, 2, int.bitwise_shift_right(colour, 16) - |> int.bitwise_and(0xff), + |> int.bitwise_and(0xff), int.bitwise_shift_right(colour, 8) - |> int.bitwise_and(0xff), + |> int.bitwise_and(0xff), int.bitwise_and(colour, 0xff), ], 39, @@ -2171,7 +2162,7 @@ pub fn bg_bright_white(text: String) -> String { /// /// fn example() { /// ansi.bg_pink("lucy") -/// // => "\x1B[48;2;255;175;243mlucy\x1B[49m" +/// // => "\x1B[48;5;219mlucy\x1B[49m" /// } /// ``` /// @@ -2204,7 +2195,7 @@ pub fn bg_bright_white(text: String) -> String { /// /// pub fn bg_pink(text: String) -> String { - bg_hex(text, 0xffaff3) + run(text, code([48, 5, 219], 49)) } /// Colour the given text's background the given colour represented by a hex `Int`. @@ -2262,9 +2253,9 @@ pub fn bg_hex(text: String, colour: Int) -> String { 48, 2, int.bitwise_shift_right(colour, 16) - |> int.bitwise_and(0xff), + |> int.bitwise_and(0xff), int.bitwise_shift_right(colour, 8) - |> int.bitwise_and(0xff), + |> int.bitwise_and(0xff), int.bitwise_and(colour, 0xff), ], 49, diff --git a/test/gleam_community_ansi_test.gleam b/test/gleam_community_ansi_test.gleam index 920ed9b..e460b21 100644 --- a/test/gleam_community_ansi_test.gleam +++ b/test/gleam_community_ansi_test.gleam @@ -1,7 +1,7 @@ -import gleeunit -import gleeunit/should import gleam_community/ansi import gleam_community/colour +import gleeunit +import gleeunit/should pub fn main() { gleeunit.main() @@ -284,13 +284,13 @@ pub fn bg_hex_test() { pub fn colour_test() { "foo bar" |> ansi.colour(colour.pink) - |> should.equal(ansi.pink("foo bar")) + |> should.equal(ansi.hex("foo bar", 0xffaff3)) } pub fn bg_colour_test() { "foo bar" |> ansi.bg_colour(colour.pink) - |> should.equal(ansi.bg_pink("foo bar")) + |> should.equal(ansi.bg_hex("foo bar", 0xffaff3)) } pub fn strip_test() {