#!/usr/bin/env node const Chalk = require('chalk') const Clear = require('clear') const Figlet = require('figlet') const Inquirer = require('inquirer') const Clui = require('clui') const Assembler = require('../asm') const replPrompt = [ { name: '>', type: 'input', validate: value => value.length > 0 }, ] // commands for the cli. these catches every user action besides assembly/disassembly of instructions const COMMANDS = [ { description: "Clear the screen", variants : [ 'C', 'CLEAR','CLEAR()', ':C', 'CLR', 'CLR()' ], action : () => Clear() }, { description: "Show help screen", variants : [ 'H', 'HELP', 'HELP()', ':H' ], action : printHelpScreen }, { description: "Quit", variants : [ 'Q', 'QUIT', 'QUIT()', ':Q', ':Q!' ], action : () => { console.log("Bye!") process.exit(0) } } ] function printHelpScreen() { Clear() console.log("\n") console.log("\t" + "-".repeat(50)) COMMANDS.forEach(c => { console.log("\t" + c.description + " : ") console.log("\t" + c.variants.join("\t")) console.log("\t" + "-".repeat(50)) }) console.log("\n") } if (process.argv[2] === "-h" || process.argv[2] === "--help") { printHelpScreen() } else if (process.argv[2] === "-u") { const promptForInstruction = () => Inquirer.prompt(replPrompt).then(i => { printHelpScreen() let input = i['>'].toUpperCase() let inputIsCLICommand = false for (let i = 0; i < COMMANDS.length; i++) { const command = COMMANDS[i] if (command.variants.indexOf(input) !== -1) { inputIsCLICommand = true command.action() break } } if (inputIsCLICommand === false) { const spinner = new Clui.Spinner('Assembling...') spinner.start() const result = Assembler.asmLine(input) console.log(`Result: 0x${Number(result).toString(16)}`) spinner.stop() } promptForInstruction() }) printHelpScreen() promptForInstruction() } else { /* Read straight from stdin BEGIN */ const readline = require('readline') const readlineInterface = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false }) readlineInterface.on('line', input => { const result = Assembler.asmLine(input) console.log(`0x${Number(result).toString(16)}`) }) }