ajout de Sheebr + support de shutdown + auto install kernel
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
const { Lexer } = require('../lib/sheebr/lexer')
|
||||
const { getline } = require('../lib/sheebr/utils')
|
||||
const fs = require('fs')
|
||||
const environment = require('../lib/sheebr/environment')
|
||||
const readline = require('readline').createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: false
|
||||
});
|
||||
const readlineSync = require('../lib/sheebr/readLineSync')
|
||||
let execSync = require('child_process').execSync
|
||||
|
||||
|
||||
let current_dir = process.cwd()
|
||||
|
||||
start()
|
||||
|
||||
async function start(){
|
||||
while(true){
|
||||
input = await getline("sheebr> ");
|
||||
if(input == "exit") break;
|
||||
else evaluate(input);
|
||||
}
|
||||
}
|
||||
|
||||
function evaluate(input){
|
||||
let lexer = new Lexer(input)
|
||||
args = lexer.scanTokens()
|
||||
|
||||
if(args[0] == "cd"){
|
||||
if(args.length != 2){
|
||||
console.log("Wrong number of arguments"); return;}
|
||||
if(!fs.existsSync(args[1])){console.log("Folder does not exist"); return;}
|
||||
current_dir = args[1][0] == "/" ? args[1] : current_dir + '/' + args[1];
|
||||
console.log(current_dir)
|
||||
return;
|
||||
}
|
||||
// check for all folders in path
|
||||
|
||||
let found = false;
|
||||
for(let path of environment.path){
|
||||
let tobreak = false;
|
||||
const files = fs.readdirSync(path);
|
||||
if(files.includes(`${args[0]}.js`)){
|
||||
found = true;
|
||||
script = execSync(`node ${path + '/' + args[0]}.js ${args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')}`, {cwd: current_dir});
|
||||
process.stdout.write(script)
|
||||
tobreak = true;
|
||||
}
|
||||
|
||||
if(tobreak) break;
|
||||
}
|
||||
if(!found){
|
||||
console.log("Program not found")
|
||||
}
|
||||
let program = args[0]
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user