Pastel 8.0.0

dotnet add package Pastel --version 8.0.0
                    
NuGet\Install-Package Pastel -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pastel" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pastel" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Pastel" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pastel --version 8.0.0
                    
#r "nuget: Pastel, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pastel@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pastel&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Pastel&version=8.0.0
                    
Install as a Cake Tool

Pastel

logo

NuGet NuGet

Give your console app a nicer look by adding some color to the output it produces. This is achieved by wrapping strings of the output in ANSI escape sequences that instruct the terminal to color the string based on the interpreted code. Tested on both Windows (requires at least Windows 10, v1511 [November Update]) and Linux.

Introduction

Modern terminals have a feature that allows them to print text in different colors. To enable this, a string is wrapped with a special sequence of characters containing a directive to the terminal to color the string that follows and stop coloring when it encounters an end code. Producing these character sequences can be cumbersome, which is the reason why I decided to build this small library that turns this into a very easy task.
Because Pastel only alters the output string, there is no need to manipulate or extend the built-in System.Console class.

If your terminal doesn't support 24-bit colors, it will approximate to the nearest color instead.

How to use

The basic syntax is very simple. Use the Pastel() method on the string you want to colorize and supply a color argument.

"ENTER".Pastel(Color.FromArgb(165, 229, 250))

Console.WriteLine($"Press {"ENTER".Pastel(Color.FromArgb(165, 229, 250))} to continue");

Example 1

You can either use a System.Drawing.Color object, a System.ConsoleColor enum or a hexadecimal string value.
Both upper and lower case hex codes are supported and the leading number sign (#) is optional.

var spectrum = new (string color, string letter)[]
{
    ("#124542", "a"),
    ("#185C58", "b"),
    ("#1E736E", "c"),
    ("#248A84", "d"),
    ("#20B2AA", "e"),
    ("#3FBDB6", "f"),
    ("#5EC8C2", "g"),
    ("#7DD3CE", "i"),
    ("#9CDEDA", "j"),
    ("#BBE9E6", "k")
};

Console.WriteLine(string.Join("", spectrum.Select(s => s.letter.Pastel(s.color))));

Example 2

Example 3

Using a Color/ConsoleColor argument pairs very well with ReSharper as the extension automatically underlines the argument list and colors it accordingly:

ReSharper color object underlining

ConsoleColor and web colors

By default, a ConsoleColor argument emits the corresponding ANSI base color code, which lets the terminal render it using its own theme. Pass useWebColors: true to instead emit the fixed web color that the value represents:

"Colorize me".Pastel(ConsoleColor.Red);                      // Themed by the terminal
"Colorize me".Pastel(ConsoleColor.Red, useWebColors: true);  // Always #FF0000

The web colors follow the combined CSS3 list. For the two names where the web and X11 definitions disagree, the web value is used:

Color Pastel X11
Gray #808080 #BEBEBE
Green #008000 #00FF00 (the web's Lime)

An inherited quirk worth knowing about: DarkGray (#A9A9A9) is lighter than Gray (#808080). DarkGray descends from X11 while Gray descends from the web, and the combined list keeps both. This is intentional and matches System.Drawing.Color.

Note that these are not the Windows console palette values (where Gray is #C0C0C0 and DarkGray is #808080).

Colors outside the 16 ConsoleColor names — such as Maroon or Purple — are reached through the Color or hexadecimal overloads:

"Colorize me".Pastel(Color.Maroon);   // #800000
"Colorize me".Pastel("#B03060");      // X11 Maroon

Background colors

Pastel also supports background colors. The syntax is exactly the same except that the method is called PastelBg.
Both foreground and background colors can be combined by chaining the methods:

"Colorize me".Pastel(Color.Black).PastelBg("FFD000");

Example 4

Disabling / enabling color output

If you for any reason would like to disable any future color output produced by Pastel for the duration of your app, simply call ConsoleExtensions.Disable(). To re-enable color output, call ConsoleExtensions.Enable().

CI/CD environments

Pastel will detect if your application is running under a common CI/CD environment and will disable all coloring if this is the case.
If you'd like to override this check and force colors in CI/CD environments, you can set an environment variable named PASTEL_DISABLE_ENVIRONMENT_DETECTION (value does not matter).

NO_COLOR

Pastel will also honor systems where console color output has explicitly been requested to be turned off. See more information about this initiative at https://no-color.org.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (36)

Showing the top 5 NuGet packages that depend on Pastel:

Package Downloads
FlubuCore

A cross platform build and deployment automation system for building projects and executing deployment scripts using C# code. Documentation can be found at: https://github.com/dotnetcore/FlubuCore Detailed examples can be found at: https://github.com/dotnetcore/FlubuCore.Examples

Diginsight.Diagnostics

Package Description

AgoraIoT.Edge.App.SDK

SDK for creation of Agora Edge Applications.

GalacticWasteManagement

Package Description

Sygenic.SharedKernel

Common code for Sygenic software

GitHub repositories (14)

Showing the top 14 popular GitHub repositories that depend on Pastel:

Repository Stars
LavaGang/MelonLoader
The World's First Universal Mod Loader for Unity Games compatible with both Il2Cpp and Mono
ClassIsland/ClassIsland
一款功能强、可定制、跨平台,适用于班级多媒体屏幕的课表信息显示工具,可以一目了然地显示各种信息。
SamboyCoding/Cpp2IL
Work-in-progress tool to reverse unity's IL2CPP toolchain.
dotnetcore/FlubuCore
A cross platform build and deployment automation system for building projects and executing deployment scripts using C# code.
microsoft/OSSGadget
Collection of tools for analyzing open source packages.
AlanMorel/MapleServer2
MapleStory 2 Emulator
aers/FFXIVClientStructs
Resources for reverse-engineering the FFXIV client's native classes.
MS2Community/Maple2
Server emulator for MapleStory2.
ActualLab/Fusion
Build real-time Blazor and MAUI apps while writing just 0.1% of the usual real-time update code. Handle 10× more API requests with the ActualLab.Rpc protocol—or 1000× more with Fusion’s transparent and perfectly coherent caching.
SECTL/SecRandom
一个易用的点名/抽奖软件,专为教育场景设计,让课堂点名更高效透明!
NotAdam/Lumina
A simple, performant and extensible framework for interacting with FFXIV game data
stride3d/stride-community-toolkit
Collection of helpers and extensions for Stride Game Engine developers. Simplifies and demonstrates common developer tasks building experiences for Stride with .NET.
AlizerUncaged/waifu-desktop
🎂 your waifu, right on your desktop!
FrostyToolsuite/FrostyToolsuite
The most advanced modding platform for games running on DICE's Frostbite game engine.
Version Downloads Last Updated
8.0.0 375 7/15/2026
7.0.1 168,870 10/29/2025
7.0.0 35,552 8/17/2025
6.0.1 207,331 12/6/2024
6.0.0 6,873 11/16/2024
5.2.1 64,734 10/26/2024
5.1.0 148,351 4/24/2024
5.0.0 48,982 1/20/2024
4.2.0 144,730 10/9/2023
4.1.0 143,680 12/18/2022
4.0.2 10,869 11/24/2022
3.0.1 52,110 6/20/2022
3.0.0 80,697 11/17/2021
Loading failed

v8.0.0
* Fix a crash on .NET Framework when a color string ended with a reset followed by a partial escape sequence
* Rename the ConsoleColor useLegacy parameter to useWebColors (breaking: recompile required if passed by name)
* Throw ArgumentOutOfRangeException instead of KeyNotFoundException for an undefined ConsoleColor value (breaking)
* Name the public parameter in the invalid hexadecimal color exception
* Only honor NO_COLOR when it is non-empty, as the specification requires
* Improve the performance of the ConsoleColor overloads and reduce allocations across all overloads