Pastel 6.0.1
dotnet add package Pastel --version 6.0.1
NuGet\Install-Package Pastel -Version 6.0.1
<PackageReference Include="Pastel" Version="6.0.1" />
paket add Pastel --version 6.0.1
#r "nuget: Pastel, 6.0.1"
// Install Pastel as a Cake Addin #addin nuget:?package=Pastel&version=6.0.1 // Install Pastel as a Cake Tool #tool nuget:?package=Pastel&version=6.0.1
Pastel
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");
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))));
Using a Color
/ConsoleColor
argument pairs very well with ReSharper as the extension automatically underlines the argument list and colors it accordingly:
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");
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.
Support
Has this library helped you or proven to be useful in your project?
- Leave a star!
- Consider buying me a coffee with the link below! ⭐
<a href="https://www.buymeacoffee.com/silkfire" target="_blank" style="margin-left: 10px;"><img src="https://img.buymeacoffee.com/button-api/?textBuy me a coffee&emoji=☕&slug=silkfire&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff"></a>
Product | Versions 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. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- System.Memory (>= 4.6.0)
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (32)
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 |
|
Diginsight.Diagnostics
Package Description |
|
AgoraIoT.Edge.App.SDK
SDK for creation of Agora Edge Applications. |
|
ArtisticPastelPainter
Package Description |
GitHub repositories (7)
Showing the top 5 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.
|
|
ClassIsland/ClassIsland
一款适用于班级多媒体屏幕的课表的信息显示工具,可以一目了然地显示各种信息。
|
|
AlanMorel/MapleServer2
MapleStory 2 Emulator
|
|
microsoft/OSSGadget
Collection of tools for analyzing open source packages.
|
Version | Downloads | Last updated |
---|---|---|
6.0.1 | 1,847 | 12/6/2024 |
6.0.0 | 3,336 | 11/16/2024 |
5.2.1 | 12,144 | 10/26/2024 |
5.1.0 | 70,505 | 4/24/2024 |
5.0.0 | 36,537 | 1/20/2024 |
4.2.0 | 89,393 | 10/9/2023 |
4.1.0 | 97,579 | 12/18/2022 |
4.0.2 | 6,501 | 11/24/2022 |
3.0.1 | 47,683 | 6/20/2022 |
3.0.0 | 59,548 | 11/17/2021 |
2.1.0 | 78,398 | 11/18/2020 |
1.3.2 | 34,978 | 5/12/2020 |
1.3.1 | 59,860 | 8/14/2019 |
1.3.0 | 75,664 | 3/29/2019 |
1.2.1 | 2,928 | 3/19/2019 |
1.2.0 | 936 | 3/17/2019 |
1.1.0 | 1,763 | 1/26/2019 |
1.0.0 | 1,351 | 12/4/2018 |
v6.0.0 Dropped support for .NET 6; added support for .NET 9