Pastel 4.1.0

.NET 6.0 .NET Framework 4.6.2
dotnet add package Pastel --version 4.1.0
NuGet\Install-Package Pastel -Version 4.1.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="4.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pastel --version 4.1.0
#r "nuget: Pastel, 4.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pastel as a Cake Addin
#addin nuget:?package=Pastel&version=4.1.0

// Install Pastel as a Cake Tool
#tool nuget:?package=Pastel&version=4.1.0

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 codes 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 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 argument pairs very well with ReSharper as the extension automatically underlines the argument list and colors it accordingly:

ReSharper color object underlining

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 some reason want 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().

NO_COLOR

Pastel will 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 Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Framework net462 net463 net47 net471 net472 net48 net481
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (19)

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

GalacticWasteManagement

Package Description

ArtisticPastelPainter

Package Description

ConsoleSimulationEngine2000

Package Description

Xenial.Tasty.Reporters.Nyan

Tasty Nyan Reporter - Delicious dotnet testing

GitHub repositories (4)

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

Repository Stars
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.
AlanMorel/MapleServer2
MapleStory 2 Emulator
microsoft/OSSGadget
Collection of tools for analyzing open source packages.
Version Downloads Last updated
4.1.0 3,105 12/18/2022
4.0.2 1,265 11/24/2022
3.0.1 16,676 6/20/2022
3.0.0 36,975 11/17/2021
2.1.0 59,621 11/18/2020
1.3.2 29,868 5/12/2020
1.3.1 48,690 8/14/2019
1.3.0 55,462 3/29/2019
1.2.1 1,994 3/19/2019
1.2.0 486 3/17/2019
1.1.0 823 1/26/2019
1.0.0 728 12/4/2018

v4.1.0 Added support for ConsoleColor arguments