# nodesnim/core/color_text

Dark Mode

Search:
Group by:

# Imports

color

# Types

    ColorCharRef = ref object
      c*: char
      color*: ColorRef
      underline*: bool

    ColorTextRef = ref object
      chars*: seq[ColorCharRef]

# Procs

    proc setColor(self: ColorTextRef; fromc, toc: int; value: ColorRef) {...}{.raises: [], tags: [].}

  Changes text color.

  Arguments:

  - `fromc` - from char position.
  - `toc` - to char position.
  - `value` - new color.

  Examples:

      import
        nodesnim / core / color

      var
        text = clrtext"hello world"
        clr = Color(1, 0.6, 1)
      text.setColor(5, text.chars.len() - 1, clr)

    proc setColor(self: ColorTextRef; value: ColorRef) {...}{.raises: [], tags: [].}

  Changes text color.

  Arguments:

  - `value` - new color.

  Examples:

      import
        nodesnim / core / color

      var
        text = clrtext"hello world"
        clr = Color(1, 0.6, 0.8)
      text.setColor(clr)

    proc setColor(self: ColorTextRef; index: int; value: ColorRef) {...}{.raises: [], tags: [].}

  Changes text color.

  Arguments:

  - `index` - char position.
  - `value` - new color.

  Examples:

      import
        nodesnim / core / color

      var
        text = clrtext"hello world"
        clr = Color(1, 0.6, 1)
      text.setColor(0, clr)

    proc setUnderline(self: ColorTextRef; fromc, toc: int; value: bool) {...}{.raises: [], tags: [].}

  Changes text underline.

  Arguments:

  - `fromc` - from char position.
  - `toc` - to char position.

  Examples:

      var text = clrtext"hello world"
      text.setUnderline(5, text.chars.len() - 1, true)

    proc setUnderline(self: ColorTextRef; value: bool) {...}{.raises: [], tags: [].}

  Changes text underline.

  Examples:

      var text = clrtext"hello world"
      text.setUnderline(true)

    proc setUnderline(self: ColorTextRef; index: int; value: bool) {...}{.raises: [], tags: [].}

  Changes text underline.

  Arguments:

  - `index` - char position.

  Examples:

      var text = clrtext"hello world"
      text.setUnderline(0, true)

    proc len(x: ColorTextRef): int {...}{.raises: [], tags: [].}

    proc splitLines(x: ColorTextRef): seq[ColorTextRef] {...}{.raises: [], tags: [].}

  Creates a new seq of ColorTextRef.

    proc `$`(text: ColorTextRef): string {...}{.raises: [], tags: [].}

    proc `$`(c: ColorCharRef): string {...}{.raises: [], tags: [].}

    proc `==`(x, y: ColorTextRef): bool {...}{.raises: [], tags: [].}

    proc `&`(x, y: ColorCharRef): ColorTextRef {...}{.raises: [], tags: [].}

  Examples:

      var
        a = clrchar 'a'
        b = clrchar 'b'
      assert a & b == clrtext"ab"

    proc `&`(x: ColorTextRef; y: ColorCharRef): ColorTextRef {...}{.raises: [], tags: [].}

    proc `&`(x: ColorCharRef; y: ColorTextRef): ColorTextRef {...}{.raises: [], tags: [].}

    proc `&`(x, y: ColorTextRef): ColorTextRef {...}{.raises: [], tags: [].}

    proc contains(x: ColorTextRef; y: ColorCharRef): bool {...}{.raises: [], tags: [].}

  Examples:

      var
        text = clrtext"hello"
        c = clrchar 'o'
      assert c in text

    proc `[]`[U, V](self: ColorTextRef; i: HSlice[U, V]): ColorTextRef

    proc `[]`(self: ColorTextRef; i: BackwardsIndex): ColorCharRef {...}{.raises: [], tags: [].}

    proc `[]`(self: ColorTextRef; i: int): ColorCharRef {...}{.raises: [], tags: [].}

    proc add(self: var ColorTextRef; other: ColorTextRef) {...}{.raises: [], tags: [].}

    proc add(self: var ColorTextRef; other: ColorCharRef) {...}{.raises: [], tags: [].}

# Funcs

    func clrtext(text: string; color: ColorRef = Color(1.0'f32, 1.0'f32, 1.0'f32);
                underline: bool = false): ColorTextRef {...}{.raises: [], tags: [].}

  Creates a new ColorText ref object.

  Arguments:

  - `color` is a text color.
  - `underline` is a text underline.

  Examples:

      import
        nodesnim / core / color

      var
        text = clrtext"hello"
        text1 = clrtext("hello", Color(1, 0.6, 1))

    func clrchar(c: char; color: ColorRef = Color(1.0'f32, 1.0'f32, 1.0'f32);
                underline: bool = false): ColorCharRef {...}{.raises: [], tags: [].}

  Creates a new ColorChar ref object.

  Arguments:

  - `color` is a char color.
  - `underline` is a char underline.

  Examples:

      import
        nodesnim / core / color

      var
        c = clrchar 's'
        c1 = clrchar('s', Color(1.0'f32, 1.0'f32, 1.0'f32), underline = true)

# Converters

    converter toChar(x: ColorCharRef): char {...}{.raises: [], tags: [].}