Add Colors to Your Terminal Chatbot (Lesson 23)

What You Will Learn

In this lesson, you will learn:

  • Why colors improve a terminal application
  • How to install the colorama library
  • How to print colorful text in Python
  • How to make your AI chatbot easier to read

By the end of this lesson, your chatbot will have a colorful and professional command-line interface.


Quick Answer

The colorama library lets you display colored text in the terminal. Instead of showing everything in the same color, you can highlight important information such as:

  • User messages
  • AI responses
  • Errors
  • Commands
  • Titles

This makes your chatbot easier to use.


Why Add Colors?

Look at this example.

Without Colors

=========================================
AI Assistant v1.0
=========================================

Current Personality : Python Teacher

You:

Everything looks the same.

Now compare it with this.

With Colors

=========================================
AI Assistant v1.0
=========================================

Current Personality : Python Teacher

You:
AI:

Even though we can’t show terminal colors in this document, imagine:

  • Blue title
  • Green AI responses
  • Yellow commands
  • Red error messages
  • Cyan user input prompt

The interface becomes much easier to read.


What Is Colorama?

Colorama is a Python library that adds color support to terminal applications. It works on:

  • Windows
  • macOS
  • Linux

It is one of the most popular libraries for creating colorful command-line applications.


Step 1: Install Colorama

Open your terminal and run:

pip install colorama

If you’re using Python 3:

pip3 install colorama


Step 2: Import Colorama

At the top of app.py, add:

from colorama import Fore, Style, init

Then initialize Colorama.

init(autoreset=True)

The autoreset=True option automatically resets the color after each print statement. This means you don’t have to reset the color manually every time.


Step 3: Color the Welcome Screen

Update your title.

Replace:

print("AI Assistant v1.0")

with:

print(Fore.BLUE + "AI Assistant v1.0")

Now your title appears in blue.


Step 4: Highlight the Current Personality

Replace:

print(f"Current Personality : {personality_name}")

with:

print(
    Fore.CYAN +
    f"Current Personality : {personality_name}"
)

Now the active personality is easier to identify.


Step 5: Color the Commands

Instead of:

print("/help")

use:

print(Fore.YELLOW + "/help")

Do the same for:

/help
/personality
/clear
/exit

Commands are now highlighted.


Step 6: Color AI Responses

Replace:

print("\nAI: ", end="")

with:

print(
    Fore.GREEN +
    "\nAI: ",
    end=""
)

Now every AI response starts in green.


Step 7: Color the User Prompt

Replace:

user_message = input("\nYou: ")

with:

user_message = input(
    Fore.CYAN + "\nYou: "
)

Now the user’s input prompt stands out from the AI’s response.


Step 8: Color Error Messages

Replace:

print("Something went wrong.")

with:

print(
    Fore.RED +
    "Something went wrong."
)

Error messages are now much easier to notice.


Example Color Scheme

A simple color scheme could look like this:

ItemColor
TitleBlue
Current PersonalityCyan
User PromptCyan
AI ResponseGreen
CommandsYellow
ErrorsRed

Using consistent colors makes your chatbot easier to understand.


Why Is This Better?

Without colors:

  • Everything looks the same.
  • Important messages are easy to miss.

With colors:

  • Easier to read
  • More professional
  • Better user experience
  • Clear separation between user and AI

Common Mistakes

Colors Don’t Appear

Make sure you installed Colorama.

pip install colorama


Forgot to Initialize

Always call:

init(autoreset=True)

before printing colored text.


All Text Stays the Same Color

If you don’t use:

init(autoreset=True)

or manually reset colors, later text may continue using the previous color.


Key Takeaways

  • Colorama adds colors to terminal applications.
  • Use colors consistently.
  • Highlight important information.
  • Colors improve readability and user experience.

Mini Quiz

1. Which library adds terminal colors?

A. pandas

B. numpy

C. colorama

D. requests

Answer: C


2. Which function initializes Colorama?

A. start()

B. run()

C. init()

D. begin()

Answer: C


3. Which color is a good choice for AI responses?

A. Green

B. Red

C. Black

D. White

Answer: A


4. Which color is commonly used for error messages?

A. Blue

B. Red

C. Green

D. Cyan

Answer: B


5. Why do we use colors?

A. To make the chatbot easier to read

B. To improve internet speed

C. To change the AI model

D. To reduce API usage

Answer: A


Practice Exercise

Complete these tasks.

  1. Install Colorama.
  2. Initialize it using init(autoreset=True).
  3. Color the welcome screen.
  4. Color the user prompt.
  5. Color AI responses.
  6. Color error messages.
  7. Test your chatbot and verify that each section uses a different color.

Lesson Summary

Excellent!

Your chatbot now looks much more professional. By using Colorama, you’ve created a colorful terminal interface that’s easier to read and more enjoyable to use. Although this change doesn’t affect how the AI works, it greatly improves the overall user experience.


Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top