(repl)
| 1346 | } |
| 1347 | |
| 1348 | function defineDefaultCommands(repl) { |
| 1349 | repl.defineCommand('break', { |
| 1350 | help: 'Sometimes you get stuck, this gets you out', |
| 1351 | action: function() { |
| 1352 | this.clearBufferedCommand(); |
| 1353 | this.displayPrompt(); |
| 1354 | }, |
| 1355 | }); |
| 1356 | |
| 1357 | let clearMessage; |
| 1358 | if (repl.useGlobal) { |
| 1359 | clearMessage = 'Alias for .break'; |
| 1360 | } else { |
| 1361 | clearMessage = 'Break, and also clear the local context'; |
| 1362 | } |
| 1363 | repl.defineCommand('clear', { |
| 1364 | help: clearMessage, |
| 1365 | action: function() { |
| 1366 | this.clearBufferedCommand(); |
| 1367 | if (!this.useGlobal) { |
| 1368 | this.output.write('Clearing context...\n'); |
| 1369 | this.resetContext(); |
| 1370 | } |
| 1371 | this.displayPrompt(); |
| 1372 | }, |
| 1373 | }); |
| 1374 | |
| 1375 | repl.defineCommand('exit', { |
| 1376 | help: 'Exit the REPL', |
| 1377 | action: function() { |
| 1378 | this.close(); |
| 1379 | }, |
| 1380 | }); |
| 1381 | |
| 1382 | repl.defineCommand('help', { |
| 1383 | help: 'Print this help message', |
| 1384 | action: function() { |
| 1385 | const names = ArrayPrototypeSort(ObjectKeys(this.commands)); |
| 1386 | const longestNameLength = MathMaxApply( |
| 1387 | ArrayPrototypeMap(names, (name) => name.length), |
| 1388 | ); |
| 1389 | ArrayPrototypeForEach(names, (name) => { |
| 1390 | const cmd = this.commands[name]; |
| 1391 | const spaces = |
| 1392 | StringPrototypeRepeat(' ', longestNameLength - name.length + 3); |
| 1393 | const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`; |
| 1394 | this.output.write(line); |
| 1395 | }); |
| 1396 | this.output.write('\nPress Ctrl+C to abort current expression, ' + |
| 1397 | 'Ctrl+D to exit the REPL\n'); |
| 1398 | this.displayPrompt(); |
| 1399 | }, |
| 1400 | }); |
| 1401 | |
| 1402 | repl.defineCommand('save', { |
| 1403 | help: 'Save all evaluated commands in this REPL session to a file', |
| 1404 | action: function(file) { |
| 1405 | try { |
no test coverage detected
searching dependent graphs…