move console to autoincluded libs. Closes #16

sdl
Bronwen 2021-05-17 21:18:21 -04:00
parent 47ef9548af
commit 30d50188ec
4 changed files with 68 additions and 73 deletions

View File

@ -78,5 +78,5 @@ export default function createAst(location) {
log(location); log(location);
log(ast); log(ast);
return ast; return ast || [];
} }

View File

@ -29,8 +29,6 @@ choice(message, choices, type) {
return new Promise(res => { return new Promise(res => {
// terminal.saveCursor();
for(const part of message.split(/\x1b\[39m/g)) { for(const part of message.split(/\x1b\[39m/g)) {
terminal.cyan(part); terminal.cyan(part);
} }
@ -38,7 +36,7 @@ choice(message, choices, type) {
terminal.singleColumnMenu(choices, (error, response) => { terminal.singleColumnMenu(choices, (error, response) => {
// terminal.restoreCursor(); // terminal.restoreCursor();
this.write(ansi.cursor.left + ansi.cursor.up(4 + response.selectedIndex)); this.write(ansi.cursor.left + ansi.cursor.up(choices.length + 2));
terminal.cyan(`${message} `); terminal.cyan(`${message} `);
terminal.grabInput(false); terminal.grabInput(false);
// terminal.move // terminal.move
@ -56,3 +54,7 @@ choice(message, choices, type) {
write(a) { write(a) {
process.stdout.write(a); process.stdout.write(a);
} }
clear {
this.write(ansi.erase.screen);
}

21
run.js
View File

@ -3,40 +3,33 @@ import debug from 'debug';
const log = debug('vogue:cli'); const log = debug('vogue:cli');
const systemLocation = resolve(process.argv[2]); const systemLocation = resolve(process.argv[2]);
import { parse, resolve } from 'path'; import { parse, resolve, dirname } from 'path';
import { readdirSync, lstatSync } from 'fs'; import { readdirSync, lstatSync } from 'fs';
import _ from 'lodash'; import _ from 'lodash';
import Module from './Module.js'; import Module from './Module.js';
import System from './System.js'; import System from './System.js';
import './extensions.js'; import './extensions.js';
import { fileURLToPath } from 'url';
// globals inside grammar context // globals inside grammar context
import minify from './minify.js'; import minify from './minify.js';
const { get, set } = _; const { get, set } = _;
const standardLibrary = resolve(fileURLToPath(dirname(import.meta.url)), 'lib');
(async () => { (async () => {
// TODO simplify this line gaddam // TODO simplify this line gaddam
log('reading', systemLocation, '...'); 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 const fullpaths = files
.map(v => resolve(systemLocation, v))
.filter(v => lstatSync(v).isFile()) .filter(v => lstatSync(v).isFile())
.filter(v => parse(v).ext === '.v'); .filter(v => parse(v).ext === '.v');
for(const path of fullpaths) log(path); for(const path of fullpaths) log(path);
log('parsing modules...'); log('parsing modules...');
const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation))); 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); const sys = new System(modules, systemLocation);
})() })()

View File

@ -6,5 +6,5 @@ async restore {
console.log('~ Welcome to Vogue ~'); console.log('~ Welcome to Vogue ~');
// process.stdout.write(JSON.stringify(console, null, 2)) // process.stdout.write(JSON.stringify(console, null, 2))
this.currentSave ??= create('world', {}); 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']);
} }