How to Make Your Terminal Talk in Color (with ANSI Codes)

How to Make Your Terminal Talk in Color (with ANSI Codes)

Table of Contents

Turn dull, gray output into colorful, readable text that actually speaks your language.

Ever squinted at a wall of monochrome logs? You know how easy it is to miss the important parts.

Your terminal doesn’t need to be gray noise. A few simple character codes can make it talk — highlighting successes in green, warnings in yellow, and progress in cyan.

Let’s turn your plain terminal into a clear, expressive display using ANSI escape codes — a tiny trick every developer should know.

What Are ANSI Escape Codes?

ANSI escape codes are small instruction snippets hidden inside your text output. They instruct your terminal on how to display what follows — color, bold, underline, or background highlights.

They look like this:

1\033[<style>;<text_color>;<bg_color>m
Part Meaning Example
\033[ Escape sequence introducer Always starts the code
<style> Optional text style (1 for bold, 4 for underline) 1
<text_color> Foreground color (30–37) 32 = green
<bg_color> Background color (40–47) 41 = red background
m Marks the end of the code m
\033[0m Resets the style Always close with this

When you print something like:

\033[32mHello\033[0m

you’re not calling a fancy function — you’re simply embedding instructions for your terminal inside your text.

Before & After: Colorful Output

Let’s see how a few escape codes can transform your output.

Here’s a quick side-by-side demo you can run in any language:

Plain Output Colorized Output
Running tests…
✓ test_login passed
✗ test_signup failed: expected 200, got 500
- test_profile skipped
✓ test_logout passed
Running tests…
✓ test_login passed
✗ test_signup failed: expected 200, got 500
- test_profile skipped
✓ test_logout passed

Without color

1print("Running tests...")
2print("✓ test_login passed")
3print("✗ test_signup failed: expected 200, got 500")
4print("- test_profile skipped")
5print("✓ test_logout passed")

With ANSI color

 1RESET = "\033[0m"
 2GREEN = "\033[32m"
 3RED = "\033[31m"
 4GRAY = "\033[90m"
 5CYAN = "\033[36m"
 6
 7print(f"{CYAN}Running tests...{RESET}")
 8print(f"{GREEN}✓ test_login passed{RESET}")
 9print(f"{RED}✗ test_signup failed:{RESET} expected 200, got 500")
10print(f"{GRAY}- test_profile skipped{RESET}")
11print(f"{GREEN}✓ test_logout passed{RESET}")

Now your terminal doesn’t just display results — it communicates them:

  • Green → Passed
  • Red → Failed
  • Gray → Skipped
  • Cyan → Context or status

Readable at a glance — even on a dark background.

Works Everywhere

Because ANSI codes live inside your text, they work in any language that prints to a terminal.

Node.js

1console.log("\x1b[32m✓ All tests passed\x1b[0m");
2console.log("\x1b[31m✗ 1 test failed\x1b[0m");

Bash

1echo -e "\033[33m[WARN]\033[0m Disk almost full"

Go

1fmt.Println("\033[35mFetching data...\033[0m")

Different syntax, same concept — the terminal interprets these escape sequences, not your code.

Beyond Debugging and Logs

Color isn’t just for test results — it’s for any terminal output:

  • CLI tools: highlight prompts, options, or errors
  • Scripts: make progress indicators stand out
  • Demos and education: separate code, output, and commentary
  • Monitoring: color-code system or CI messages for instant clarity

A dash of color turns raw text into a lightweight, human-friendly UI.

Terminal Compatibility

ANSI colors work in most modern terminals:

  • macOS: Terminal, iTerm2
  • Linux: bash, zsh, fish
  • Windows 10+: Windows Terminal

Info

If you see strange characters like ^[32m instead of colors, ANSI support might be off or your shell is outdated.

Quick Reference

Purpose Code Example
Reset 0 \033[0m
Bold 1 \033[1m
Underline 4 \033[4m
Text (foreground) 30–37 \033[32m = Green
Background 40–47 \033[41m = Red background
Gray (dim) 90 \033[90m = Gray text

Tip

You can mix and match these codes — just separate them with semicolons inside the same \033[ sequence.

For a full list of advanced ANSI sequences — including cursor movement, 256‑color palettes, and true‑color support — see the ANSI Escape Sequences Cheatsheet (GitHub Gist) by Conner Will.

Prefer Libraries?

Don’t want to memorize codes? Use helper libraries that handle colors, resets, and platform quirks for you.

Python

Node.js

Go

Rust

In Short

  • ANSI escape codes colorize and style terminal output.
  • They’re simple text sequences your terminal already understands.
  • They work everywhere — Python, Node, Go, Bash, you name it.
  • And they make CLI tools, logs, and scripts far more readable.

Your terminal isn’t just output — it’s your program’s voice.

A few characters of ANSI can turn plain output into a story your users can read at a glance.

Make sure it speaks clearly — and in color.

TL;DR for Skimmers

  • Use \033[ codes to style terminal output
  • Works in Python, Node, Go, Bash, and more
  • Supported in all modern terminals
  • Libraries like chalk, colorama, rich make it easy

Try it today: Add one color-coded line to your script — your eyes will thank you.

Related Posts

Rust Coding Conventions and Learning Resources

Rust Coding Conventions and Learning Resources

What coding style should I adopt for my Rust code to ensure consistency with my favorite Rust libraries? Where can I learn to develop a specific …

Read More
Python Learning Resources and Coding Conventions

Python Learning Resources and Coding Conventions

[Last update date: August 23, 2025]

If you’re looking to learn the Python programming language and improve your coding skills, using the right resources and following solid coding …

Read More
C Learning Resources and Coding Conventions

C Learning Resources and Coding Conventions

If you’re looking to learn the C programming language and improve your coding skills, using the right resources and following solid coding …

Read More