Hand
This commit is contained in:
parent
a19ae8a746
commit
7becdd5a80
|
@ -23,13 +23,6 @@ server.addListener("error",(err)=> {
|
|||
})
|
||||
exports.http = server;
|
||||
|
||||
let authorize = auth({
|
||||
users:{
|
||||
saqut: "yum81633"
|
||||
},
|
||||
challenge: true
|
||||
});
|
||||
|
||||
app.get("/script",(request, response)=>{
|
||||
response.sendFile(resolve("./script/index.js"))
|
||||
});
|
||||
|
@ -42,14 +35,23 @@ app.get("/index.js.map",(request, response)=>{
|
|||
app.get("/stream",(request, response)=>{
|
||||
response.sendFile(resolve("./public/index.html"))
|
||||
});
|
||||
app.use("/stream",express.static(resolve("./public")));
|
||||
|
||||
app.get("/",authorize,(request, response)=>{
|
||||
app.get("/",(request, response)=>{
|
||||
response.sendFile(resolve("./script/index.html"))
|
||||
});
|
||||
app.post("/stats",authorize,(request, response)=>{
|
||||
app.post("/stats",(request, response)=>{
|
||||
response.json(stats.others);
|
||||
});
|
||||
app.get("/console",(request, response)=>{
|
||||
response.sendFile(resolve("./console/index.html"))
|
||||
});
|
||||
app.get("/console/lib.js",(request, response)=>{
|
||||
setTimeout(()=> {
|
||||
response.sendFile(resolve("./console/lib.js"))
|
||||
}, Math.random() * 5_000 | 0)
|
||||
});
|
||||
app.use("/stream",express.static(resolve("./public")));
|
||||
app.use("/console/",express.static(resolve("./console")));
|
||||
|
||||
app.get("*",(request, response)=>{
|
||||
response.sendFile(resolve("./script/status.xml"))
|
||||
});
|
|
@ -5,7 +5,7 @@ addListener('disconnect',(global, xclient)=>{
|
|||
const {intersection, pairs} = xclient.getSucureClients();
|
||||
for (const [clientid, client] of intersection)
|
||||
{
|
||||
client.send([
|
||||
client?.send([
|
||||
{
|
||||
id: clientid
|
||||
},
|
||||
|
|
|
@ -0,0 +1,508 @@
|
|||
function Hemex()
|
||||
{
|
||||
|
||||
};
|
||||
Hemex.EOL = "\n";
|
||||
/**
|
||||
* Hemex variable white space chars
|
||||
* @type {Number[]}
|
||||
*/
|
||||
Hemex.WhiteSpace = [
|
||||
9,10,11,12,13,32,133
|
||||
];
|
||||
/**
|
||||
* Current cursor position
|
||||
* @type {Number}
|
||||
*/
|
||||
Hemex.prototype.offset = 0;
|
||||
/**
|
||||
* Mapping offset points
|
||||
* @type {Number[]}
|
||||
*/
|
||||
Hemex.prototype.offsetMap = [];
|
||||
Hemex.prototype.beginPosition = function(){
|
||||
this.offsetMap.push(
|
||||
this.getLastPosition()
|
||||
)
|
||||
}
|
||||
/**
|
||||
* Adding current position to offset map
|
||||
*/
|
||||
Hemex.prototype.acceptPosition = function(){
|
||||
let t = this.offsetMap.pop();
|
||||
this.setLastPosition(t)
|
||||
}
|
||||
/**
|
||||
* Get text range current and parent offsets
|
||||
* @returns {[Number,Number]}
|
||||
*/
|
||||
Hemex.prototype.positionRange = function(){
|
||||
let len = this.offsetMap.length;
|
||||
if(len == 0)
|
||||
{
|
||||
return [0,this.offset]
|
||||
}else if(len == 1){
|
||||
return [this.offset,this.offsetMap[len - 1]]
|
||||
}else{
|
||||
return [this.offsetMap[len - 2],this.offsetMap[len - 1]]
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get text range between current offset and parent offset
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.getPositionRange = function(){
|
||||
let u = this.positionRange();
|
||||
return this.text.slice(u[0],u[1])
|
||||
}
|
||||
/**
|
||||
* Cancel current position and return to parent offset
|
||||
*/
|
||||
Hemex.prototype.rejectPosition = function(){
|
||||
this.offsetMap.pop()
|
||||
}
|
||||
/**
|
||||
* Get current layer of position from last offset of map
|
||||
* @returns {Number}
|
||||
*/
|
||||
Hemex.prototype.getLastPosition = function(){
|
||||
return this.offsetMap.length == 0 ? this.offset : this.offsetMap.slice(-1)[0]
|
||||
}
|
||||
/**
|
||||
* Set last position offset from offset map last layer
|
||||
* @param {Number} n
|
||||
*/
|
||||
Hemex.prototype.setLastPosition = function(n){
|
||||
if(this.offsetMap.length == 0)
|
||||
this.offset = n
|
||||
else this.offsetMap[this.offsetMap.length - 1] = n
|
||||
}
|
||||
/**
|
||||
* Get current layer of position from last offset of map
|
||||
* Some as getLastPosition()
|
||||
* @returns {Number}
|
||||
*/
|
||||
Hemex.prototype.getOffset = function(){
|
||||
return this.getLastPosition()
|
||||
}
|
||||
/**
|
||||
* Set last position offset from offset map last layer and return it value
|
||||
* @param {Number} n
|
||||
* @returns {Number}
|
||||
*/
|
||||
Hemex.prototype.setOffset = function(n){
|
||||
this.setLastPosition(n);
|
||||
return this.getLastPosition()
|
||||
}
|
||||
/**
|
||||
* Get text length
|
||||
* @type {Number}
|
||||
*/
|
||||
Hemex.prototype.length = 0;
|
||||
|
||||
/**
|
||||
* Hemex lexing data
|
||||
* @type {String}
|
||||
*/
|
||||
Hemex.prototype.text = "";
|
||||
|
||||
/**
|
||||
* set lexing data
|
||||
* @param {String} text
|
||||
* @returns {void}
|
||||
*/
|
||||
Hemex.prototype.setText = function(text){
|
||||
this.offset = 0;
|
||||
this.length = text.length;
|
||||
this.offsetMap = [];
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* get lexing all data
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.getText = function(){
|
||||
return this.text;
|
||||
}
|
||||
/**
|
||||
* Get one character from cursor
|
||||
* @param {Number} n
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.getChar = function(n){
|
||||
return this.text.charAt(n?this.getOffset()+n:this.getOffset())
|
||||
}
|
||||
/**
|
||||
* Boolean
|
||||
* @param {Number} n
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.isChar = function(b){
|
||||
return this.getChar() == b
|
||||
}
|
||||
/**
|
||||
* Dump all data from cursor position to end of char
|
||||
* @param {Number} n
|
||||
*/
|
||||
Hemex.prototype.dump = function(n){
|
||||
return this.text.slice(this.getOffset(),this.getOffset()+n)
|
||||
}
|
||||
/**
|
||||
* Control coming end of line
|
||||
* @returns {Bollean}
|
||||
*/
|
||||
Hemex.prototype.isEnd = function(){
|
||||
return this.length > this.getOffset()
|
||||
}
|
||||
/**
|
||||
* Forward one char
|
||||
*/
|
||||
Hemex.prototype.nextChar = function(){
|
||||
this.setOffset(this.getOffset() + 1);
|
||||
}
|
||||
/**
|
||||
* Forward n char
|
||||
*/
|
||||
Hemex.prototype.toChar = function(n){
|
||||
this.setOffset(this.getOffset() + n);
|
||||
}
|
||||
/**
|
||||
* Reading while end of line
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.getLine = function(){
|
||||
return this.of(function(){
|
||||
switch(this.getChar())
|
||||
{
|
||||
case Hemex.EOL: return false;
|
||||
default: return true;
|
||||
}
|
||||
}.bind(this))
|
||||
}
|
||||
/**
|
||||
* Read all data until the function returns false
|
||||
* @param {Boolean} p
|
||||
* @param {(char:String)=>Boolean} e
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.of = function(e,p){
|
||||
let k = [],count=0;
|
||||
while(this.isEnd()){
|
||||
if(e(p,count)) k.push(this.getChar());
|
||||
else return k.join('');
|
||||
count++;
|
||||
this.nextChar();
|
||||
};
|
||||
return k.length == 0 ? false : k.join('')
|
||||
}
|
||||
Hemex.prototype.each = function(e,p){
|
||||
let k = [];
|
||||
while(this.isEnd())
|
||||
if(!e(p)) return;
|
||||
else this.nextChar();
|
||||
}
|
||||
Hemex.prototype.while = function(e,p){
|
||||
let k = [];
|
||||
while(this.isEnd())
|
||||
if(!e(p)) return;
|
||||
}
|
||||
/**
|
||||
* Controlling for current char type
|
||||
* @param {Boolean} reverse
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Hemex.prototype.isNumber = function(reverse){
|
||||
let c = this.getChar().charCodeAt(0);
|
||||
let result = c >= 48 && c <= 57;
|
||||
return reverse ? !result : result;
|
||||
}
|
||||
/**
|
||||
* Read all data until char type is not number
|
||||
* @param {Boolean} reverse
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.readNumbers = function(reverse){
|
||||
return this.of(this.isNumber.bind(this),reverse)
|
||||
}
|
||||
/**
|
||||
* Controlling for current char type
|
||||
* @param {Boolean} reverse
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Hemex.prototype.isBigLetter = function(reverse){
|
||||
let c = this.getChar().charCodeAt(0);
|
||||
let result = c >= 97 && c <= 122;
|
||||
return reverse ? !result : result;
|
||||
}
|
||||
/**
|
||||
* Controlling for current char type
|
||||
* @param {Boolean} reverse
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Hemex.prototype.isSmallLetter = function(reverse){
|
||||
let c = this.getChar().charCodeAt(0);
|
||||
let result = c >= 65 && c <= 90;
|
||||
return reverse ? !result : result;
|
||||
}
|
||||
/**
|
||||
* Controlling for current char type
|
||||
* @param {Boolean} reverse
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Hemex.prototype.isLetter = function(reverse){
|
||||
let result = this.isSmallLetter() || this.isBigLetter()
|
||||
return reverse ? !result : result;
|
||||
}
|
||||
/**
|
||||
* Read all data until char type is not letter
|
||||
* @param {Boolean} reverse
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.readLetters = function(reverse){
|
||||
return this.of(this.isLetter.bind(this),reverse)
|
||||
}
|
||||
/**
|
||||
* Controlling for current char type
|
||||
* @param {Boolean} reverse
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Hemex.prototype.isWhiteSpace = function(reverse){
|
||||
let c = this.getChar(),ct = c.charCodeAt(0);
|
||||
let result = (
|
||||
c == '\n' ||
|
||||
c == '\r' ||
|
||||
c == '\t' ||
|
||||
c == ' ' ||
|
||||
Hemex.WhiteSpace.includes(ct)
|
||||
)
|
||||
return reverse ? !result : result;
|
||||
}
|
||||
/**
|
||||
* Read all data until char type is not white space
|
||||
* @param {Boolean} reverse
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.readWhiteSpace = function(reverse){
|
||||
return this.of(this.isWhiteSpace.bind(this),reverse)
|
||||
}
|
||||
/**
|
||||
* Controlling data
|
||||
* @param {Boolean} reverse
|
||||
* @returns {String}
|
||||
*/
|
||||
Hemex.prototype.include = function(words,next){
|
||||
this.beginPosition();
|
||||
for(let i = 0; i<words.length; i++)
|
||||
{
|
||||
if(words[i] != this.getChar())
|
||||
{
|
||||
this.rejectPosition();
|
||||
return false;
|
||||
};
|
||||
this.nextChar();
|
||||
};
|
||||
if(next) this.acceptPosition();
|
||||
else this.rejectPosition();
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Controlling data
|
||||
* @param {Boolean} reverse
|
||||
* @returns {String|boolean}
|
||||
*/
|
||||
Hemex.prototype.includes = function(arrays,accept){
|
||||
this.beginPosition();
|
||||
let flags = Array.from(arrays).fill(true);
|
||||
let index = 0;
|
||||
this.each(function(){
|
||||
let stopLoop = true;
|
||||
for(let T in arrays)
|
||||
{
|
||||
if(!flags[T] || arrays[T].length <= index) continue;
|
||||
stopLoop = false;
|
||||
flags[T] &= arrays[T][index] == this.getChar()
|
||||
};
|
||||
index++;
|
||||
return !stopLoop && flags.filter(function(val){return val}).length != 0;
|
||||
}.bind(this));
|
||||
let result = arrays.filter(function(_,index){return flags[index]});
|
||||
if(accept) this.acceptPosition();
|
||||
else this.rejectPosition();
|
||||
return result.length == 0 ? false : result
|
||||
}
|
||||
/**
|
||||
* Parsing number formats like; 12 75.1 0xE7 0b10 +3.46
|
||||
* @returns {[String,Number]}
|
||||
*/
|
||||
Hemex.prototype.readNumber = function(){
|
||||
let data = [];
|
||||
let base = 10;
|
||||
let nextDot = false;
|
||||
let c = this.getChar();
|
||||
if(this.isChar('0'))
|
||||
{
|
||||
this.nextChar();
|
||||
switch(this.getChar())
|
||||
{
|
||||
case 'x':{
|
||||
base = 16;
|
||||
this.nextChar();
|
||||
data.push('0x')
|
||||
break;
|
||||
}
|
||||
case 'b':{
|
||||
base = 2;
|
||||
this.nextChar();
|
||||
data.push('0b')
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
base = 8;
|
||||
this.nextChar();
|
||||
data.push('0')
|
||||
}
|
||||
}
|
||||
}else base = 10;
|
||||
this.each(()=>{
|
||||
switch(c = this.getChar())
|
||||
{
|
||||
case '0':
|
||||
case '1':{
|
||||
data.push(c);
|
||||
break;
|
||||
}
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':{
|
||||
if(base >= 8){
|
||||
data.push(c);
|
||||
break;
|
||||
}else return false;
|
||||
}
|
||||
case '8':
|
||||
case '9':{
|
||||
if(base >= 10){
|
||||
data.push(c);
|
||||
break;
|
||||
}else return false;
|
||||
}
|
||||
case 'A':
|
||||
case 'a':
|
||||
case 'B':
|
||||
case 'b':
|
||||
case 'C':
|
||||
case 'c':
|
||||
case 'D':
|
||||
case 'd':
|
||||
/* case 'E': case 'e': */
|
||||
case 'F':
|
||||
case 'f':{
|
||||
if(base >= 16){
|
||||
data.push(c);
|
||||
break;
|
||||
}else return false;
|
||||
}
|
||||
case '.':{
|
||||
if(!nextDot){
|
||||
if(data.length == 0){
|
||||
data.push("0");
|
||||
}else data.push(".");
|
||||
nextDot = true;
|
||||
isFloat = true;
|
||||
}else{
|
||||
throw new Error("Float number in Double dot");
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 'E':
|
||||
case 'e':{
|
||||
if(this.getChar(1)!='+'){
|
||||
if(base == 16){
|
||||
data.push(c);
|
||||
break;
|
||||
}else return false;
|
||||
};
|
||||
if(data.length == 0){
|
||||
this.rejectPosition();
|
||||
return false;
|
||||
};
|
||||
data.push('e');
|
||||
this.nextChar();
|
||||
if(this.getChar()=='+' || this.getChar()=='-'){
|
||||
data.push(char());
|
||||
this.nextChar();
|
||||
};
|
||||
let result = null;
|
||||
this.each(()=>{
|
||||
switch(this.getChar()){
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':{
|
||||
data.push(this.getChar());
|
||||
this.nextChar();
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
default:{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
return true
|
||||
});
|
||||
return data.length == 0 ? false : [data.join(''),base]
|
||||
}
|
||||
|
||||
Hemex.prototype.syntaxs = new Map();
|
||||
/**
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(hmx:Hemex, result: (result:any) => any,...args:any[]) => any} callback
|
||||
*/
|
||||
Hemex.prototype.syntax = function(name, callback){
|
||||
this.syntaxs.set(name, callback)
|
||||
}
|
||||
|
||||
Hemex.prototype.give = function(name, ...args){
|
||||
let sandbox = this.syntaxs.get(name);
|
||||
if(sandbox)
|
||||
{
|
||||
let res = undefined;
|
||||
hmx.beginPosition();
|
||||
if(sandbox(
|
||||
this,
|
||||
arg => {
|
||||
res = arg
|
||||
},
|
||||
...args
|
||||
))
|
||||
{
|
||||
hmx.acceptPosition();
|
||||
return res;
|
||||
}else{
|
||||
hmx.rejectPosition();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param {Error} message
|
||||
*/
|
||||
Hemex.prototype.throw = function(message){
|
||||
throw new Error(message)
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="tr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WebSocket Terminal</title>
|
||||
<style>
|
||||
body{
|
||||
background-color: black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="terminal"></div>
|
||||
<script src="xterm.js"></script>
|
||||
<link rel="stylesheet" href="xterm.min.css">
|
||||
<script src="./Hemex.js"></script>
|
||||
<script src="lib.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,908 @@
|
|||
var term = new Terminal({
|
||||
cursorStyle: "underline",
|
||||
cols: 180,
|
||||
rows: 50
|
||||
});
|
||||
term.open(document.querySelector('#terminal'));
|
||||
|
||||
|
||||
function newLine(t = true, prompt = true) {
|
||||
t && term.write('\r\n');
|
||||
cursorPosition = 0;
|
||||
if(prompt)
|
||||
{
|
||||
term.write(DEFAULT_PROMPT);
|
||||
cursorPosition += CLEAR_STYLING(DEFAULT_PROMPT).length;
|
||||
}
|
||||
resetUserSpace()
|
||||
}
|
||||
|
||||
let waitms = ms => new Promise(ok => setTimeout(()=>ok(), ms));
|
||||
|
||||
let cursorPosition = 0;
|
||||
let _buffer = [];
|
||||
let COLOR_RESET = () => "\x1B[0m";
|
||||
let COLOR_TEXT = (r,g,b) => `\x1B[38;2;${r};${g};${b}m`;
|
||||
let COLOR_BACKGROUND = (r,g,b) => `\x1B[48;2;${r};${g};${b}m`;
|
||||
|
||||
let CURSOR_MOVE = (row, col) => `\x1B[${row};${col}H`;
|
||||
let CURSOR_MOVE_UP = () => `\x1B[A`;
|
||||
let CURSOR_MOVE_DOWN = () => `\x1B[B`;
|
||||
let CURSOR_MOVE_RIGHT = () => `\x1B[C`;
|
||||
let CURSOR_MOVE_LEFT = () => `\x1B[D`;
|
||||
|
||||
let CLEAR_SCREEN = () => `\x1B[2J`;
|
||||
let CLEAR_LINE = () => `\x1B[2K`;
|
||||
|
||||
term.write(CURSOR_MOVE(2,1));
|
||||
|
||||
let CLEAR_STYLING = (text) => text.toString().replace(/\x1B(.*?)m/ig,'');
|
||||
|
||||
function writeHi()
|
||||
{
|
||||
term.write(
|
||||
"Merhaba, "
|
||||
+ COLOR_TEXT(0,255,0)
|
||||
+ COLOR_BACKGROUND(32,32,32)
|
||||
+ ' saQut RC Shell '
|
||||
+ COLOR_RESET()
|
||||
+ "\n\n\r"
|
||||
);
|
||||
|
||||
newLine();
|
||||
}
|
||||
|
||||
let userSpace = {
|
||||
buffer: [],
|
||||
paddingChars: 0,
|
||||
size: 0
|
||||
};
|
||||
|
||||
function resetUserSpace()
|
||||
{
|
||||
userSpace = {
|
||||
buffer: [],
|
||||
paddingChars: 0,
|
||||
size: 0
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentLine()
|
||||
{
|
||||
return term
|
||||
.buffer
|
||||
.active
|
||||
.getLine(
|
||||
term
|
||||
.buffer
|
||||
.active
|
||||
.cursorY
|
||||
)
|
||||
.translateToString()
|
||||
}
|
||||
|
||||
|
||||
let pausedInput = false;
|
||||
let activeProgram = false;
|
||||
|
||||
term.onData(async chars => {
|
||||
if(pausedInput)
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
if(chars.length > 1)
|
||||
{
|
||||
return await DefaultProcess(chars);
|
||||
}
|
||||
|
||||
if(chars.length == 1)
|
||||
{
|
||||
if(activeProgram)
|
||||
{
|
||||
if(activeProgram._sys.idleChar)
|
||||
{
|
||||
return activeProgram._sys.idleChar.triggerChar(chars);
|
||||
}
|
||||
}
|
||||
return await DefaultProcess(chars);
|
||||
}else if(activeProgram){
|
||||
return
|
||||
}
|
||||
|
||||
let tokens = [];
|
||||
chars.toString().replace(/(\x1B.+?m)|(\x1B\[.+)|(.+)/igm, (_,a,b,c,d,e,f,g) => {
|
||||
let charx = a || b || c;
|
||||
if(charx)
|
||||
{
|
||||
if(/^(\x1B.*?m)$|^(\x1B\[.*)$/i.test(charx))
|
||||
{
|
||||
tokens.push([charx,])
|
||||
}else{
|
||||
tokens.push([,charx])
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (const [code, chars] of tokens)
|
||||
{
|
||||
pausedInput = true;
|
||||
if(code)
|
||||
{
|
||||
await DefaultProcess(code);
|
||||
}else if(chars)
|
||||
{
|
||||
for (const char of chars.split(''))
|
||||
{
|
||||
await DefaultProcess(char);
|
||||
}
|
||||
}
|
||||
pausedInput = false;
|
||||
}
|
||||
})
|
||||
|
||||
async function DefaultProcess(char)
|
||||
{
|
||||
let contextchanged = false;
|
||||
switch(char)
|
||||
{
|
||||
// Backspace
|
||||
case '\x7f':
|
||||
if(userSpace.paddingChars > 0)
|
||||
{
|
||||
term.write('\b \b');
|
||||
cursorPosition--;
|
||||
|
||||
let after = userSpace.buffer.slice(0, userSpace.paddingChars - 1);
|
||||
let before = userSpace.buffer.slice(userSpace.paddingChars);
|
||||
userSpace.buffer = [
|
||||
...after,
|
||||
...before
|
||||
];
|
||||
userSpace.paddingChars--;
|
||||
userSpace.size--;
|
||||
contextchanged = true;
|
||||
|
||||
term.write(before.join('')+" \b");
|
||||
term.write(before.map(() => '\b').join(''));
|
||||
}
|
||||
break;
|
||||
// Enter
|
||||
case '\r':
|
||||
let command = userSpace.buffer.join('');
|
||||
|
||||
if(activeProgram && activeProgram._sys.idleReadline)
|
||||
{
|
||||
newLine(true, false);
|
||||
return activeProgram._sys.triggerReadline(command);
|
||||
}
|
||||
|
||||
let parsedCommand = ParseCommand(command);
|
||||
if(parsedCommand != false)
|
||||
{
|
||||
let program = parsedCommand.find(e => e.type == 'commandname').data;
|
||||
|
||||
pausedInput = true;
|
||||
|
||||
newLine(true, false);
|
||||
|
||||
await ExecuteCommand(
|
||||
program,
|
||||
parsedCommand
|
||||
);
|
||||
pausedInput = false;
|
||||
|
||||
newLine(false);
|
||||
}else{
|
||||
newLine();
|
||||
}
|
||||
break;
|
||||
case CURSOR_MOVE_LEFT():
|
||||
if(userSpace.paddingChars > 0)
|
||||
{
|
||||
userSpace.paddingChars--;
|
||||
term.write(CURSOR_MOVE_LEFT());
|
||||
}
|
||||
break;
|
||||
case CURSOR_MOVE_UP():
|
||||
case CURSOR_MOVE_DOWN():
|
||||
break;
|
||||
// Delete
|
||||
case "\x1B[3~":
|
||||
let after = userSpace.buffer.slice(0, userSpace.paddingChars);
|
||||
let before = userSpace.buffer.slice(userSpace.paddingChars + 1);
|
||||
term.write(before.join('')+" \b");
|
||||
term.write(before.map(() => '\b').join(''));
|
||||
userSpace.buffer = [
|
||||
...after,
|
||||
...before
|
||||
];
|
||||
userSpace.size--;
|
||||
contextchanged = true;
|
||||
break;
|
||||
case CURSOR_MOVE_RIGHT():
|
||||
if(userSpace.paddingChars < userSpace.size)
|
||||
{
|
||||
term.write(CURSOR_MOVE_RIGHT());
|
||||
userSpace.paddingChars++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
let printable = char.charCodeAt(0);
|
||||
if(printable < 32)
|
||||
{
|
||||
return
|
||||
}
|
||||
// insert or append ?
|
||||
if(userSpace.paddingChars == userSpace.size)
|
||||
{
|
||||
term.write(char);
|
||||
|
||||
userSpace.buffer = [
|
||||
...userSpace.buffer.slice(0, userSpace.paddingChars),
|
||||
char,
|
||||
...userSpace.buffer.slice(userSpace.paddingChars),
|
||||
];
|
||||
|
||||
userSpace.paddingChars++;
|
||||
userSpace.size++;
|
||||
cursorPosition++;
|
||||
contextchanged = true;
|
||||
|
||||
}else{
|
||||
|
||||
let after = userSpace.buffer.slice(0, userSpace.paddingChars);
|
||||
let before = userSpace.buffer.slice(userSpace.paddingChars);
|
||||
|
||||
userSpace.buffer = [
|
||||
...after,
|
||||
char,
|
||||
...before
|
||||
];
|
||||
|
||||
term.write(char);
|
||||
term.write(before.join(''));
|
||||
term.write(before.map(() => '\b').join(''));
|
||||
contextchanged = true;
|
||||
userSpace.paddingChars++;
|
||||
userSpace.size++;
|
||||
cursorPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
if(!activeProgram)
|
||||
{
|
||||
contextchanged && COLORIZE_LINE();
|
||||
}
|
||||
};
|
||||
|
||||
async function COLORIZE_LINE()
|
||||
{
|
||||
let before = userSpace.buffer.slice(0, userSpace.paddingChars);
|
||||
let after = userSpace.buffer.slice(userSpace.paddingChars);
|
||||
let coloredCommand = CommandColorize(before.concat(after).join(''));
|
||||
|
||||
if(coloredCommand)
|
||||
{
|
||||
// Cursoru en başa al
|
||||
term.write(CURSOR_MOVE_LEFT().repeat(before.length));
|
||||
term.write(coloredCommand);
|
||||
term.write(CURSOR_MOVE_LEFT().repeat(after.length));
|
||||
}
|
||||
}
|
||||
|
||||
let USER_SPACE = "virtualhost";
|
||||
let USER_NAME = [
|
||||
147 + Math.random() * 25 | 0,
|
||||
200 + Math.random() * 56 | 0,
|
||||
0 + Math.random() * 256 | 0,
|
||||
0 + Math.random() * 256 | 0
|
||||
].join('.');
|
||||
|
||||
let DEFAULT_PROMPT = (
|
||||
COLOR_RESET()
|
||||
+ '['
|
||||
+ COLOR_TEXT(0,255,0)
|
||||
+ USER_SPACE
|
||||
+ ' '
|
||||
+ COLOR_TEXT(0,128,255)
|
||||
+ USER_NAME
|
||||
+ COLOR_RESET()
|
||||
+ '] $ '
|
||||
);
|
||||
|
||||
|
||||
writeHi();
|
||||
|
||||
let _color_command = [255,255,255];
|
||||
let _color_option = [128,128,255];
|
||||
let _color_stringdata = [128,255,64];
|
||||
|
||||
function CommandColorize(command)
|
||||
{
|
||||
let hmx = new Hemex();
|
||||
hmx.setText(command);
|
||||
|
||||
let output = [];
|
||||
|
||||
let commandBefore = hmx.of(() => !hmx.isLetter());
|
||||
|
||||
if(commandBefore.length != 0)
|
||||
{
|
||||
output.push(
|
||||
COLOR_TEXT(255,255,255),
|
||||
commandBefore,
|
||||
COLOR_RESET()
|
||||
)
|
||||
}
|
||||
|
||||
if(!hmx.isLetter())
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
let commandName = hmx.of(() => hmx.isLetter() || hmx.isNumber() || hmx.includes(['-','_',':','.','$']));
|
||||
|
||||
if(hmx.isEnd() && !hmx.isWhiteSpace())
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
output.push(
|
||||
COLOR_TEXT(..._color_command),
|
||||
commandName,
|
||||
COLOR_RESET()
|
||||
);
|
||||
|
||||
let all = [], stringstarted = false;
|
||||
hmx.each(() => {
|
||||
let char = hmx.getChar();
|
||||
switch(char)
|
||||
{
|
||||
case '\'':
|
||||
case '"':
|
||||
case '`':{
|
||||
if(stringstarted == false)
|
||||
{
|
||||
stringstarted = char;
|
||||
all.push(COLOR_TEXT(..._color_stringdata), char)
|
||||
}else if(stringstarted == char){
|
||||
stringstarted = false;
|
||||
all.push(char, COLOR_TEXT(..._color_option))
|
||||
}else{
|
||||
all.push(char)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:{
|
||||
if(all.length == 0)
|
||||
{
|
||||
all.push(COLOR_TEXT(..._color_option), char);
|
||||
}else{
|
||||
all.push(char)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
output.push(all.join(''))
|
||||
|
||||
output.push(COLOR_RESET())
|
||||
return output.join('')
|
||||
}
|
||||
|
||||
function ParseCommand(command)
|
||||
{
|
||||
let hmx = new Hemex();
|
||||
hmx.setText(command);
|
||||
|
||||
hmx.of(() => !hmx.isLetter());
|
||||
|
||||
if(!hmx.isLetter())
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
let onlyArgs = false;
|
||||
|
||||
let commandName = hmx.of(() => hmx.isLetter() || hmx.isNumber() || hmx.includes(['-','_',':','.','$']));
|
||||
|
||||
if(hmx.isEnd() && !hmx.isWhiteSpace())
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
hmx.readWhiteSpace();
|
||||
|
||||
let args = [];
|
||||
|
||||
let xargs = [], operation = 'option';
|
||||
|
||||
hmx.beginPosition();
|
||||
hmx.while(()=>{
|
||||
if(hmx.include('--') && operation == 'option')
|
||||
{
|
||||
xargs.length && (
|
||||
args.push({
|
||||
type: 'data',
|
||||
data: xargs.join('')
|
||||
}),
|
||||
xargs = []
|
||||
);
|
||||
|
||||
hmx.beginPosition();
|
||||
|
||||
hmx.include('--', true);
|
||||
let argumentkey = hmx.of(() => hmx.isLetter() || hmx.isNumber() || hmx.includes(['-','_',':','.','$']));
|
||||
|
||||
if(argumentkey == false)
|
||||
{
|
||||
hmx.rejectPosition();
|
||||
return true;
|
||||
}
|
||||
|
||||
args.push({
|
||||
type: "argument",
|
||||
data: argumentkey
|
||||
});
|
||||
|
||||
hmx.acceptPosition();
|
||||
|
||||
hmx.readWhiteSpace();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(hmx.include('-') && operation == 'option')
|
||||
{
|
||||
xargs.length && (
|
||||
args.push({
|
||||
type: 'data',
|
||||
data: xargs.join('').trim()
|
||||
}),
|
||||
xargs = []
|
||||
);
|
||||
|
||||
hmx.beginPosition();
|
||||
hmx.nextChar();
|
||||
let argumentkey = hmx.of(() => hmx.isLetter() || hmx.isNumber());
|
||||
|
||||
if(argumentkey == false)
|
||||
{
|
||||
hmx.rejectPosition();
|
||||
return true;
|
||||
}
|
||||
|
||||
argumentkey.split('').forEach(e => {
|
||||
args.push({
|
||||
type: "flag",
|
||||
data: e
|
||||
})
|
||||
})
|
||||
|
||||
hmx.acceptPosition();
|
||||
|
||||
hmx.readWhiteSpace();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
let char;
|
||||
if((char = hmx.includes(['\'','"'])) && operation == 'option')
|
||||
{
|
||||
xargs.length && (
|
||||
args.push({
|
||||
type: 'data',
|
||||
data: xargs.join('')
|
||||
}),
|
||||
xargs = []
|
||||
);
|
||||
|
||||
let escapeChar = char[0];
|
||||
hmx.nextChar();
|
||||
|
||||
let data = [];
|
||||
|
||||
hmx.while(() => {
|
||||
let char = hmx.getChar();
|
||||
switch(hmx.getChar())
|
||||
{
|
||||
case escapeChar:{
|
||||
hmx.nextChar();
|
||||
return false;
|
||||
}
|
||||
default:{
|
||||
data.push(char);
|
||||
hmx.nextChar();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
args.push({
|
||||
type: "string",
|
||||
data: data.join('')
|
||||
})
|
||||
|
||||
hmx.readWhiteSpace();
|
||||
|
||||
return true;
|
||||
}
|
||||
xargs.push(hmx.getChar());
|
||||
if(hmx.isWhiteSpace())
|
||||
{
|
||||
operation = 'option';
|
||||
}else{
|
||||
operation = 'data';
|
||||
}
|
||||
|
||||
hmx.nextChar();
|
||||
|
||||
if(hmx.isEnd())
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
args.push({
|
||||
type: "data",
|
||||
data: xargs.join('')
|
||||
})
|
||||
return false;
|
||||
}
|
||||
});
|
||||
onlyArgs = hmx.getPositionRange();
|
||||
hmx.acceptPosition();
|
||||
|
||||
return [{
|
||||
type: "cmdline",
|
||||
data: command
|
||||
},{
|
||||
type: "commandname",
|
||||
data: commandName
|
||||
},{
|
||||
type: "arguments",
|
||||
data: onlyArgs
|
||||
}, ...args]
|
||||
}
|
||||
|
||||
function generatepipe()
|
||||
{
|
||||
pausedInput = true;
|
||||
|
||||
let events = {};
|
||||
|
||||
let gen = {
|
||||
stdin: {
|
||||
setPaused(boolean){
|
||||
pausedInput = Boolean(boolean);
|
||||
},
|
||||
async readline(){
|
||||
gen.stdin.setPaused(false);
|
||||
gen._sys.idleReadline = true;
|
||||
return await new Promise(ok => {
|
||||
events['readline'] = (result) => {
|
||||
gen.stdin.setPaused(true);
|
||||
gen._sys.idleReadline = false;
|
||||
ok(result)
|
||||
events['readline'] = null;
|
||||
};
|
||||
})
|
||||
},
|
||||
async getchar(){
|
||||
gen.stdin.setPaused(false);
|
||||
gen._sys.idleChar = true;
|
||||
return await new Promise(ok => {
|
||||
events['read'] = (result) => {
|
||||
gen.stdin.setPaused(true);
|
||||
gen._sys.idleChar = false;
|
||||
events['read'] = null;
|
||||
ok(result)
|
||||
};
|
||||
})
|
||||
}
|
||||
},
|
||||
stdout: {
|
||||
async write(...args){
|
||||
term.write(args.map(e => e.toString()).join(' '))
|
||||
},
|
||||
async writeln(...args){
|
||||
term.writeln(args.map(e => e.toString()).join(' '))
|
||||
}
|
||||
},
|
||||
stderr: {
|
||||
async write(...args){
|
||||
term.write(COLOR_TEXT(255,0,0));
|
||||
term.write(args.map(e => e.toString()).join(' '))
|
||||
term.write(COLOR_RESET());
|
||||
},
|
||||
async writeln(...args){
|
||||
term.write(COLOR_TEXT(255,0,0));
|
||||
term.writeln(args.map(e => e.toString()).join(' '))
|
||||
term.write(COLOR_RESET());
|
||||
}
|
||||
},
|
||||
_sys:{
|
||||
idleReadline: false,
|
||||
idleChar: false,
|
||||
triggerReadline(text){
|
||||
if(events['readline']) events['readline'](text)
|
||||
},
|
||||
triggerChar(text){
|
||||
if(events['read']) events['read'](text)
|
||||
},
|
||||
destroy(){
|
||||
gen.stdin.setPaused(false);
|
||||
events = void 0;
|
||||
gen._sys.idleReadline = false;
|
||||
gen._sys.idleChar = false;
|
||||
gen._sys = void 0;
|
||||
gen.stderr = void 0;
|
||||
gen.stdin = void 0;
|
||||
gen.stdout = void 0;
|
||||
activeProgram = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
activeProgram = gen;
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
async function ExecuteCommand(command, cmdline)
|
||||
{
|
||||
let Namespace = await CommandNamespace(command);
|
||||
if(Namespace == null)
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await new Promise(async (ok,reject) => {
|
||||
resetUserSpace();
|
||||
let program = new Namespace(generatepipe());
|
||||
program.exit = () => ok();
|
||||
try{
|
||||
let t = program.main(cmdline);
|
||||
if(t?.constructor?.name == 'AsyncFunction')
|
||||
{
|
||||
await t;
|
||||
}
|
||||
}catch(e){
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
catch(exception)
|
||||
{
|
||||
term.writeln('');
|
||||
term.write(COLOR_TEXT(255,0,0));
|
||||
term.writeln('Yazılım hatası:');
|
||||
term.writeln('=========================');
|
||||
term.write(COLOR_RESET());
|
||||
term.writeln(exception.message);
|
||||
term.writeln(exception.stack.replace(/\n/g,'\r\n'));
|
||||
term.write(COLOR_TEXT(255,0,0));
|
||||
term.writeln('=========================');
|
||||
term.write(COLOR_RESET());
|
||||
}
|
||||
finally
|
||||
{
|
||||
pausedInput = false;
|
||||
activeProgram = void 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function InspectRepo()
|
||||
{
|
||||
if(CommandNamespace.repos.find(e => e.downloaded == false))
|
||||
{
|
||||
term.writeln(COLOR_RESET()+"\r\nUpdating repos....")
|
||||
await wait(100);
|
||||
}else{
|
||||
term.writeln('');
|
||||
}
|
||||
for(const repo of CommandNamespace.repos)
|
||||
{
|
||||
if(repo.downloaded == false)
|
||||
{
|
||||
term.writeln(`Downloading:${COLOR_TEXT(0,255,0)} ${repo.name} ${COLOR_RESET()} ${repo.endpoint}`);
|
||||
await wait(100);
|
||||
let file = await DownloadRepoMetapack(repo.endpoint);
|
||||
repo.packages = file;
|
||||
term.writeln(`Downloaded:${COLOR_TEXT(0,255,0)} ${repo.name} ${COLOR_RESET()} ${repo.endpoint}`);
|
||||
await wait(100);
|
||||
repo.downloaded = true;
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
async function CommandNamespace(command)
|
||||
{
|
||||
let package = false;
|
||||
if(!CommandNamespace.namespaces.has(command))
|
||||
{
|
||||
await InspectRepo();
|
||||
for(const repo of CommandNamespace.repos)
|
||||
{
|
||||
for (const repopackage in repo.packages)
|
||||
{
|
||||
let packageName = repopackage;
|
||||
let meta = repo.packages[repopackage];
|
||||
let _command = meta.commands.find(_command => command == _command);
|
||||
|
||||
if(_command)
|
||||
{
|
||||
package = [packageName,meta];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(package == false)
|
||||
{
|
||||
term.writeln(COLOR_TEXT(255,0,0) + "'" + command + "' not found !" + COLOR_RESET());
|
||||
}else{
|
||||
term.writeln([
|
||||
COLOR_TEXT(0,255,0),
|
||||
package[0],
|
||||
COLOR_TEXT(200,200,200),
|
||||
" paketine ait olan ",
|
||||
COLOR_TEXT(0,255,0),
|
||||
command,
|
||||
COLOR_TEXT(200,200,200),
|
||||
" komutunu kullanabilmek için aşağıdaki komutunu çalıştırın"
|
||||
].join('') +
|
||||
"\r\n\n" +
|
||||
CommandColorize(`load '${package[0]}' from 'official'`)+
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
}else{
|
||||
return CommandNamespace.namespaces.get(command);
|
||||
}
|
||||
}
|
||||
|
||||
function wait(ms)
|
||||
{
|
||||
return new Promise(ok => setTimeout(() => ok(),ms));
|
||||
}
|
||||
|
||||
async function DownloadRepoMetapack(endpoint)
|
||||
{
|
||||
let request = await fetch(endpoint,{
|
||||
method: "get",
|
||||
cache: "force-cache",
|
||||
priority: "high",
|
||||
redirect: "follow",
|
||||
referrerPolicy: "no-referrer"
|
||||
});
|
||||
|
||||
await wait(100);
|
||||
|
||||
try{
|
||||
let response = await request.json();
|
||||
return response;
|
||||
}catch
|
||||
{
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
CommandNamespace.namespaces = new Map();
|
||||
CommandNamespace.repos = [{
|
||||
name: "official",
|
||||
endpoint: new URL('/console/official/packages.json',window.location),
|
||||
downloaded: false,
|
||||
packages: {}
|
||||
}];
|
||||
|
||||
|
||||
|
||||
class SystemLoad{
|
||||
stdin = null;
|
||||
stdout = null;
|
||||
constructor(pipe){
|
||||
this.stdin = pipe.stdin;
|
||||
this.stdout = pipe.stdout;
|
||||
}
|
||||
printhelp()
|
||||
{
|
||||
this.stdout.writeln('Kullanım şekli: ');
|
||||
this.stdout.writeln('ExampleProgram paketini kurmak için aşağıdaki komutu yazmalısınız\r\n');
|
||||
this.stdout.writeln(
|
||||
CommandColorize(`load 'ExampleProgram'`)+"\r\n"
|
||||
);
|
||||
|
||||
}
|
||||
async main(args)
|
||||
{
|
||||
let m = false, nargs = args.filter(({type}) => {
|
||||
if(type == "arguments") return m = true, false;
|
||||
return m;
|
||||
});
|
||||
|
||||
let packname;
|
||||
if(nargs[0].type == "string")
|
||||
{
|
||||
packname = nargs[0].data;
|
||||
}else{
|
||||
this.printhelp();
|
||||
this.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(CommandNamespace.repos.find(e => e.downloaded == false))
|
||||
{
|
||||
this.stdout.writeln(COLOR_RESET()+"\r\nUpdating repos....")
|
||||
}else{
|
||||
this.stdout.writeln('');
|
||||
}
|
||||
for(const repo of CommandNamespace.repos)
|
||||
{
|
||||
if(repo.downloaded == false)
|
||||
{
|
||||
this.stdout.writeln(`Downloading:${COLOR_TEXT(0,255,0)} ${repo.name} ${COLOR_RESET()} ${repo.endpoint}`);
|
||||
await wait(100);
|
||||
let file = await DownloadRepoMetapack(repo.endpoint.href);
|
||||
if(file == null){
|
||||
continue
|
||||
}
|
||||
repo.packages = file;
|
||||
this.stdout.writeln(`Downloaded:${COLOR_TEXT(0,255,0)} ${repo.name} ${COLOR_RESET()} ${repo.endpoint}`);
|
||||
await wait(100);
|
||||
repo.downloaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
let endpoints = CommandNamespace.repos.map(e => e.packages[packname] && e.packages[packname].endpoints.map(endpoint => new URL(endpoint,e.endpoint))).filter(e => !!e)
|
||||
|
||||
if(endpoints.length == 0)
|
||||
{
|
||||
term.writeln(COLOR_TEXT(255,0,0) + "'" + packname + "' repo not found !" + COLOR_RESET());
|
||||
await wait(100);
|
||||
this.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const endpoint of endpoints[0])
|
||||
{
|
||||
let href = endpoint.href;
|
||||
this.stdout.writeln(`Packet downloading :${COLOR_TEXT(0,255,0)} ${packname} ${COLOR_RESET()} ${endpoint.href}`);
|
||||
await wait(100);
|
||||
|
||||
let request = await fetch(href,{
|
||||
method: "get",
|
||||
cache: "force-cache",
|
||||
priority: "high",
|
||||
redirect: "follow",
|
||||
referrerPolicy: "no-referrer"
|
||||
});
|
||||
|
||||
this.stdout.writeln(`Packet unzip to :${COLOR_TEXT(0,255,0)} /mount/xpack/${packname}/ ${COLOR_RESET()}`);
|
||||
await wait(100);
|
||||
|
||||
let script = await request.text();
|
||||
|
||||
try{
|
||||
this.stdout.writeln(`Analyzing..`);
|
||||
await new Promise(ok => setTimeout(() => ok(),1000));
|
||||
(new Function(script))();
|
||||
this.stdout.writeln(`Process success`);
|
||||
await wait(100);
|
||||
}catch{
|
||||
this.stderr.writeln(`Process error`);
|
||||
await wait(100);
|
||||
}
|
||||
}
|
||||
this.exit();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CommandNamespace.namespaces.set('load', SystemLoad);
|
|
@ -0,0 +1,51 @@
|
|||
class CommandJS{
|
||||
stdin = null;
|
||||
stdout = null;
|
||||
stderr = null;
|
||||
constructor(pipe){
|
||||
this.stdin = pipe.stdin;
|
||||
this.stdout = pipe.stdout;
|
||||
this.stderr = pipe.stderr;
|
||||
}
|
||||
async main(args)
|
||||
{
|
||||
let commandline = args.find(e => e.type == "arguments");
|
||||
if(commandline)
|
||||
{
|
||||
try{
|
||||
let t = eval(commandline.data);
|
||||
if(typeof t != "undefined")
|
||||
{
|
||||
this.stdout.writeln(JSON.stringify(t,null, ' ').replace(/\n/g,'\r\n'));
|
||||
}
|
||||
}catch(e){
|
||||
this.stderr.writeln(e.message);
|
||||
}
|
||||
}
|
||||
this.exit();
|
||||
}
|
||||
};
|
||||
|
||||
class CommandJSRaw{
|
||||
stdin = null;
|
||||
stdout = null;
|
||||
stderr = null;
|
||||
constructor(pipe){
|
||||
this.stdin = pipe.stdin;
|
||||
this.stdout = pipe.stdout;
|
||||
this.stderr = pipe.stderr;
|
||||
}
|
||||
async main(args)
|
||||
{
|
||||
let commandline = args.find(e => e.type == "arguments");
|
||||
if(commandline)
|
||||
{
|
||||
let t = eval(commandline.data);
|
||||
this.stdout.writeln(t);
|
||||
}
|
||||
this.exit();
|
||||
}
|
||||
};
|
||||
|
||||
CommandNamespace.namespaces.set('js', CommandJS);
|
||||
CommandNamespace.namespaces.set('jsecho', CommandJSRaw);
|
|
@ -0,0 +1,18 @@
|
|||
class CommandSet{
|
||||
stdin = null;
|
||||
stdout = null;
|
||||
stderr = null;
|
||||
constructor(pipe){
|
||||
this.stdin = pipe.stdin;
|
||||
this.stdout = pipe.stdout;
|
||||
this.stderr = pipe.stderr;
|
||||
}
|
||||
async main(args)
|
||||
{
|
||||
this.stdout.writeln(JSON.stringify(args,null, ' ').replace(/\n/g,'\r\n'));
|
||||
this.exit();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
CommandNamespace.namespaces.set('set', CommandSet);
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"native": {
|
||||
"endpoints": [
|
||||
"./native/js.js",
|
||||
"./native/set.js"
|
||||
],
|
||||
"commands": [
|
||||
"js",
|
||||
"jsecho",
|
||||
"set"
|
||||
]
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:0}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm .xterm-scroll-area{visibility:hidden}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm .xterm-cursor-pointer,.xterm.xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) ::selection{color:transparent}.xterm .xterm-accessibility-tree{user-select:text;white-space:pre}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue