Skip to content

Commit

Permalink
fix(styles): Colors again
Browse files Browse the repository at this point in the history
  • Loading branch information
jamonholmgren committed Oct 16, 2023
1 parent 2b43894 commit 2cf0c81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cli/commands/demo/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export default {
print(gptGreen("Hello!"))
print(white(bgGreen("there!")))
print(yellow(`Hey ${red("you")}! I ${bgGreen("like")} ${gptGreen("you")}!`))

print(`And ... \u001B[41mHello, \u001B[42mWorld\u001B[41m!\u001B[49m ... yet again!`)
},
}
24 changes: 12 additions & 12 deletions tests/styles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ import { color, colorRGB, colorHex, bgColor } from "bluebun"

test("color", () => {
// normal colors
expect(color(42)("Hello")).toBe("\u001B[42mHello\u001B[39m")
expect(color(43)("Hello")).toBe("\u001B[43mHello\u001B[39m")
expect(color(32)("Hello")).toBe("\u001B[32mHello\u001B[39m")
expect(color(33)("Hello")).toBe("\u001B[33mHello\u001B[39m")

// background
expect(color(42, true)("Hello")).toBe("\u001B[52mHello\u001B[49m")
expect(color(32, true)("Hello")).toBe("\u001B[42mHello\u001B[49m")
})

test("nested colors", () => {
const red = color(41)
const green = color(42)
expect(red("Hello, " + green("World") + "!")).toBe("\u001B[41mHello, \u001B[42mWorld\u001B[41m!\u001B[39m")
const red = color(31)
const green = color(32)
expect(red("Hello, " + green("World") + "!")).toBe("\u001B[31mHello, \u001B[32mWorld\u001B[31m!\u001B[39m")
})

test("nested colors with backgrounds", () => {
const red = color(41)
const bgGreen = bgColor(42)
expect(red("Hello, " + bgGreen("World") + "!")).toBe("\u001B[41mHello, \u001B[52mWorld\u001B[49m!\u001B[39m")
const red = color(31)
const bgGreen = bgColor(32)
expect(red("Hello, " + bgGreen("World") + "!")).toBe("\u001B[31mHello, \u001B[42mWorld\u001B[49m!\u001B[39m")
})

test("nested background colors", () => {
const bgRed = bgColor(41)
const bgGreen = bgColor(42)
expect(bgRed("Hello, " + bgGreen("World") + "!")).toBe("\u001B[51mHello, \u001B[52mWorld\u001B[51m!\u001B[49m")
const bgRed = bgColor(31)
const bgGreen = bgColor(32)
expect(bgRed("Hello, " + bgGreen("World") + "!")).toBe("\u001B[41mHello, \u001B[42mWorld\u001B[41m!\u001B[49m")
})

test("colorRGB", () => {
Expand Down

0 comments on commit 2cf0c81

Please sign in to comment.