diff --git a/createAst.js b/createAst.js index 5f19326..466508f 100644 --- a/createAst.js +++ b/createAst.js @@ -78,5 +78,5 @@ export default function createAst(location) { log(location); log(ast); - return ast; + return ast || []; } \ No newline at end of file diff --git a/test/console.v b/lib/console.v similarity index 85% rename from test/console.v rename to lib/console.v index 0c5110c..6f428e2 100644 --- a/test/console.v +++ b/lib/console.v @@ -1,58 +1,60 @@ -static console; - -import chalk from 'chalk'; -import tk from 'terminal-kit'; -import ansi from 'sisteransi'; - -restore { - const {terminal} = tk; - terminal.on('key', function(name, matches, data) { - if (name === 'CTRL_C') { - process.exit(2); - } - }); - - this.write(ansi.cursor.hide); -} - -log(a) { - if(typeof a === 'number') a = chalk.yellow(a); - - // const string = a.toString(); - - process.stdout.write(a + '\n'); -} - -choice(message, choices, type) { - const {terminal} = tk; - type ??= 'string'; - - return new Promise(res => { - - // terminal.saveCursor(); - - for(const part of message.split(/\x1b\[39m/g)) { - terminal.cyan(part); - } - terminal.cyan('\n'); - - terminal.singleColumnMenu(choices, (error, response) => { - // terminal.restoreCursor(); - this.write(ansi.cursor.left + ansi.cursor.up(4 + response.selectedIndex)); - terminal.cyan(`${message} `); - terminal.grabInput(false); - // terminal.move - - terminal(response.selectedText + '\n').eraseDisplayBelow(); - if(type === 'string') { - res(response.selectedText); - } else { - res(response.selectedIndex); - } - }); - }); -} - -write(a) { - process.stdout.write(a); +static console; + +import chalk from 'chalk'; +import tk from 'terminal-kit'; +import ansi from 'sisteransi'; + +restore { + const {terminal} = tk; + terminal.on('key', function(name, matches, data) { + if (name === 'CTRL_C') { + process.exit(2); + } + }); + + this.write(ansi.cursor.hide); +} + +log(a) { + if(typeof a === 'number') a = chalk.yellow(a); + + // const string = a.toString(); + + process.stdout.write(a + '\n'); +} + +choice(message, choices, type) { + const {terminal} = tk; + type ??= 'string'; + + return new Promise(res => { + + for(const part of message.split(/\x1b\[39m/g)) { + terminal.cyan(part); + } + terminal.cyan('\n'); + + terminal.singleColumnMenu(choices, (error, response) => { + // terminal.restoreCursor(); + this.write(ansi.cursor.left + ansi.cursor.up(choices.length + 2)); + terminal.cyan(`${message} `); + terminal.grabInput(false); + // terminal.move + + terminal(response.selectedText + '\n').eraseDisplayBelow(); + if(type === 'string') { + res(response.selectedText); + } else { + res(response.selectedIndex); + } + }); + }); +} + +write(a) { + process.stdout.write(a); +} + +clear { + this.write(ansi.erase.screen); } \ No newline at end of file diff --git a/run.js b/run.js index 09cbfec..1f83c50 100755 --- a/run.js +++ b/run.js @@ -3,40 +3,33 @@ import debug from 'debug'; const log = debug('vogue:cli'); const systemLocation = resolve(process.argv[2]); -import { parse, resolve } from 'path'; +import { parse, resolve, dirname } from 'path'; import { readdirSync, lstatSync } from 'fs'; import _ from 'lodash'; import Module from './Module.js'; import System from './System.js'; import './extensions.js'; +import { fileURLToPath } from 'url'; // globals inside grammar context import minify from './minify.js'; const { get, set } = _; +const standardLibrary = resolve(fileURLToPath(dirname(import.meta.url)), 'lib'); (async () => { // TODO simplify this line gaddam log('reading', systemLocation, '...'); - const files = readdirSync(systemLocation); + const files = [ + ...readdirSync(systemLocation).map(v => resolve(systemLocation, v)), + ...readdirSync(standardLibrary).map(v => resolve(standardLibrary, v)) + ]; const fullpaths = files - .map(v => resolve(systemLocation, v)) .filter(v => lstatSync(v).isFile()) .filter(v => parse(v).ext === '.v'); for(const path of fullpaths) log(path); log('parsing modules...'); const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation))); - - // const modules = - // (await Promise.all( - // readdirSync(systemLocation) - // .map(v => resolve(systemLocation, v)) - // .map(v => { log(v); return v; }) - // .map(loc => Module.create(loc)) - // )).reduce((acc, val) => { - // set(acc, val.name.full, val); - // return acc; - // }, {}); const sys = new System(modules, systemLocation); })() diff --git a/test/main.v b/test/main.v index 3670586..c78697b 100644 --- a/test/main.v +++ b/test/main.v @@ -6,5 +6,5 @@ async restore { console.log('~ Welcome to Vogue ~'); // process.stdout.write(JSON.stringify(console, null, 2)) this.currentSave ??= create('world', {}); - const choice = await console.choice('select a thing', ['a', 'b', 'c']); + const choice = await console.choice('select a thing', ['a', 'b', 'c', 'd']); } \ No newline at end of file