|
12 | 12 | ? function (s, p) { return s.startsWith(p); } |
13 | 13 | : function (s, p) { return s.indexOf(p) === 0; }; |
14 | 14 |
|
15 | | - /** |
16 | | - * Repeats the given string some number of times. |
17 | | - * |
18 | | - * This is just a polyfill for `String.prototype.repeat`. |
19 | | - * |
20 | | - * @param {string} str |
21 | | - * @param {number} times |
22 | | - * @returns {string} |
23 | | - */ |
24 | | - function repeat(str, times) { |
25 | | - var s = ''; |
26 | | - for (var i = 0; i < times; i++) { |
27 | | - s += str; |
| 15 | + // Support for IE11 that has no endsWith() |
| 16 | + /** @type {(str: string, suffix: string) => boolean} */ |
| 17 | + var endsWith = ''.endsWith |
| 18 | + ? function (str, suffix) { |
| 19 | + return str.endsWith(suffix); |
28 | 20 | } |
29 | | - return s; |
30 | | - } |
| 21 | + : function (str, suffix) { |
| 22 | + var len = str.length; |
| 23 | + return str.substring(len - suffix.length, len) === suffix; |
| 24 | + }; |
31 | 25 |
|
32 | 26 | /** |
33 | 27 | * Returns whether the given hook environment has a command line info object. |
|
79 | 73 | } |
80 | 74 |
|
81 | 75 | var codeLines = env.code.split('\n'); |
| 76 | + |
| 77 | + var continuationLineIndicies = commandLine.continuationLineIndicies = new Set(); |
| 78 | + var lineContinuationStr = pre.getAttribute('data-continuation-str'); |
| 79 | + |
| 80 | + // Identify code lines that are a continuation line and thus don't need |
| 81 | + // a prompt |
| 82 | + if (lineContinuationStr && codeLines.length > 1) { |
| 83 | + for (var j = 1; j < codeLines.length; j++) { |
| 84 | + if (codeLines.hasOwnProperty(j - 1) |
| 85 | + && endsWith(codeLines[j - 1], lineContinuationStr)) { |
| 86 | + // Mark this line as being a continuation line |
| 87 | + continuationLineIndicies.add(j); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
82 | 92 | commandLine.numberOfLines = codeLines.length; |
83 | 93 | /** @type {string[]} */ |
84 | 94 | var outputLines = commandLine.outputLines = []; |
|
168 | 178 | } |
169 | 179 |
|
170 | 180 | // Create the "rows" that will become the command-line prompts. -- cwells |
171 | | - var promptLines; |
| 181 | + var promptLines = ''; |
172 | 182 | var rowCount = commandLine.numberOfLines || 0; |
173 | 183 | var promptText = getAttribute('data-prompt', ''); |
| 184 | + var promptLine; |
174 | 185 | if (promptText !== '') { |
175 | | - promptLines = repeat('<span data-prompt="' + promptText + '"></span>', rowCount); |
| 186 | + promptLine = '<span data-prompt="' + promptText + '"></span>'; |
176 | 187 | } else { |
177 | 188 | var user = getAttribute('data-user', 'user'); |
178 | 189 | var host = getAttribute('data-host', 'localhost'); |
179 | | - promptLines = repeat('<span data-user="' + user + '" data-host="' + host + '"></span>', rowCount); |
| 190 | + promptLine = '<span data-user="' + user + '" data-host="' + host + '"></span>'; |
| 191 | + } |
| 192 | + |
| 193 | + var continuationLineIndicies = commandLine.continuationLineIndicies || new Set(); |
| 194 | + var continuationPromptText = getAttribute('data-continuation-prompt', '>'); |
| 195 | + var continuationPromptLine = '<span data-continuation-prompt="' + continuationPromptText + '"></span>'; |
| 196 | + |
| 197 | + // Assemble all the appropriate prompt/continuation lines |
| 198 | + for (var j = 0; j < rowCount; j++) { |
| 199 | + if (continuationLineIndicies.has(j)) { |
| 200 | + promptLines += continuationPromptLine; |
| 201 | + } else { |
| 202 | + promptLines += promptLine; |
| 203 | + } |
180 | 204 | } |
181 | 205 |
|
182 | 206 | // Create the wrapper element. -- cwells |
|
0 commit comments