-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import stripAnsi from 'strip-ansi' | ||
import stripFinalNewline from 'strip-final-newline' | ||
|
||
import { FORMATS } from './formats/list.js' | ||
import { addPadding } from './utils/indent.js' | ||
import { wrapRows } from './utils/wrap.js' | ||
|
||
// Handle content returned by `reporter.report()`. | ||
// We purposely do not remove empty lines before/after the `content` since those | ||
// might be used to avoid vertical jitter when the reporter knows those empty | ||
// lines will be eventually filled (e.g. when combinations stats become | ||
// available). | ||
export const handleContent = function ({ content, output, format, colors }) { | ||
const contentA = handleColors(content, colors) | ||
const contentB = trimEnd(contentA) | ||
const contentC = wrapRows(contentB) | ||
const contentD = padContents(contentC, format) | ||
return { content: contentD, output } | ||
} | ||
|
||
// Reporters should always assume `colors` are true, but the core remove this | ||
// from the returned content if not. | ||
const handleColors = function (content, colors) { | ||
return colors ? content : stripAnsi(content) | ||
} | ||
|
||
// Trim the end of each line to avoid wrapping-related visual bugs | ||
const trimEnd = function (content) { | ||
return content.split('\n').map(trimEndLine).join('\n') | ||
} | ||
|
||
const trimEndLine = function (line) { | ||
return line.trimEnd() | ||
} | ||
|
||
const padContents = function (joinedContents, format) { | ||
if (FORMATS[format].padding === undefined) { | ||
return joinedContents | ||
} | ||
|
||
const joinedContentsA = `${stripFinalNewline(joinedContents)}\n` | ||
return addPadding(joinedContentsA) | ||
} |