Giter Site home page Giter Site logo

colors.net's Introduction

Colors.Net

Colors.Net

Installation:

PS> Install-Package Colors.Net

Basic usage:

using Colors.Net;

ColoredConsole.WriteLine("Hello, World");
ColoredConsole.Write("Hello, World");

So it's pretty much the same surface as System.Console. However, to add color, all you have to do is either

using Colors.Net.StringColorExtensions;

ColoredConsole.WriteLine($"{"Hello".Red()}, world!");

or

using static Colors.Net.StringStaticMethods;

ColoredConsole.WriteLine($"{Red("Hello")}, World");

Since this is just manipulating strings, it's very easy to use which ever pattern you like. I personally like:

using Colors.Net.StringColorExtensions;

var @hello = "Hello".Red();

ColoredConsole.WriteLine($"{@hello}, World");

and the result of course is the same in all 2 cases:

Hello, World!

Nested colors:

You can also use nested colors and they will work as you'd expect string concat to work. For example:

var @yellow = Yellow("I'm Yellow!");
var @red = Red("I'm Red!");
var @blue = "I'm Blue".Blue(); // just to show a different way

ColoredConsole
    .WriteLine($@"{Green($"I'm green yet {@yellow}, {@red}, {@blue} and back to green.")}");

and this prints:

Nested colors

Fluent-like Api:

I like chaining calls that logically make sense together. Anyway, WriteLine() and Write() return an instance of IConsoleWriter so you can chain WriteLine() and Write() calls. It looks something like this:

ColoredConsole
    .WriteLine($"{DarkCyan("Title:")} Welcome to My Cli")
    .WriteLine()
    .WriteLine($"{DarkCyan("Version:")} {Magenta("1.0.0")}");

and that prints:

Chaining

Performance cost:

ColoredConsole
    .WriteLine($@"{Green($"I'm green yet {@yellow}, {@red}, {@blue} and back to green.")}");

Has 0.1 msec overhead when compared to Console.WriteLine(). This is measured by the Runner project doing this 10,000 with an extra runtime of 1000 msec.

Credits:

The interface is inspired by colors.js.

Supported colors:

All colors in System.ConsoleColor enum.

colors.net's People

Contributors

ahmelsayed avatar fabiocav avatar

Stargazers

Ivan Navoznov avatar  avatar Kai Walter avatar William avatar RogerZeng avatar Bill Skrei avatar Jared Nance avatar

Watchers

 avatar James Cloos avatar

Forkers

fabiocav

colors.net's Issues

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.