:sparkles: Add support for custom prompts in custom Termynal
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by Sebastián Ramírez · parent 95c1f10 · Browse files · 3 files·+25 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+25 added−8 removed
- other:+25 added−8 removed
Provenance
- Commit
13e0c8e- Tree
b162e8b- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
Sebastián Ramírez <tiangolo@gmail.com>- Parent
95c1f10
3 files changed+25 added−8 removed
modified:docs/css/custom.css+6 added-1 removed
1223456789.termynal-comment { color: #999; color: #4a968f; font-style: italic; display: block;}
.termy { white-space: pre-wrap;}modified:docs/js/custom.js+17 added-3 removed
4 unmodified lines567891011121315 unmodified lines29303132323333343536373816 unmodified lines5556575858596061626364656667686970717273747576777879808124 unmodified lines4 unmodified lines });});const progressLiteralStart = "---> 100%";const promptLiteralStart = "$ ";const customPromptLiteralStart = "# ";const termynalActivateClass = "termy";let termynals = [];
function createTermynals() {15 unmodified lines dataValue = {}; if (isBlankSpace) { dataValue["delay"] = 0; } if (buffer.length > 1 && buffer[buffer.length - 1] === "") { // The last single <br> won't have effect if (buffer[buffer.length - 1] === "") { // A last single <br> won't have effect // so put an additional one buffer.push(""); } const bufferValue = buffer.join("<br>");16 unmodified lines value: value }); } else if (line.startsWith("// ")) { saveBuffer(); const value = line.replace("// ", "").trimEnd(); const value = "💬 " + line.replace("// ", "").trimEnd(); useLines.push({ value: value, class: "termynal-comment", delay: 0 }); } else if (line.startsWith(customPromptLiteralStart)) { saveBuffer(); const promptStart = line.indexOf(promptLiteralStart); if (promptStart === -1) { console.error("Custom prompt found but no end delimiter", line) } const prompt = line.slice(0, promptStart).replace(customPromptLiteralStart, "") let value = line.slice(promptStart + promptLiteralStart.length); useLines.push({ type: "input", value: value, prompt: prompt }); } else { buffer.push(line); } }24 unmodified linesmodified:docs/js/termynal.js+2 added-4 removed
241 unmodified lines242 if (prop === 'class') {243 attrs += ` class=${line[prop]} `244 continue245 }246- attrs += this.pfx;247-246 if (prop === 'type') {249- attrs += `="${line[prop]}" `247+ attrs += `${this.pfx}="${line[prop]}" `248 } else if (prop !== 'value') {251- attrs += `-${prop}="${line[prop]}" `249+ attrs += `${this.pfx}-${prop}="${line[prop]}" `250 }251 }252 253 return attrs;11 unmodified lines