MCPcopy
hub / github.com/pallets/werkzeug / openShell

Function openShell

src/werkzeug/debug/shared/debugger.js:94–146  ·  view source on GitHub ↗

* Helper function for shell initialization

(consoleNode, target, frameID)

Source from the content-addressed store, hash-verified

92 * Helper function for shell initialization
93 */
94function openShell(consoleNode, target, frameID) {
95 promptForPin();
96 if (consoleNode) {
97 slideToggle(consoleNode);
98 return consoleNode;
99 }
100 let historyPos = 0;
101 const history = [""];
102 const consoleElement = createConsole();
103 const output = createConsoleOutput();
104 const form = createConsoleInputForm();
105 const command = createConsoleInput();
106
107 target.parentNode.appendChild(consoleElement);
108 consoleElement.append(output);
109 consoleElement.append(form);
110 form.append(command);
111 command.focus();
112 slideToggle(consoleElement);
113
114 form.addEventListener("submit", (e) => {
115 handleConsoleSubmit(e, command, frameID).then((consoleOutput) => {
116 output.append(consoleOutput);
117 command.focus();
118 consoleElement.scrollTo(0, consoleElement.scrollHeight);
119 const old = history.pop();
120 history.push(command.value);
121 if (typeof old !== "undefined") {
122 history.push(old);
123 }
124 historyPos = history.length - 1;
125 command.value = "";
126 });
127 });
128
129 command.addEventListener("keydown", (e) => {
130 if (e.key === "l" && e.ctrlKey) {
131 output.innerText = "--- screen cleared ---";
132 } else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
133 // Handle up arrow and down arrow.
134 if (e.key === "ArrowUp" && historyPos > 0) {
135 e.preventDefault();
136 historyPos--;
137 } else if (e.key === "ArrowDown" && historyPos < history.length - 1) {
138 historyPos++;
139 }
140 command.value = history[historyPos];
141 }
142 return false;
143 });
144
145 return consoleElement;
146}
147
148function addEventListenersToElements(elements, event, listener) {
149 elements.forEach((el) => el.addEventListener(event, listener));

Callers 2

addConsoleIconToFramesFunction · 0.85
createInteractiveConsoleFunction · 0.85

Calls 10

promptForPinFunction · 0.85
slideToggleFunction · 0.85
createConsoleFunction · 0.85
createConsoleOutputFunction · 0.85
createConsoleInputFormFunction · 0.85
createConsoleInputFunction · 0.85
handleConsoleSubmitFunction · 0.85
appendMethod · 0.80
popMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected