(color)
| 48 | } |
| 49 | |
| 50 | showSourceCode(color) { |
| 51 | if (!this.source) return '' |
| 52 | |
| 53 | let css = this.source |
| 54 | if (color == null) color = pico.isColorSupported |
| 55 | |
| 56 | let aside = text => text |
| 57 | let mark = text => text |
| 58 | let highlight = text => text |
| 59 | if (color) { |
| 60 | let { bold, gray, red } = pico.createColors(true) |
| 61 | mark = text => bold(red(text)) |
| 62 | aside = text => gray(text) |
| 63 | if (terminalHighlight) { |
| 64 | highlight = text => terminalHighlight(text) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | let lines = css.split(/\r?\n/) |
| 69 | let start = Math.max(this.line - 3, 0) |
| 70 | let end = Math.min(this.line + 2, lines.length) |
| 71 | let maxWidth = String(end).length |
| 72 | |
| 73 | return lines |
| 74 | .slice(start, end) |
| 75 | .map((line, index) => { |
| 76 | let number = start + 1 + index |
| 77 | let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ' |
| 78 | if (number === this.line) { |
| 79 | if (line.length > 160) { |
| 80 | let padding = 20 |
| 81 | let subLineStart = Math.max(0, this.column - padding) |
| 82 | let subLineEnd = Math.max( |
| 83 | this.column + padding, |
| 84 | this.endColumn + padding |
| 85 | ) |
| 86 | let subLine = line.slice(subLineStart, subLineEnd) |
| 87 | |
| 88 | let spacing = |
| 89 | aside(gutter.replace(/\d/g, ' ')) + |
| 90 | line |
| 91 | .slice(0, Math.min(this.column - 1, padding - 1)) |
| 92 | .replace(/[^\t]/g, ' ') |
| 93 | |
| 94 | return ( |
| 95 | mark('>') + |
| 96 | aside(gutter) + |
| 97 | highlight(subLine) + |
| 98 | '\n ' + |
| 99 | spacing + |
| 100 | mark('^') |
| 101 | ) |
| 102 | } |
| 103 | |
| 104 | let spacing = |
| 105 | aside(gutter.replace(/\d/g, ' ')) + |
| 106 | line.slice(0, this.column - 1).replace(/[^\t]/g, ' ') |
| 107 |
no test coverage detected