Skip to content

Commit

Permalink
fix: use more widely available color for pink instead of hex (#12)
Browse files Browse the repository at this point in the history
* fix: use more widely available color for pink instead of hex

* fix: update workflow

* fix: bump version
  • Loading branch information
brettkolodny authored Aug 12, 2024
1 parent 9ff0102 commit a598625
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "26.1"
gleam-version: "0.33.0"
gleam-version: "1.4.1"

- run: |
version="v$(cat gleam.toml | grep -m 1 "version" | sed -r "s/version *= *\"([[:digit:].]+)\"/\1/")"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "26.1"
gleam-version: "0.33.0"
gleam-version: "1.4.1"

- run: gleam format --check

Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "gleam_community_ansi"
version = "1.4.0"
version = "1.4.1"
licences = ["Apache-2.0"]
description = "ANSI colours, formatting, and control codes"
repository = { type = "github", user = "gleam-community", repo = "ansi" }
Expand Down
33 changes: 12 additions & 21 deletions src/gleam_community/ansi.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------------------------
Expand All @@ -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",
)
}

Expand Down Expand Up @@ -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"
/// }
/// ```
///
Expand Down Expand Up @@ -1298,7 +1289,7 @@ pub fn bright_white(text: String) -> String {
/// </div>
///
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`.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
/// }
/// ```
///
Expand Down Expand Up @@ -2204,7 +2195,7 @@ pub fn bg_bright_white(text: String) -> String {
/// </div>
///
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`.
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions test/gleam_community_ansi_test.gleam
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a598625

Please sign in to comment.