gleam_community/ansi


This package was heavily inspired by the colors module in the Deno standard library. The original source code can be found here.

The license of that package is produced below:

MIT License

Copyright 2018-2022 the Deno authors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Functions

pub fn bg_black(text: String) -> String

Colour the given text’s background black.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_black("lucy")
  // => "\x1B[40mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_blue(text: String) -> String

Colour the given text’s background blue.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_blue("lucy")
  // => "\x1B[44mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_black(text: String) -> String

Colour the given text’s background bright black.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_black("lucy")
  // => "\x1B[100mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_blue(text: String) -> String

Colour the given text’s background bright blue.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_blue("lucy")
  // => "\x1B[104mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_cyan(text: String) -> String

Colour the given text’s background bright cyan.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_cyan("lucy")
  // => "\x1B[106mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_green(text: String) -> String

Colour the given text’s background bright green.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_green("lucy")
  // => "\x1B[102mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_magenta(text: String) -> String

Colour the given text’s background bright magenta.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_magenta("lucy")
  // => "\x1B[105mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_red(text: String) -> String

Colour the given text’s background bright red.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_red("lucy")
  // => "\x1B[101mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_white(text: String) -> String

Colour the given text’s background bright white.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_white("lucy")
  // => "\x1B[107mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_bright_yellow(text: String) -> String

Colour the given text’s background bright yellow.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_bright_yellow("lucy")
  // => "\x1B[103mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_color(text: String, colour: Colour) -> String

This is an alias for bg_colour for those who prefer the American English spelling.

pub fn bg_colour(text: String, colour: Colour) -> String

Colour the given text’s background with the given colour represented by a Colour.

Example:
import gleam_community/ansi
import gleam_community/colour.{Colour}

fn example() {
  let pink = colour.from_hsl(0.8583, 1.0, 0,84)
  ansi.bg_colour("lucy", pink)
  // => "\x1B[48;2;255;175;243mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_cyan(text: String) -> String

Colour the given text’s background cyan.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_cyan("lucy")
  // => "\x1B[46mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_green(text: String) -> String

Colour the given text’s background green.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_green("lucy")
  // => "\x1B[42mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_hex(text: String, colour: Int) -> String

Colour the given text’s background the given colour represented by a hex Int.

The given hex Int can be any valid shorthand hexadecimal form.

❗️ Note that if supplied hex Int is less than 0 or larger than 0xfffff the colour will be set to black and white respectively.

Example:
import gleam_community/ansi

fn example() {
  ansi.hex("lucy", 0xffaff3)
  // => "\x1B[48;2;255;175;243mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_magenta(text: String) -> String

Colour the given text’s background magenta.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_magenta("lucy")
  // => "\x1B[45mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_pink(text: String) -> String

Colour the given text’s background pink.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_pink("lucy")
  // => "\x1B[48;2;255;175;243mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_red(text: String) -> String

Colour the given text’s background red.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_red("lucy")
  // => "\x1B[41mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_white(text: String) -> String

Colour the given text’s background white.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_white("lucy")
  // => "\x1B[47mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bg_yellow(text: String) -> String

Colour the given text’s background yellow.

Example:
import gleam_community/ansi

fn example() {
  ansi.bg_yellow("lucy")
  // => "\x1B[43mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn black(text: String) -> String

Colour the given text black.

Example:
import gleam_community/ansi

fn example() {
  ansi.black("lucy")
  // => "\x1B[30mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn blue(text: String) -> String

Colour the given text blue.

Example:
import gleam_community/ansi

fn example() {
  ansi.blue("lucy")
  // => "\x1B[34mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bold(text: String) -> String

Style the given text bold.

Example:
import gleam_community/ansi

fn example() {
  ansi.bold("lucy")
  // => "\x1B[1mlucy\x1B[22m"
}

❗️ Note the trailing "\x1B[22m" added to the string. This is the escape code for the “default” bold/dim style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be dim but the text “fun?” will be both underlined, and bold!

pub fn bright_black(text: String) -> String

Colour the given text bright black. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
import gleam_community/ansi

fn example() {
  ansi.bright_black("lucy")
  // => "\x1B[90mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_blue(text: String) -> String

Colour the given text bright blue. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
fn example() {
  ansi.bright_blue("lucy")
  // => "\x1B[94mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_cyan(text: String) -> String

Colour the given text bright cyan. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
fn example() {
  ansi.bright_cyan("lucy")
  // => "\x1B[96mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_green(text: String) -> String

Colour the given text bright green. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
fn example() {
  ansi.bright_green("lucy")
  // => "\x1B[92mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_magenta(text: String) -> String

Colour the given text bright gremagentaen. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
fn example() {
  ansi.bright_magenta("lucy")
  // => "\x1B[95mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_red(text: String) -> String

Colour the given text bright red. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
import gleam_community/ansi

fn example() {
  ansi.bright_red("lucy")
  // => "\x1B[91mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_white(text: String) -> String

Colour the given text bright white. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
fn example() {
  ansi.bright_white("lucy")
  // => "\x1B[97mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn bright_yellow(text: String) -> String

Colour the given text bright yellow. This should increase the luminosity of the base colour, but some terminals will interpret this as bold instead.

Example:
fn example() {
  ansi.bright_yellow("lucy")
  // => "\x1B[93mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn color(text: String, color: Colour) -> String

This is an alias for colour for those who prefer the American English spelling.

pub fn colour(text: String, colour: Colour) -> String

Colour the given text the given colour represented by a Colour.

Example:
import gleam_community/ansi
import gleam_community/colour.{Colour}

fn example() {
  let pink = colour.from_hsl(0.8583, 1.0, 0,84)
  ansi.colour("lucy", pink)
  // => "\x1B[48;2;255;175;243mlucy\x1B[49m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn cyan(text: String) -> String

Colour the given text cyan.

Example:
import gleam_community/ansi

fn example() {
  ansi.cyan("lucy")
  // => "\x1B[36mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn dim(text: String) -> String

Style the given text’s colour to be dimmer.

Example:
import gleam_community/ansi

fn example() {
  ansi.dim("lucy")
  // => "\x1B[2mlucy\x1B[22m"
}

❗️ Note the trailing "\x1B[22m" added to the string. This is the escape code for the “default” bold/dim style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be dim but the text “fun?” will be both underlined, and bold!

pub fn gray(text: String) -> String

This is an alias for grey for those who prefer the American English spelling.

pub fn green(text: String) -> String

Colour the given text green.

Example:
import gleam_community/ansi

fn example() {
  ansi.green("lucy")
  // => "\x1B[32mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn grey(text: String) -> String

Colour the given text gray.

Example:
import gleam_community/ansi

fn example() {
  ansi.gray("lucy")
  // => "\x1B[90mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn hex(text: String, colour: Int) -> String

Colour the given text the given colour represented by a hex Int.

The given hex Int can be any valid shorthand hexadecimal form.

❗️ Note that if supplied hex Int is less than 0 or larger than 0xfffff the colour will be set to black and white respectively.

Example:
import gleam_community/ansi

fn example() {
  ansi.hex("lucy", 0xffaff3)
  // => "\x1B[38;2;255;175;243mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[49m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn hidden(text: String) -> String

Style the given text to be hidden.

Example:
import gleam_community/ansi

fn example() {
  ansi.hidden("lucy")
  // => "\x1B[8mlucy\x1B[28m"
}

❗️ Note the trailing "\x1B[28m" added to the string. This is the escape code for the “default” hidden style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be dim but the text “fun?” will be both underlined, and bold!

pub fn inverse(text: String) -> String

Inverse the given text’s colour, and background colour.

Example:
import gleam_community/ansi

fn example() {
  ansi.inverse("lucy")
  // => "\x1B[7mlucy\x1B[27m"
}

❗️ Note the trailing "\x1B[27m" added to the string. This is the escape code for the “default” inverse style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be dim but the text “fun?” will be both underlined, and bold!

pub fn italic(text: String) -> String

Style the given text italic.

Example:
import gleam_community/ansi

fn example() {
  ansi.italic("lucy")
  // => "\x1B[3mlucy\x1B[23m"
}

❗️ Note the trailing "\x1B[23m" added to the string. This is the escape code for the “default” italic style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.underline("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be underlined but the text “fun?” will be both underlined, and bold!

pub fn magenta(text: String) -> String

Colour the given text magenta.

Example:
import gleam_community/ansi

fn example() {
  ansi.magenta("lucy")
  // => "\x1B[35mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn pink(text: String) -> String

Colour the given text pink.

Example:
import gleam_community/ansi

fn example() {
  ansi.pink("lucy")
  // => "\x1B[38;2;255;175;243mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn red(text: String) -> String

Colour the given text red.

Example:
import gleam_community/ansi

fn example() {
  ansi.red("lucy")
  // => "\x1B[31mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn reset(text: String) -> String

Reset the text modified

pub fn strikethrough(text: String) -> String

Style the given text to be striked through.

Example:
import gleam_community/ansi

fn example() {
  ansi.strikethrough("lucy")
  // => "\x1B[9mlucy\x1B[29m"
}

❗️ Note the trailing "\x1B[29m" added to the string. This is the escape code for the “default” strikethrough style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be dim but the text “fun?” will be both underlined, and bold!

pub fn strip(text: String) -> String

Strips the ansi control characters from the text.

Example:
import gleam_community/ansi

fn example() {
  let bold_lucy = ansi.bold("lucy")
  // => "\x1B[1mlucy\x1B[22m"
  ansi.strip(bold_lucy)
  // => "lucy"
}

In this example, the text “lucy” is boldened by ansi.bold and then converted back to the original string with ansi.strip.

pub fn underline(text: String) -> String

Style the given text’s colour to be dimmer.

Example:
import gleam_community/ansi

fn example() {
  ansi.underline("lucy")
  // => "\x1B[4mlucy\x1B[24m"
}

❗️ Note the trailing "\x1B[24m" added to the string. This is the escape code for the “default” underline style of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default style, it will use both the outter style and the inner style.

import gleam_community/ansi

fn example() {
  ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be dim but the text “fun?” will be both underlined, and bold!

pub fn white(text: String) -> String

Colour the given text white.

Example:
import gleam_community/ansi

fn example() {
  ansi.white("lucy")
  // => "\x1B[37mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

pub fn yellow(text: String) -> String

Colour the given text yellow.

Example:
import gleam_community/ansi

fn example() {
  ansi.yellow("lucy")
  // => "\x1B[33mlucy\x1B[39m"
}

❗️ Note the trailing "\x1B[39m" added to the string. This is the escape code for the “default” colour of the terminal. This means text you write after this will revert back to default.

gleam_community/ansi is smart about nested styles; instead of using the default colour, it will use the colour of the outter style.

import gleam_community/ansi

fn example() {
  ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?")
}

In this example, the text “Gleam” will be pink but the text “fun?” will be yellow, not the default colour!

Search Document