• Stars
    star
    105
  • Rank 326,730 (Top 7 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🖍 Paint your console from .NET

build nuget

🖍 Crayon

An easy peasy tiny library for coloring console output in inline strings using ANSI escape codes.

V2

The API has changed to support background colors. I dropped the extension methods on string and opted for the using static directive instead. All methods now have an overload for direct input so you no longer have to end with a Text() invocation.

Examples

using static Crayon.Output;

Console.WriteLine(Green($"green {Red($"{Bold("bold")} red")} green"));
Console.WriteLine(Bright.Blue($"Bright {Green("and normal green")}"));
Console.WriteLine(Bold().Green().Text($"starting green {Red("then red")} must be green again"));

screenshot

Colors

Black()
Red()
Green()
Yellow()
Blue()
Magenta()
Cyan()
White()
Rgb(r, g, b)
Background.Blue()
Bright.Blue()

Decorations

Bold()
Dim()
Underline()
Reversed()

Text

Blue().Underline().Text("input")
Blue().Underline("input")

All colors and decorations have an overload with direct input and terminating the formatter.

Rainbows 🌈

Thanks to DevinR528 we now have rainbows!

var rainbow = new Rainbow(0.5);
for(var i = 0; i < 15; i++)
{
    Console.WriteLine(rainbow.Next().Bold().Text("rainbow"));
}

How compatible is it?

It works fine on everything except for older Windows versions.

Credits

My journey for using ANSI codes in C# first brought me here: https://www.jerriepelser.com/blog/using-ansi-color-codes-in-net-console-apps/

The ANSI coloring details was inspired by this blog post: http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html

The code for enabling ANSI colors feature on Windows was borrowed from this issue: microsoft/WSL#1873

No greater compliment than someone taking your work for inspiration. In return I peaked into his code for the RGB support!

More Repositories

1

AzureFunctions.TestHelpers

Test your Azure Functions! ⚡
C#
59
star
2

Unmockable

💉 ↪️ 🎁 Unmockable objects wrapping in .NET
C#
41
star
3

BoxstarterPackages

My wrongly named chocolatey packages repository. See the url for the AU results.
PowerShell
31
star
4

hypothesist

🧐 Hypothesise about future events and validate from a test!
C#
18
star
5

CloudEventify

C#
16
star
6

vsts-tasks-packer

TypeScript
15
star
7

efcore-practices

Attempt to capture some good or best practices in an API that supports testing
C#
11
star
8

gitviz

🔬 Visualize the directed acyclic graph that is your repository!
Shell
9
star
9

Dapr.Wrapr

start and stop a dapr.io self-hosted sidecar from your integration tests
C#
9
star
10

Consoleum

Selenium for Console Apps
C#
7
star
11

azdev2gh

Migrate a Product Backlog from Azure DevOps to GitHub Issues
C#
5
star
12

Glitter

C#
4
star
13

iffy

⁉️ use conditions in your builders
C#
4
star
14

PolymorphicJsonTypeInfoResolver

C#
3
star
15

CommandLiners

C#
2
star
16

dotnet-core-loves-docker

dotnet core ❤ docker
CSS
2
star
17

setvar

Transform output from a tool into pipeline variables in Azure Pipelines
Go
2
star
18

stryker-baseline-reporter

A baseline reporter for the excellent JavaScript mutation testing framework /Stryker/
TypeScript
2
star
19

EDA

C#
1
star
20

linq2xml

C#
1
star
21

sudffler

C#
1
star
22

azcopy-azure-function

Bicep
1
star
23

user-story-mapping-exercise

CSS
1
star
24

centric

C#
1
star
25

cnetin1

C#
1
star
26

AzureDevOpsRest

Testable and Extensible REST Client for Azure DevOps
C#
1
star
27

azure-functions-tdd

C#
1
star
28

dapr-community-call-demo

C#
1
star
29

CodeQuality

C#
1
star
30

terraform-github-training-repository-apssd

Setup repositories for students in the Scrum.org APS-SD training.
HCL
1
star