Skip to content

Commit

Permalink
fix: show topic list without extra newline
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 20, 2018
1 parent c879408 commit 89d0bc5
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 163 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
"bugs": "https://github.com/oclif/plugin-help/issues",
"dependencies": {
"@oclif/command": "^1.4.13",
"chalk": "^2.3.2",
"chalk": "^2.4.0",
"indent-string": "^3.2.0",
"lodash.template": "^4.4.0",
"string-width": "^2.1.1",
"widest-line": "^2.0.0",
"wrap-ansi": "^3.0.1"
},
"devDependencies": {
"@oclif/config": "^1.6.2",
"@oclif/dev-cli": "^1.12.1",
"@oclif/config": "^1.6.6",
"@oclif/dev-cli": "^1.13.3",
"@oclif/errors": "^1.0.4",
"@oclif/plugin-legacy": "^1.0.9",
"@oclif/plugin-plugins": "^1.0.8",
"@oclif/test": "^1.0.4",
"@oclif/plugin-legacy": "^1.0.11",
"@oclif/plugin-plugins": "^1.0.9",
"@oclif/test": "^1.0.5",
"@oclif/tslint": "^1.1.0",
"@types/chai": "^4.1.2",
"@types/chai": "^4.1.3",
"@types/indent-string": "^3.0.0",
"@types/lodash.template": "^4.4.3",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.2",
"@types/mocha": "^5.2.0",
"@types/node": "^9.6.6",
"@types/strip-ansi": "^3.0.0",
"@types/wrap-ansi": "^3.0.0",
"chai": "^4.1.2",
"concurrently": "^3.5.1",
"globby": "^8.0.1",
"mocha": "^5.0.5",
"mocha": "^5.1.1",
"strip-ansi": "^4.0.0",
"ts-node": "^5.0.1",
"ts-node": "^6.0.0",
"tslint": "^5.9.1",
"typescript": "^2.8.1"
"typescript": "^2.8.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export default class Help {
let body = renderList(topics.map(c => [
c.name,
c.description && this.render(c.description.split('\n')[0])
]), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2})
]), {
spacer: '\n',
stripAnsi: this.opts.stripAnsi,
maxWidth: this.opts.maxWidth - 2,
})
return [
bold('COMMANDS'),
indent(body, 2),
Expand Down
7 changes: 4 additions & 3 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const wrap = require('wrap-ansi')

const widestLine = require('widest-line')

export function renderList(input: (string | undefined)[][], opts: {maxWidth: number, multiline?: boolean, stripAnsi?: boolean}): string {
export function renderList(input: (string | undefined)[][], opts: {maxWidth: number, multiline?: boolean, stripAnsi?: boolean, spacer?: string}): string {
if (input.length === 0) {
return ''
}
Expand All @@ -30,7 +30,7 @@ export function renderList(input: (string | undefined)[][], opts: {maxWidth: num
if (opts.multiline) return renderMultiline()
const maxLength = widestLine(input.map(i => i[0]).join('\n'))
let output = ''
let spacer = '\n'
let spacer = opts.spacer || '\n'
let cur = ''
for (let [left, right] of input) {
if (cur) {
Expand All @@ -54,7 +54,8 @@ export function renderList(input: (string | undefined)[][], opts: {maxWidth: num
}
// if we start putting too many lines down, render in multiline format
if (lines.length > 4) return renderMultiline()
spacer = '\n\n'
// if spacer is not defined, separate all rows with extra newline
if (!opts.spacer) spacer = '\n\n'
cur += '\n'
cur += indent(lines.join('\n'), maxLength + 2)
}
Expand Down
Loading

0 comments on commit 89d0bc5

Please sign in to comment.