Home Explore Blog CI



nushell

1st chunk of `commands/docs/ansi.md`
712e45ec4a68def111973d804bd1f888dafa037aeae43b910000000100000c10
---
title: ansi
categories: |
  platform
version: 0.104.0
platform: |
  Output ANSI codes to change color and style of text.
usage: |
  Output ANSI codes to change color and style of text.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `ansi` for [platform](/commands/categories/platform.md)

<div class='command-title'>Output ANSI codes to change color and style of text.</div>

## Signature

```> ansi {flags} (code)```

## Flags

 -  `--escape, -e`: escape sequence without the escape character(s) ('\x1b[' is not required)
 -  `--osc, -o`: operating system command (osc) escape sequence without the escape character(s) ('\x1b]' is not required)
 -  `--list, -l`: list available ansi code names

## Parameters

 -  `code`: The name of the code to use (from `ansi -l`).


## Input/output types:

| input   | output |
| ------- | ------ |
| nothing | any    |
## Examples

Change color to green (see how the next example text will be green!)
```nu
> ansi green

```

Reset the color
```nu
> ansi reset

```

Use different colors and styles in the same text
```nu
> $'(ansi red_bold)Hello(ansi reset) (ansi green_dimmed)Nu(ansi reset) (ansi purple_italic)World(ansi reset)'
Hello Nu World
```

The same example as above with short names
```nu
> $'(ansi rb)Hello(ansi reset) (ansi gd)Nu(ansi reset) (ansi pi)World(ansi reset)'
Hello Nu World
```

Use escape codes, without the '\x1b['
```nu
> $"(ansi --escape '3;93;41m')Hello(ansi reset)"  # italic bright yellow on red background
Hello
```

Use structured escape codes
```nu
> let bold_blue_on_red = {  # `fg`, `bg`, `attr` are the acceptable keys, all other keys are considered invalid and will throw errors.
        fg: '#0000ff'
        bg: '#ff0000'
        attr: b
    }
    $"(ansi --escape $bold_blue_on_red)Hello, Nu World!(ansi reset)"
Hello, Nu World!
```

## Notes
```text
An introduction to what ANSI escape sequences are can be found in the
]8;;https://en.wikipedia.org/wiki/ANSI_escape_code\ANSI escape code]8;;\ Wikipedia page.

Escape sequences usual values:
╭────┬────────────┬────────┬────────┬─────────╮
│  # │    type    │ normal │ bright │  name   │
├────┼────────────┼────────┼────────┼─────────┤
│  0 │ foreground │     30 │     90 │ black   │
│  1 │ foreground │     31 │     91 │ red     │
│  2 │ foreground │     32 │     92 │ green   │
│  3 │ foreground │     33 │     93 │ yellow  │
│  4 │ foreground │     34 │     94 │ blue    │
│  5 │ foreground │     35 │     95 │ magenta │
│  5 │ foreground │     35 │     95 │ purple  │
│  6 │ foreground │     36 │     96 │ cyan    │
│  7 │ foreground │     37 │     97 │ white   │
│  8 │ foreground │     39 │        │ default │

Title: ansi
Summary
The `ansi` command outputs ANSI escape codes to change the color and style of text in the terminal. It takes a code name as an argument (use `ansi -l` to list available codes). It can also use escape sequences and structured escape codes without the escape character.