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

@ -1,58 +1,60 @@
static console; static console;
import chalk from 'chalk'; import chalk from 'chalk';
import tk from 'terminal-kit'; import tk from 'terminal-kit';
import ansi from 'sisteransi'; import ansi from 'sisteransi';
restore { restore {
const {terminal} = tk; const {terminal} = tk;
terminal.on('key', function(name, matches, data) { terminal.on('key', function(name, matches, data) {
if (name === 'CTRL_C') { if (name === 'CTRL_C') {
process.exit(2); process.exit(2);
} }
}); });
this.write(ansi.cursor.hide); this.write(ansi.cursor.hide);
} }
log(a) { log(a) {
if(typeof a === 'number') a = chalk.yellow(a); if(typeof a === 'number') a = chalk.yellow(a);
// const string = a.toString(); // const string = a.toString();
process.stdout.write(a + '\n'); process.stdout.write(a + '\n');
} }
choice(message, choices, type) { choice(message, choices, type) {
const {terminal} = tk; const {terminal} = tk;
type ??= 'string'; type ??= 'string';
return new Promise(res => { return new Promise(res => {
// terminal.saveCursor(); for(const part of message.split(/\x1b\[39m/g)) {
terminal.cyan(part);
for(const part of message.split(/\x1b\[39m/g)) { }
terminal.cyan(part); terminal.cyan('\n');
}
terminal.cyan('\n'); terminal.singleColumnMenu(choices, (error, response) => {
// terminal.restoreCursor();
terminal.singleColumnMenu(choices, (error, response) => { this.write(ansi.cursor.left + ansi.cursor.up(choices.length + 2));
// terminal.restoreCursor(); terminal.cyan(`${message} `);
this.write(ansi.cursor.left + ansi.cursor.up(4 + response.selectedIndex)); terminal.grabInput(false);
terminal.cyan(`${message} `); // terminal.move
terminal.grabInput(false);
// terminal.move terminal(response.selectedText + '\n').eraseDisplayBelow();
if(type === 'string') {
terminal(response.selectedText + '\n').eraseDisplayBelow(); res(response.selectedText);
if(type === 'string') { } else {
res(response.selectedText); res(response.selectedIndex);
} else { }
res(response.selectedIndex); });
} });
}); }
});
} write(a) {
process.stdout.write(a);
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']);
} }