GithubHelp home page GithubHelp logo

crayon's Introduction

build nuget

Crayon

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

Examples

Console.WriteLine(Output.Green($"green {Output.Red($"{Output.Bold("bold")} red")} green"));
Console.WriteLine("normal");
Console.WriteLine(Output.BrightBlue($"Bright {Output.Green("and normal green")}"));
Console.WriteLine(Output.Green($"The difference {Output.Bold("between bold")} and {Output.BrightGreen("bright green")}"));
Console.WriteLine(Output.Green().Bold().Underline().Reversed().Text("hoi!"));
Console.WriteLine(Output.Bold().Green().Text($"starting green {Output.Red("then red")} must be green again"));

screenshot

Two modes

The static methods accepting string input Output.Red("input") return formatted string output. This also works with nested interpolated strings Output.Red($"input {Output.Bold("bold")}").

Or building up a formatter using Output.Bold().Red().Text("input") where the string is only returned after closing with the Text method. This can also be mixed with interpolated strings.

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!

crayon's People

Contributors

riezebosch avatar dependabot-preview[bot] avatar jamjar00 avatar devinragotzy avatar nikeee avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.