MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / init

Function init

tools/xsbug-log/xsbug-log.js:146–340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

144 },
145
146 init() {
147 this.loadPrefs();
148 this.rl = require('node:readline').createInterface({
149 input: process.stdin,
150 output: process.stdout,
151 prompt: '(xsdb) ',
152 completer: (line, callback) => {
153 const m = this.getMachine(this.activeThreadId);
154 if (m && typeof m.completer === 'function')
155 m.completer(line, callback);
156 else
157 callback(null, [[], line]);
158 }
159 });
160
161 // Suppress TAB processing while completions are displayed
162 const origTabComplete = this.rl._tabComplete;
163 this.rl._tabComplete = function(lastKeypressWasTab) {
164 const m = this.completer && this._router?.getMachine(this._router.activeThreadId);
165 if (m && m.completionsShown)
166 return;
167 origTabComplete.call(this, lastKeypressWasTab);
168 };
169 this.rl._router = this;
170
171 this.rl.on('line', (line) => {
172 const active = this.getMachine(this.activeThreadId);
173 if (active) active.promptShown = false;
174
175 const str = line.trim();
176 if (str === 'set mcsim on' || str === 'set mcsim off') {
177 this.showMcsim = str === 'set mcsim on';
178 this.savePrefs();
179 if (active) {
180 active.report('set', { showMcsim: this.showMcsim }, undefined, () => {
181 console.log(`mcsim thread: ${this.showMcsim ? 'on' : 'off'}`);
182 active.showPrompt();
183 });
184 } else {
185 console.log(`mcsim thread: ${this.showMcsim ? 'on' : 'off'}`);
186 }
187 return;
188 }
189 if (str.startsWith('info threads')) {
190 const threadsData = this.machines.map(m => {
191 if (!m) return null;
192 if (m.id === undefined) return null;
193 if (this.isHidden(m)) return null;
194 return {
195 id: m.id,
196 active: m.id === this.activeThreadId,
197 name: m.title || `worker-${m.id}`,
198 state: !m.connected ? 'Disconnected' : (m.running ? 'Running' : 'Stopped'),
199 path: (!m.connected || m.running) ? undefined : (m.currentPath || 'unknown'),
200 line: (!m.connected || m.running) ? undefined : (m.currentLine || '?')
201 };
202 }).filter(Boolean);
203

Callers 1

bme68x.jsFile · 0.85

Calls 15

completerMethod · 0.80
reportMethod · 0.80
showPromptMethod · 0.80
mapMethod · 0.80
handleCommandMethod · 0.80
commandErrorMethod · 0.80
printLocationMethod · 0.80
exitMethod · 0.80
doAbortMethod · 0.80
doStepMethod · 0.80
logMethod · 0.65
callbackFunction · 0.50

Tested by

no test coverage detected