Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cjk width problem on usage table #297

Merged
merged 2 commits into from Nov 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:',
' 안녕하세요 선생님 안녕 친구야 인사하는 어린이 착한 어린이',
''
])
})
})
})