Skip to content

Commit

Permalink
Support CJK characters (piuccio#27)
Browse files Browse the repository at this point in the history
* Support CJK characters

* fix stdin
  • Loading branch information
piuccio authored Aug 25, 2017
1 parent 1d17990 commit 93222b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (argv.l) {
} else if (argv._.length) {
say();
} else {
require("get-stdin")(function (data) {
require("get-stdin")().then(function (data) {
if (data) {
argv._ = [data];
say();
Expand Down
8 changes: 5 additions & 3 deletions lib/balloon.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var stringWidth = require("string-width");

exports.say = function (text, wrap) {
var delimiters = {
first : ["/", "\\"],
Expand Down Expand Up @@ -83,16 +85,16 @@ function split (text, wrap) {
function max (lines) {
var max = 0;
for (var i = 0, len = lines.length; i < len; i += 1) {
if (lines[i].length > max) {
max = lines[i].length;
if (stringWidth(lines[i]) > max) {
max = stringWidth(lines[i]);
}
}

return max;
}

function pad (text, length) {
return text + (new Array(length - text.length + 1)).join(" ");
return text + (new Array(length - stringWidth(text) + 1)).join(" ");
}

function top (length) {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
"test": "node test.js"
},
"dependencies": {
"get-stdin": "^4.0.1",
"optimist": "~0.6.1"
"get-stdin": "^5.0.1",
"optimist": "~0.6.1",
"string-width": "~2.1.1"
},
"devDependencies": {
"nodeunit": "~0.11.1",
"rollup": "^0.47.4",
"rollup-plugin-commonjs": "^8.1.0",
"rollup": "^0.48.2",
"rollup-plugin-commonjs": "^8.2.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-string": "^2.0.2"
},
Expand Down
10 changes: 5 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import nodeResolve from 'rollup-plugin-node-resolve';
import string from 'rollup-plugin-string';

export default {
entry: 'browser.js',
input: 'browser.js',
plugins: [
nodeResolve({
module: true,
Expand All @@ -14,9 +14,9 @@ export default {
include: '**/*.cow',
}),
],
moduleName: 'cowsay',
targets: [
{ dest: 'build/cowsay.umd.js', format: 'umd' },
{ dest: 'build/cowsay.es.js', format: 'es' },
name: 'cowsay',
output: [
{ file: 'build/cowsay.umd.js', format: 'umd' },
{ file: 'build/cowsay.es.js', format: 'es' },
]
}

0 comments on commit 93222b8

Please sign in to comment.