move console to autoincluded libs. Closes #16
parent
47ef9548af
commit
30d50188ec
|
|
@ -78,5 +78,5 @@ export default function createAst(location) {
|
|||
log(location);
|
||||
log(ast);
|
||||
|
||||
return ast;
|
||||
return ast || [];
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
21
run.js
21
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);
|
||||
})()
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
}
|
||||
Reference in New Issue