amishell
Version:
Interactive shell for the WinUAE and FS-UAE Amiga emulators.
111 lines • 4.62 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const amishell_1 = require("./amishell");
const readline = require("readline");
const versionLabel = "1.0";
var amishell;
parseArgs();
function parseArgs() {
return __awaiter(this, void 0, void 0, function* () {
let emulator = (process.platform === "win32") ? "winuae" : "fsuae";
const optionDefinitions = [
{ name: 'activate', alias: 'a', type: Boolean, defaultValue: false },
{ name: 'emulator', alias: 'e', type: String, defaultValue: emulator },
{ name: 'help', alias: 'h', type: Boolean },
{ name: 'port', alias: 'p', type: Number, defaultValue: 1234 },
{ name: 'timeout', alias: 't', type: Number, defaultValue: 500 },
{ name: 'version', alias: 'v', type: Boolean },
{ name: 'command', type: String, multiple: true, defaultOption: true }
];
const cliArgs = require('command-line-args');
const args = cliArgs(optionDefinitions, { partial: true });
if (args._unknown && args._unknown.length > 0) {
console.log("amishell: unrecognized option '" + args._unknown[0] + "'");
process.exit(1);
}
if (args.help) {
help();
}
if (args.version) {
version();
}
amishell = new amishell_1.AmiShell(args.emulator, args.port);
amishell.on("data", (data) => {
process.stdout.write(data);
});
amishell.on("error", (error) => {
console.error("[Communication with Amiga emulator failed]");
console.error(error.message);
terminate(1);
});
if (args.command) {
let command = args.command.join(" ");
yield amishell.executeCommand(command, args.activate, args.timeout);
process.exit(0);
}
shell(args.activate, args.timeout);
});
}
function help() {
console.log("Executes commands in a running Amiga emulator.");
console.log("Usage: [options] <command>");
console.log("\nOptions");
console.log("-a, --activate Activate (send to front) the emulator window");
console.log("-e, --emulator <emulator> Emulator in use (fsuae or winuae)");
console.log("-h, --help Show this help");
console.log("-p, --port <port> Port used by the emulator for serial comm. (default = 1234)");
console.log("-t, --timeout <timeout> Timeout in milliseconds (default = 500)");
console.log("-v, --version Show the version number");
console.log("\nSpecify no <command> to enter Shell mode.");
process.exit(0);
}
function version() {
console.log("amishell v" + versionLabel);
process.exit(0);
}
function shell(activate, timeout) {
return __awaiter(this, void 0, void 0, function* () {
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let busy = false;
yield prompt(rl);
rl.on('line', (command) => __awaiter(this, void 0, void 0, function* () {
if (!busy) {
busy = true;
yield amishell.executeCommand("", false, 100, true);
if (amishell.eot) {
yield amishell.executeCommand(command, activate, timeout);
}
yield prompt(rl);
busy = false;
}
}));
rl.on('close', () => {
console.log('\n[Terminated by user]');
terminate();
});
});
}
function prompt(rl) {
return __awaiter(this, void 0, void 0, function* () {
let cwd = yield amishell.executeCommand("cd", false, 250, true);
cwd = amishell.eot ? cwd.replace("\n", "") + "> " : "";
rl.setPrompt(cwd);
rl.prompt();
});
}
function terminate(code = 0) {
process.exit(code);
}
//# sourceMappingURL=main.js.map