MCPcopy Index your code
hub / github.com/vercel/hyper / render

Method render

bin/yarn-standalone.js:117315–117380  ·  view source on GitHub ↗
(content, bottomContent)

Source from the content-addressed store, hash-verified

117313 }
117314
117315 render(content, bottomContent) {
117316 this.rl.output.unmute();
117317 this.clean(this.extraLinesUnderPrompt);
117318
117319 /**
117320 * Write message to screen and setPrompt to control backspace
117321 */
117322
117323 var promptLine = lastLine(content);
117324 var rawPromptLine = stripAnsi(promptLine);
117325
117326 // Remove the rl.line from our prompt. We can't rely on the content of
117327 // rl.line (mainly because of the password prompt), so just rely on it's
117328 // length.
117329 var prompt = rawPromptLine;
117330 if (this.rl.line.length) {
117331 prompt = prompt.slice(0, -this.rl.line.length);
117332 }
117333 this.rl.setPrompt(prompt);
117334
117335 // SetPrompt will change cursor position, now we can get correct value
117336 var cursorPos = this.rl._getCursorPos();
117337 var width = this.normalizedCliWidth();
117338
117339 content = this.forceLineReturn(content, width);
117340 if (bottomContent) {
117341 bottomContent = this.forceLineReturn(bottomContent, width);
117342 }
117343 // Manually insert an extra line if we're at the end of the line.
117344 // This prevent the cursor from appearing at the beginning of the
117345 // current line.
117346 if (rawPromptLine.length % width === 0) {
117347 content += '\n';
117348 }
117349 var fullContent = content + (bottomContent ? '\n' + bottomContent : '');
117350 this.rl.output.write(fullContent);
117351
117352 /**
117353 * Re-adjust the cursor at the correct position.
117354 */
117355
117356 // We need to consider parts of the prompt under the cursor as part of the bottom
117357 // content in order to correctly cleanup and re-render.
117358 var promptLineUpDiff = Math.floor(rawPromptLine.length / width) - cursorPos.rows;
117359 var bottomContentHeight =
117360 promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
117361 if (bottomContentHeight > 0) {
117362 util.up(this.rl, bottomContentHeight);
117363 }
117364
117365 // Reset cursor at the beginning of the line
117366 util.left(this.rl, stringWidth(lastLine(fullContent)));
117367
117368 // Adjust cursor on the right
117369 if (cursorPos.cols > 0) {
117370 util.right(this.rl, cursorPos.cols);
117371 }
117372

Callers

nothing calls this directly

Calls 6

cleanMethod · 0.95
normalizedCliWidthMethod · 0.95
forceLineReturnMethod · 0.95
lastLineFunction · 0.85
heightFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected