Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #297 from disjukr/cjk-width-patch
Browse files Browse the repository at this point in the history
Fix cjk width problem on usage table
  • Loading branch information
bcoe committed Nov 14, 2015
2 parents 9a0171e + 4cf7121 commit b4b4acf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/usage.js
Expand Up @@ -2,6 +2,7 @@
// failures, etc. keeps logging in one place.
var cliui = require('cliui')
var decamelize = require('decamelize')
var stringWidth = require('string-width')
var wsize = require('window-size')

module.exports = function (yargs, y18n) {
Expand Down Expand Up @@ -260,7 +261,7 @@ module.exports = function (yargs, y18n) {
}

table.forEach(function (v) {
width = Math.max(v[0].length, width)
width = Math.max(stringWidth(v[0]), width)
})

// if we've enabled 'wrap' we should limit
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"cliui": "^3.0.3",
"decamelize": "^1.1.1",
"os-locale": "^1.4.0",
"string-width": "^1.0.1",
"window-size": "^0.1.2",
"y18n": "^3.2.0"
},
Expand Down
18 changes: 18 additions & 0 deletions test/usage.js
Expand Up @@ -1748,4 +1748,22 @@ describe('usage tests', function () {
])
})
})

describe('cjk', function () {
it('should calculate width of cjk text correctly', function () {
var r = checkUsage(function () {
var y = yargs()
.example('안녕하세요 선생님 안녕 친구야', '인사하는 어린이 착한 어린이')
.wrap(80)

y.showHelp()
})

r.errors.join('\n').split(/\n+/).should.deep.equal([
'Examples:',
' 안녕하세요 선생님 안녕 친구야 인사하는 어린이 착한 어린이',
''
])
})
})
})

0 comments on commit b4b4acf

Please sign in to comment.