Skip to content

Commit 89d0bc5

Browse files
committed
fix: show topic list without extra newline
1 parent c879408 commit 89d0bc5

File tree

4 files changed

+112
-163
lines changed

4 files changed

+112
-163
lines changed

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
"bugs": "https://github.com/oclif/plugin-help/issues",
77
"dependencies": {
88
"@oclif/command": "^1.4.13",
9-
"chalk": "^2.3.2",
9+
"chalk": "^2.4.0",
1010
"indent-string": "^3.2.0",
1111
"lodash.template": "^4.4.0",
1212
"string-width": "^2.1.1",
1313
"widest-line": "^2.0.0",
1414
"wrap-ansi": "^3.0.1"
1515
},
1616
"devDependencies": {
17-
"@oclif/config": "^1.6.2",
18-
"@oclif/dev-cli": "^1.12.1",
17+
"@oclif/config": "^1.6.6",
18+
"@oclif/dev-cli": "^1.13.3",
1919
"@oclif/errors": "^1.0.4",
20-
"@oclif/plugin-legacy": "^1.0.9",
21-
"@oclif/plugin-plugins": "^1.0.8",
22-
"@oclif/test": "^1.0.4",
20+
"@oclif/plugin-legacy": "^1.0.11",
21+
"@oclif/plugin-plugins": "^1.0.9",
22+
"@oclif/test": "^1.0.5",
2323
"@oclif/tslint": "^1.1.0",
24-
"@types/chai": "^4.1.2",
24+
"@types/chai": "^4.1.3",
2525
"@types/indent-string": "^3.0.0",
2626
"@types/lodash.template": "^4.4.3",
27-
"@types/mocha": "^5.0.0",
28-
"@types/node": "^9.6.2",
27+
"@types/mocha": "^5.2.0",
28+
"@types/node": "^9.6.6",
2929
"@types/strip-ansi": "^3.0.0",
3030
"@types/wrap-ansi": "^3.0.0",
3131
"chai": "^4.1.2",
3232
"concurrently": "^3.5.1",
3333
"globby": "^8.0.1",
34-
"mocha": "^5.0.5",
34+
"mocha": "^5.1.1",
3535
"strip-ansi": "^4.0.0",
36-
"ts-node": "^5.0.1",
36+
"ts-node": "^6.0.0",
3737
"tslint": "^5.9.1",
38-
"typescript": "^2.8.1"
38+
"typescript": "^2.8.3"
3939
},
4040
"engines": {
4141
"node": ">=8.0.0"

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ export default class Help {
118118
let body = renderList(topics.map(c => [
119119
c.name,
120120
c.description && this.render(c.description.split('\n')[0])
121-
]), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2})
121+
]), {
122+
spacer: '\n',
123+
stripAnsi: this.opts.stripAnsi,
124+
maxWidth: this.opts.maxWidth - 2,
125+
})
122126
return [
123127
bold('COMMANDS'),
124128
indent(body, 2),

src/list.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const wrap = require('wrap-ansi')
66

77
const widestLine = require('widest-line')
88

9-
export function renderList(input: (string | undefined)[][], opts: {maxWidth: number, multiline?: boolean, stripAnsi?: boolean}): string {
9+
export function renderList(input: (string | undefined)[][], opts: {maxWidth: number, multiline?: boolean, stripAnsi?: boolean, spacer?: string}): string {
1010
if (input.length === 0) {
1111
return ''
1212
}
@@ -30,7 +30,7 @@ export function renderList(input: (string | undefined)[][], opts: {maxWidth: num
3030
if (opts.multiline) return renderMultiline()
3131
const maxLength = widestLine(input.map(i => i[0]).join('\n'))
3232
let output = ''
33-
let spacer = '\n'
33+
let spacer = opts.spacer || '\n'
3434
let cur = ''
3535
for (let [left, right] of input) {
3636
if (cur) {
@@ -54,7 +54,8 @@ export function renderList(input: (string | undefined)[][], opts: {maxWidth: num
5454
}
5555
// if we start putting too many lines down, render in multiline format
5656
if (lines.length > 4) return renderMultiline()
57-
spacer = '\n\n'
57+
// if spacer is not defined, separate all rows with extra newline
58+
if (!opts.spacer) spacer = '\n\n'
5859
cur += '\n'
5960
cur += indent(lines.join('\n'), maxLength + 2)
6061
}

0 commit comments

Comments
 (0)