Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
Functions
color.c File Reference

Implementation of terminal color support detection. More...

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "color.h"
#include <unistd.h>
Include dependency graph for color.c:

Functions

bool terminal_supports_color (void)
 Checks if the current terminal supports ANSI color escape sequences.
 

Detailed Description

Implementation of terminal color support detection.

This module provides the function terminal_supports_color() which detects if the current terminal supports ANSI color escape sequences. It caches the result to avoid redundant system calls.

On Windows, it attempts to enable ANSI support on modern terminals (Windows Terminal, VS Code terminal, ConEmu, Cmder) by enabling virtual terminal processing. On Unix-like systems, it checks environment variables and terminal capabilities to determine color support.

Note
The function uses platform-specific APIs and environment variables.
Author
Connor Harris
Date
2025

Function Documentation

◆ terminal_supports_color()

bool terminal_supports_color ( void  )

Checks if the current terminal supports ANSI color escape sequences.

Checks if the terminal supports ANSI color escape sequences.

This function determines whether the terminal connected to standard output supports colored output using ANSI escape sequences.

The result is cached after the first call for efficiency.

On Windows:

  • Detects Windows Terminal, VS Code terminal, ConEmu, Cmder via environment variables.
  • Attempts to enable ANSI escape code processing via the console API.
  • Checks Windows version for fallback support.

On Unix/Linux:

  • Checks TERM environment variable for common terminal types supporting color.
  • Uses tput colors command to verify the number of colors supported.
Returns
true if ANSI color output is supported, false otherwise.