[Pkg-javascript-commits] [node-ansi] 01/04: Add patch to provide a string API
Jérémy Lal
kapouer at moszumanska.debian.org
Tue Aug 5 21:46:33 UTC 2014
This is an automated email from the git hooks/post-receive script.
kapouer pushed a commit to branch master
in repository node-ansi.
commit ca128115bc61ab836c013a1df55d4c93e6555716
Author: Jérémy Lal <kapouer at melix.org>
Date: Tue Aug 5 23:42:09 2014 +0200
Add patch to provide a string API
---
debian/patches/str_api.patch | 50 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/debian/patches/str_api.patch b/debian/patches/str_api.patch
new file mode 100644
index 0000000..1ec431e
--- /dev/null
+++ b/debian/patches/str_api.patch
@@ -0,0 +1,50 @@
+From: Jérémy Lal <kapouer at melix.org>
+Last-Update: 2014-08-05
+Description: provide a simple string-oriented API that make this module
+ a straightforward replacement for ansicolors, ansistyles.
+Forwarded: https://github.com/TooTallNate/ansi.js/pull/17
+--- a/README.md
++++ b/README.md
+@@ -68,6 +68,9 @@
+
+ // Clean up after yourself!
+ cursor.reset()
++
++// a string-oriented API is provided too
++console.log(ansi.underline(ansi.bgGrey(ansi.red('this is red'))));
+ ```
+
+
+--- a/lib/ansi.js
++++ b/lib/ansi.js
+@@ -403,3 +403,30 @@
+ }
+ return rtn
+ }
++
++/**
++ * ansi.<color>(string), ansi.bg<Color>(string), ansi.<style>(string)
++ */
++
++function strHelper(g, key, str) {
++ var stream = {
++ str: '',
++ write: function(str) {this.str += str;},
++ on: function(){},
++ listeners: function() {return [];}
++ };
++ var cursor = ansi(stream, {enabled: true});
++ var the = g ? cursor[g] : cursor;
++ the[key]().write(str).reset();
++ return stream.str;
++}
++
++Object.keys(colors).forEach(function(key) {
++ var name = key.charAt(0).toUpperCase() + key.substring(1);
++ ansi[key] = strHelper.bind(undefined, 'fg', key);
++ ansi['bg' + name] = strHelper.bind(undefined, 'bg', key);
++});
++Object.keys(styles).forEach(function(key) {
++ ansi[key] = strHelper.bind(undefined, false, key);
++});
++
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ansi.git
More information about the Pkg-javascript-commits
mailing list