GithubHelp home page GithubHelp logo

paintbrush's Introduction

Paintbrush

build NPM Version codecov.io

Paintbrush is an ascii coloring tool for nodejs.

It depends only on util.inspect.

Synopsis

var paint = require ('paintbrush');

console.log (paint ('red', 'red text'));

console.log (paint ('red+black_bg', 'red text on black'));

paint.redOnBlack = paint.bind (paint, 'red+black_bg');
paint.error      = paint.bind (paint, "red+white_bg");
paint.path       = paint.cyan.bind (paint);

// actually this is main reason to publish another one module
console.log (paint.redOnBlack ('red text on black'));


// use to discard colors and repaint output from another program
var httpProcess = child_process.spawn (
	'/usr/bin/env',
	['dataflows', 'daemon', '--no-fork'], {
		stdio: ['pipe', 'pipe', 'pipe']
	}
);

httpProcess.stderr.on ('data', function (data) {
	// paint grey every string chunk without color information
	// to differentiate between server and client output
	process.stdout.write (paint.fillUnpainted ('grey', data.toString()));
});

httpProcess.stdout.on ('data', function (data) {
	if (verbose) {
		process.stdout.write (paint.fillUnpainted ('grey', data.toString()));
	}
	if (!ignoreStdout) shellOutput += data;
	if (!ignoreStdout) {
		var m = paint.stripColor (shellOutput).match (/http initiator running at http:\/\/([^:]+):([^\/]+)/);
		if (m) {
		// …
		}
	}
});

API

var paint = require ('paintbrush');

paint function allows you to write colored messages. First parameter is a color attribute specification. You can use bold, italic, underline and inverse modifiers; white, grey, black, blue, cyan, green, magenta, red and yellow colors; also every color you can use as background, just add _bg. Any following arguments joined with space character between them.

console.log (
	paint ("black+italic+cyan_bg", "will paint black italic text", "on cyan", "background")
);

paint.stripColor can be used to discard any color information from string. Also you can use paint.discardColor as an alias.

paint.fillUnpainted will fill any color-absent chunks to color you want. Take a look into example in Synopsis to get idea how it works.

paintbrush's People

Contributors

apla 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.