etch/style

This module provides utilities for styling terminal text.

Types

A type that represents text attributes like bold, italic, etc.

pub type Attribute {
  Bold
  Dim
  Underline
  Italic
  Blinking
  Inverse
}

Constructors

  • Bold

    Bold text.

  • Dim

    Dim text.

  • Underline

    Underline text.

  • Italic

    Italic text.

  • Blinking

    Blinking text.

  • Inverse

    Inverse (swaps foreground and background Colors).

A type that represents a color that can be set as foreground or background.

pub type Color {
  Default
  Black
  Grey
  Red
  BrightRed
  Green
  BrightGreen
  Yellow
  BrightYellow
  Blue
  BrightBlue
  Magenta
  BrightMagenta
  Cyan
  BrightCyan
  White
  BrightWhite
  BrightGrey
  AnsiValue(v: Int)
  Rgb(r: Int, g: Int, b: Int)
}

Constructors

  • Default

    Default terminal color.

  • Black

    Black color.

  • Grey

    Grey color.

  • Red

    Red color.

  • BrightRed

    Bright red color.

  • Green

    Green color.

  • BrightGreen

    Bright green color.

  • Yellow

    Yellow color.

  • BrightYellow

    Bright yellow color.

  • Blue

    Blue color.

  • BrightBlue

    Bright blue color.

  • Magenta

    Magenta color.

  • BrightMagenta

    Bright magenta color.

  • Cyan

    Cyan color.

  • BrightCyan

    Bright cyan color.

  • White

    White color.

  • BrightWhite

    Bright white color.

  • BrightGrey

    Bright grey color.

  • AnsiValue(v: Int)

    Ansi color (256 colors). See https://www.ditig.com/256-colors-cheat-sheet.

  • Rgb(r: Int, g: Int, b: Int)

    RGB color.

Allows to save style (foreground and background Colors) and Attributes) and use it later by calling with_style.

pub type Style {
  Style(bg: Color, fg: Color, attributes: List(Attribute))
}

Constructors

Values

pub fn ansi(s: String, value: Int) -> String

Sets the foreground Color to the given ANSI value and resets it afterwards.

pub fn attributes(s: String, a: List(Attribute)) -> String

Sets Attributes of a string.

pub fn black(s: String) -> String

Sets the foreground Color to black and resets the color afterwards.

pub fn blinking(s: String) -> String

Makes the string blinking and resets this attribute afterwards.

pub fn blue(s: String) -> String

Sets the foreground Color to blue and resets the color afterwards.

pub fn bold(s: String) -> String

Makes the string bold and resets this attribute afterwards.

pub fn bright_blue(s: String) -> String

Sets the foreground Color to bright blue and resets the color afterwards.

pub fn bright_cyan(s: String) -> String

Sets the foreground Color to bright cyan and resets the color afterwards.

pub fn bright_green(s: String) -> String

Sets the foreground Color to bright green and resets the color afterwards.

pub fn bright_grey(s: String) -> String

Sets the foreground Color to bright grey and resets the color afterwards.

pub fn bright_magenta(s: String) -> String

Sets the foreground Color to bright magenta and resets the color afterwards.

pub fn bright_red(s: String) -> String

Sets the foreground Color to bright red and resets the color afterwards.

pub fn bright_white(s: String) -> String

Sets the foreground Color to bright white and resets the color afterwards.

pub fn bright_yellow(s: String) -> String

Sets the foreground Color to bright yellow and resets the color afterwards.

pub fn cyan(s: String) -> String

Sets the foreground Color to cyan and resets the color afterwards.

pub fn default_style() -> Style

Returns default Style with terminal’s default foreground and background Colors) and no Attributes.

pub fn dim(s: String) -> String

Makes the string dim and resets this attribute afterwards.

pub fn green(s: String) -> String

Sets the foreground Color to green and resets the color afterwards.

pub fn grey(s: String) -> String

Sets the foreground Color to grey and resets the color afterwards.

pub fn inverse(s: String) -> String

Makes the string inverse (swaps background and foreground colors) and resets this attribute afterwards. See Color.

pub fn italic(s: String) -> String

Makes the string italic and resets this attribute afterwards.

pub fn magenta(s: String) -> String

Sets the foreground Color to magenta and resets the color afterwards.

pub fn on(s: String, c: Color) -> String

Sets the foreground color of a string. It does not reset the color after applying it. Also see with to set the foreground color. Using with_on is prefered to set both the background and foreground colors.

pub fn on_ansi(s: String, value: Int) -> String

Sets the background Color to the given ANSI value and resets it afterwards.

pub fn on_black(s: String) -> String

Sets the background Color to black and resets it afterwards.

pub fn on_blue(s: String) -> String

Sets the background Color to blue and resets it afterwards.

pub fn on_bright_blue(s: String) -> String

Sets the background Color to bright blue and resets it afterwards.

pub fn on_bright_cyan(s: String) -> String

Sets the background Color to bright cyan and resets it afterwards.

pub fn on_bright_green(s: String) -> String

Sets the background Color to bright green and resets it afterwards.

pub fn on_bright_grey(s: String) -> String

Sets the background Color to bright grey and resets it afterwards.

pub fn on_bright_magenta(s: String) -> String

Sets the background Color to bright magenta and resets it afterwards.

pub fn on_bright_red(s: String) -> String

Sets the background Color to bright red and resets it afterwards.

pub fn on_bright_white(s: String) -> String

Sets the background Color to bright white and resets it afterwards.

pub fn on_bright_yellow(s: String) -> String

Sets the background Color to bright yellow and resets it afterwards.

pub fn on_cyan(s: String) -> String

Sets the background Color to cyan and resets it afterwards.

pub fn on_green(s: String) -> String

Sets the background Color to green and resets it afterwards.

pub fn on_grey(s: String) -> String

Sets the background Color to grey and resets it afterwards.

pub fn on_magenta(s: String) -> String

Sets the background Color to magenta and resets it afterwards.

pub fn on_rbg(s: String, r: Int, g: Int, b: Int) -> String

Sets the background Color to the given RBG color and resets it afterwards.

pub fn on_red(s: String) -> String

Sets the background Color to red and resets it afterwards.

pub fn on_white(s: String) -> String

Sets the background Color to white and resets it afterwards.

pub fn on_yellow(s: String) -> String

Sets the background Color to yellow and resets it afterwards.

pub fn rbg(s: String, r: Int, g: Int, b: Int) -> String

Sets the foreground Color to the given RBG color and resets it afterwards.

pub fn red(s: String) -> String

Sets the foreground Color to red and resets the color afterwards.

pub fn reset_attributes(s: String) -> String

Resets Attributes of the string.

pub fn reset_background(s: String) -> String

Resets background of the string. See Color.

pub fn reset_color(s: String) -> String

Resets color of the string. See Color.

pub fn reset_foreground(s: String) -> String

Resets foreground of the string. See Color.

pub fn reset_style(s: String) -> String

Resets color of the string. See Color.

pub fn set_style(s: Style) -> String

Resets color of the string. See Color.

pub fn underline(s: String) -> String

Makes the string underline and resets this attribute afterwards.

pub fn white(s: String) -> String

Sets the foreground Color to white and resets the color afterwards.

pub fn with(s: String, c: Color) -> String

Sets the foreground color of a string. It does not reset the color after applying it. Also see on to set the background color. Using with_on is prefered to set both the background and foreground colors.

pub fn with_on(s: String, fg: Color, bg: Color) -> String

Sets both the foreground and background colors. It is the prefered way to set them both for one string. Also see with to set the foreground color and on to set the background color.

pub fn with_style(s: String, style: Style) -> String

Applies style to a string.

pub fn yellow(s: String) -> String

Sets the foreground Color to yellow and resets the color afterwards.

Search Document