Skip to content

Commit 8098859

Browse files
committed
I'm crushing your head!
1 parent 0a1e0b3 commit 8098859

2 files changed

Lines changed: 62 additions & 38 deletions

File tree

apps/Terminal.js

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,6 @@ const Com = class {//«
13391339
this.opts=opts;
13401340
this.numErrors = 0;
13411341
this.noPipe = false;
1342-
// this.inBack = in_background;
13431342
for (let k in env) {
13441343
this[k]=env[k];
13451344
}
@@ -1463,6 +1462,15 @@ log(num);
14631462
resp(str, opts={}){//«
14641463
if (this.shell.cancelled) return;
14651464
const{term}=this;
1465+
if (this.inBackground){
1466+
if (opts.isErr){
1467+
console.error(str);
1468+
}
1469+
else{
1470+
console.log(str);
1471+
}
1472+
return;
1473+
}
14661474
opts.name = this.name;
14671475
term.response(str, opts);
14681476
term.scrollIntoView();
@@ -3885,17 +3893,17 @@ async scanQuote(par, which, in_backquote, cont_quote){//«
38853893
this.index=cur;
38863894
if (this.source[cur+2]==="("){
38873895
// rv = await this.scanComSub(quote, true, is_bq||in_backquote);
3888-
rv = await this.scanSub(quote, {isMath: true, inBack: is_bq||in_backquote});
3896+
rv = await this.scanSub(quote, {isMath: true, inBQ: is_bq||in_backquote});
38893897
if (rv===null) this.throwUnexpectedToken(`unterminated math expression`);
38903898
}
38913899
else if (this.source[cur+1]==="{"){
38923900
// rv = await this.scanComSub(quote, true, is_bq||in_backquote);
3893-
rv = await this.scanSub(quote, {isParam: true, inBack: is_bq||in_backquote});
3901+
rv = await this.scanSub(quote, {isParam: true, inBQ: is_bq||in_backquote});
38943902
if (rv===null) this.throwUnexpectedToken(`unterminated parameter substitution`);
38953903
}
38963904
else{
38973905
// rv = await this.scanComSub(quote, null, is_bq||in_backquote);
3898-
rv = await this.scanSub(quote, {isComSub: true, inBack: is_bq||in_backquote});
3906+
rv = await this.scanSub(quote, {isComSub: true, inBQ: is_bq||in_backquote});
38993907
if (rv===null) this.throwUnexpectedToken(`unterminated command substitution`);
39003908
}
39013909
if (isStr(rv)) this.throwUnexpectedToken(rv);
@@ -4015,7 +4023,7 @@ let is_comsub = opts.isComSub;
40154023
if (!(is_math||is_param||is_comsub)){
40164024
throw new Error("NOT is_comsub || is_math || is_param ?!?!? HJKHFDK^&*^$*&#");
40174025
}
4018-
let in_backquote = opts.inBack;
4026+
let in_backquote = opts.inBQ;
40194027
let cont_sub = opts.contSub;
40204028

40214029
////async scanComSub(par, is_math, in_backquote, cont_sub){
@@ -4085,15 +4093,15 @@ else if (ch==="$"&&(this.source[cur+1]==="("||this.source[cur+1]==="{")){//«
40854093
if (this.source[cur+2]==="("){
40864094
this.index=cur;
40874095
// let rv = await this.scanComSub(sub, true, in_backquote);
4088-
let rv = await this.scanSub(sub, {isMath: true, inBack: in_backquote});
4096+
let rv = await this.scanSub(sub, {isMath: true, inBQ: in_backquote});
40894097
if (rv===null) return `unterminated math expansion`;
40904098
if (isStr(rv)) return rv;
40914099
out.push(rv);
40924100
cur=this.index;
40934101
}
40944102
else if (this.source[cur+1]==="{"){
40954103
this.index=cur;
4096-
let rv = await this.scanSub(sub, {isParam: true, inBack: in_backquote});
4104+
let rv = await this.scanSub(sub, {isParam: true, inBQ: in_backquote});
40974105
if (rv===null) return `unterminated parameter expansion`;
40984106
if (isStr(rv)) return rv;
40994107
out.push(rv);
@@ -4103,7 +4111,7 @@ else if (ch==="$"&&(this.source[cur+1]==="("||this.source[cur+1]==="{")){//«
41034111
this.index=cur;
41044112
////async scanComSub(par, is_math, in_backquote, cont_sub){
41054113
// let rv = await this.scanComSub(sub, false, in_backquote);
4106-
let rv = await this.scanSub(sub, {isComSub: true, inBack: true});
4114+
let rv = await this.scanSub(sub, {isComSub: true, inBQ: true});
41074115
if (rv===null) return `unterminated command substitution`;
41084116
if (isStr(rv)) return rv;
41094117
out.push(rv);
@@ -4169,7 +4177,7 @@ if (this.eol()){
41694177
sub.val = out;
41704178
await this.more();
41714179
// return await this.scanComSub(par, is_math, in_backquote, sub);
4172-
return await this.scanSub(par, {isMath: is_math, isComSub: is_comsub, isParam: is_param, inBack: in_backquote, contSub: sub, parenDepth: paren_depth});
4180+
return await this.scanSub(par, {isMath: is_math, isComSub: is_comsub, isParam: is_param, inBQ: in_backquote, contSub: sub, parenDepth: paren_depth});
41734181
}
41744182

41754183

@@ -6609,23 +6617,18 @@ async makeScriptCom(com_ast, comopts){//«
66096617
return com;
66106618
}//»
66116619

6612-
async executePipeline(pipe, loglist, loglist_iter, opts){//«
6620+
async executePipeline(pipe, loglist, loglist_iter, opts, in_background){//«
66136621
const{term}=this;
6614-
// const make_sh_err_com = ShellMod.util.make_sh_err_com;
6615-
// const make_sh_err_com = make_sh_error_com;
66166622
let lastcomcode;
6617-
// let {stdin: optStdin, scriptOut, scriptArgs, scriptName, subLines, heredocScanner, env, isInteractive}=opts;
6618-
// let {stdin: optStdin, scriptArgs, scriptName, subLines, heredocScanner, env, isInteractive, loopNum}=opts;
66196623
let {stdin: optStdin, env}=opts;
6620-
let in_background = false;
6624+
// let in_background = false;
66216625
let pipelist = pipe.pipe;
66226626
if (!pipelist){
66236627
return `sh: pipeline list not found!`;
66246628
}
66256629
let pipetype = pipe.type;
66266630
let pipeline = [];
66276631
let hasBang = pipe.hasBang;
6628-
let screenGrab = {grabber: ""};
66296632
let last_com;
66306633
for (let j=0; j < pipelist.length; j++) {//«
66316634
let com_ast = pipelist[j];
@@ -6665,7 +6668,7 @@ log(red);
66656668
else comopts.stdinLns = comopts.stdin.split("\n");
66666669
}
66676670
comopts.outRedir = out_redir;
6668-
6671+
comopts.inBackground = in_background;
66696672
if (last_com){//«
66706673
//XWMNJUO
66716674
let env_readline = new EnvReadLine(term);
@@ -6688,8 +6691,6 @@ log(red);
66886691
}
66896692
else if (com_ast.simple_command){
66906693
com = await this.makeCommand(com_ast.simple_command, comopts)
6691-
//log(com);
6692-
//if (com.isExit === true) return com;
66936694
if (com.breakStatementLoop === true) return com;
66946695
}
66956696
else{//«
@@ -6724,6 +6725,7 @@ comopts.envReadLine = "Blarney stone in the YADDER YADDER YADDER MCSLADDER!?!?!?
67246725
}
67256726
*/
67266727
}
6728+
com.inBackground = in_background;
67276729
pipeline.push(com);
67286730
last_com = com;
67296731
}//»
@@ -6819,8 +6821,8 @@ we *ALWAYS* break from the logic list, so we return
68196821
}
68206822
//»
68216823

6822-
async executeAndOr(andor_list, andor_sep, opts){//«
6823-
6824+
async executeAndOr(andor_list, andor_sep, opts, in_background){//«
6825+
//let in_background = opts.inBackground || andor_sep === "&";
68246826
let loglist=[];
68256827
let last = andor_list.pop();
68266828
for (let i=0; i < andor_list.length-1; i+=2){
@@ -6836,7 +6838,7 @@ andor_list.push(last);
68366838
let lastcomcode;
68376839
for (let i=0; i < loglist.length; i++){//«
68386840

6839-
let rv = await this.executePipeline(loglist[i], loglist, i, opts);
6841+
let rv = await this.executePipeline(loglist[i], loglist, i, opts, in_background);
68406842
//continue;
68416843
if (this.cancelled) return;
68426844
// if (this.cancelled) continue;
@@ -6868,12 +6870,45 @@ cwarn("CONTINUE", i, rv.nextIter);
68686870
return lastcomcode;
68696871

68706872
}//»
6871-
6873+
/*Safe version
6874+
async executeStatements(statements, opts){//«
6875+
const{term}=this;
6876+
let lastcomcode;
6877+
for (let i=0; i < statements.length-1; i+=2){
6878+
lastcomcode = await this.executeAndOr(statements[i].andor, statements[i+1], opts, opts.inBackground || statements[i+1] === "&");
6879+
if (isObj(lastcomcode) && lastcomcode.breakStatementLoop) {
6880+
return lastcomcode.code;
6881+
}
6882+
if (isLoopCont(lastcomcode)||isLoopBreak(lastcomcode)) return lastcomcode;
6883+
}
6884+
return lastcomcode;
6885+
}//»
6886+
*/
6887+
///*
68726888
async executeStatements(statements, opts){//«
68736889
const{term}=this;
68746890
let lastcomcode;
68756891
for (let i=0; i < statements.length-1; i+=2){
6876-
lastcomcode = await this.executeAndOr(statements[i].andor, statements[i+1], opts);
6892+
let in_background = opts.inBackground || statements[i+1] === "&";
6893+
if (statements[i+1] === "&"){
6894+
/*
6895+
In bash, when the '&' is used immediately, like:
6896+
$ if sleep 1 && false & then echo hi; else echo ho; fi
6897+
this evaluates to true, and hi is output
6898+
*/
6899+
this.executeAndOr(statements[i].andor, statements[i+1], opts, true);
6900+
lastcomcode = E_SUC;
6901+
}
6902+
else{
6903+
6904+
/*
6905+
If this is a compound command, invoked like:
6906+
$ ./myscript.sh &
6907+
This does *not* immediately return, which is particularly noticeable if there are long
6908+
running processes (or just sleep statements) inside of the script
6909+
*/
6910+
lastcomcode = await this.executeAndOr(statements[i].andor, statements[i+1], opts, in_background);
6911+
}
68776912
// if (isObj(lastcomcode) && lastcomcode.breakStatementLoop) break;
68786913
if (isObj(lastcomcode) && lastcomcode.breakStatementLoop) {
68796914
return lastcomcode.code;
@@ -6882,6 +6917,7 @@ async executeStatements(statements, opts){//«
68826917
}
68836918
return lastcomcode;
68846919
}//»
6920+
//*/
68856921

68866922
//SLDPEHDBF
68876923
async compile(command_str, opts={}){//«
@@ -9420,19 +9456,7 @@ log(out);
94209456
opts = {isErr: true};
94219457
}
94229458

9423-
let {didFmt, colors, pretty, isErr, isSuc, isWrn, isInf, inBack, noBr} = opts;
9424-
if (inBack){
9425-
if (isErr){
9426-
cerr(out);
9427-
}
9428-
else if (isWrn){
9429-
cwarn(out);
9430-
}
9431-
else{
9432-
log(out);
9433-
}
9434-
return;
9435-
}
9459+
let {didFmt, colors, pretty, isErr, isSuc, isWrn, isInf, noBr} = opts;
94369460
if (out == "" && out.isNL){
94379461
out=" \n ";
94389462
}

list.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["README.md/2548","apps",["Audio.js/4093","BinView.js/9814","Folder.js/10944","Help.js/979","MediaPlayer.js/2074","Meta.js/2279","Music.js/4844","NN.js/1136","Poker.js/41043","Something.js/32","Terminal.js/256684","TextEdit.js/5174","WorkMan.js/3808","YourApp.js/418","dev",["Ermpt.js/507","Grammar.js/15536","HTML.js/1348","Hands.js/15575","Kuhn.js/7362","Launcher.js/20502","NewShell.js/84972","Player.js/2121","Poker5.js/4891","TakePicture.js/3475","Worker.js/1195","audio",["Blah.js/3601","MakeSomeBass.js/5879","Midi.js/3953","Noise.js/2048","Vowels.js/13141","cool",["RandomWalk.js/5090"],"zsave",["Faust.js/35023","Jazzed.js/18165","Jazzed2.js/31797","Karplus.js/30845","Noisecraft.js/11936"]],"svg",["SVG1.js/12599","SVG2.js/18599"],"zold",["Poker.js/26967","Poker2.js/76136","Poker3.js/65113","Poker4.js/36503"]],"games",["Arcade.js/12599"],"hw",["MidiCtl.js/3691"],"media",["2Cameras.js/3258","Camera.js/3673","MediaPlayer.js/16115","VideoCutter.js/44729"],"template",["Basic.js/489","Template.js/396","WebAudio.js/2877"],"util",["ImageView.js/2696","Unicoder.js/16896"]],"bin",["ALLLIST/106","APPLIST/104","DIRGET/47","DOBEAUTIFY/71","DOLINKS/330","DOZIP/801","GITUP/396","MKLOTWLIST/136","MKSYMLINKS/487","PYSERV/84","SSLPYSERV.py/528","dojsbeautify/71","js",["getdir.js/665"],"vallgrep/398","vvallgrep/544"],"coms",["audio.js/1766","esprima.js/171824","extra.js/10807","fs.js/26758","mail.js/43901","shell.js/175037","template.js/336","test",["dummy.js/21"],"test.js/1982","yt.js/66863","zhold",["mail.js/22724"]],"doc",["EDITING/1847","START_HERE/2609","apis",["imap-flow.js/104043","imapflow.txt/38670"],"concepts",["DATA_IPC/4482"],"dev",["CHANGES/2853","DESK/63027","FS/7462","TERMINAL/149463","VIM/16037"]],"index.html/1184","init",["my_setup.js/1264"],"local",["_poker",["001/19229","003/23581","FLOP_EV_1.json/3312805","FLOP_EV_2.json/3389041","FLOP_EV_3.json/3719620","FLOP_EV_4.json/3503737","FLOP_EV_5.js/3470856","RIVER_EV_1.json/38068483","RIVER_EV_2.json/39745965","RIVER_EV_3.json/44070681","RIVER_EV_4.json/41514544","RIVER_EV_5.json/41100610","TURN_EV_1.json/17598825","TURN_EV_2.json/18032587","TURN_EV_3.json/19787973","TURN_EV_4.json/18622556","TURN_EV_5.json/18423232"]],"mods",["audio",["multi_freq_worklet.js/1502","random_walk_worklet.js/3039"],"games",["GBEmulator.js/9708","NESEmulator.js/222309","binjgb.wasm/87232"],"help",["shell.js/3591"],"hw",["midi.js/2323"],"term",["email.js/10406","less.js/19368","log.js/13262","vim.js/150516"],"util",["math.js/12125","nn",["snake",["worker.js/29373"]],"pretty.js/93856","walt.js/204893","wasm.js/42764","wasmparser.js/34331","webmparser.js/58730"],"workers",["poker.js/37420"]],"node",["server.js/7198","svcs",["imap.js/17772","mount.js/16553","smtp.js/1359","template.js/1831","ws.js/2156","ytdl.js/11982"]],"sys",["config.js/8812","desk.js/216683","fs.js/66130","util.js/20006"],"www",["blog.css/181","config",["bashrc.txt/692","desert.vim/2952","nano-hack.txt/2324","vimrc.txt/1443"],"desk.css/1898","docs",["blog-template.html/291","help.html/9104","what-it-is.html/4370"],"examples",["test.sh/66"],"favicon.ico/15086","lotw256.png/41075","lotw48.png/2966","stuff",["noise.html/1669"]],"zzhold",["DESK/1306","SHELL/17941","noisecraft",["audiograph.js/22588","audioview.js/5086","audioworklet.js/1319","compiler.js/15169","dialog.js/3578","editor.js/72623","eventable.js/965","knob.js/10041","midi.js/2044","model.js/57480","music.js/7887","synth.js/6652","utils.js/6876","zhold",["audioworklet.js/2980","compiler.js/37421","model.js/57645"]],"writes",["RUNTIME.js/4583","Terminal.js/80662"]]]
1+
["README.md/2548","apps",["Audio.js/4093","BinView.js/9814","Folder.js/10944","Help.js/979","MediaPlayer.js/2074","Meta.js/2279","Music.js/4844","NN.js/1136","Poker.js/41043","Something.js/32","Terminal.js/257501","TextEdit.js/5174","WorkMan.js/3808","YourApp.js/418","dev",["Ermpt.js/507","Grammar.js/15536","HTML.js/1348","Hands.js/15575","Kuhn.js/7362","Launcher.js/20502","NewShell.js/84972","Player.js/2121","Poker5.js/4891","TakePicture.js/3475","Worker.js/1195","audio",["Blah.js/3601","MakeSomeBass.js/5879","Midi.js/3953","Noise.js/2048","Vowels.js/13141","cool",["RandomWalk.js/5090"],"zsave",["Faust.js/35023","Jazzed.js/18165","Jazzed2.js/31797","Karplus.js/30845","Noisecraft.js/11936"]],"svg",["SVG1.js/12599","SVG2.js/18599"],"zold",["Poker.js/26967","Poker2.js/76136","Poker3.js/65113","Poker4.js/36503"]],"games",["Arcade.js/12599"],"hw",["MidiCtl.js/3691"],"media",["2Cameras.js/3258","Camera.js/3673","MediaPlayer.js/16115","VideoCutter.js/44729"],"template",["Basic.js/489","Template.js/396","WebAudio.js/2877"],"util",["ImageView.js/2696","Unicoder.js/16896"]],"bin",["ALLLIST/106","APPLIST/104","DIRGET/47","DOBEAUTIFY/71","DOLINKS/330","DOZIP/801","GITUP/396","MKLOTWLIST/136","MKSYMLINKS/487","PYSERV/84","SSLPYSERV.py/528","dojsbeautify/71","js",["getdir.js/665"],"vallgrep/398","vvallgrep/544"],"coms",["audio.js/1766","esprima.js/171824","extra.js/10807","fs.js/26758","mail.js/43901","shell.js/175037","template.js/336","test",["dummy.js/21"],"test.js/1982","yt.js/66863","zhold",["mail.js/22724"]],"doc",["EDITING/1847","START_HERE/2609","apis",["imap-flow.js/104043","imapflow.txt/38670"],"concepts",["DATA_IPC/4482"],"dev",["CHANGES/2853","DESK/63027","FS/7462","TERMINAL/149463","VIM/16037"]],"index.html/1184","init",["my_setup.js/1264"],"local",["_poker",["001/19229","003/23581","FLOP_EV_1.json/3312805","FLOP_EV_2.json/3389041","FLOP_EV_3.json/3719620","FLOP_EV_4.json/3503737","FLOP_EV_5.js/3470856","RIVER_EV_1.json/38068483","RIVER_EV_2.json/39745965","RIVER_EV_3.json/44070681","RIVER_EV_4.json/41514544","RIVER_EV_5.json/41100610","TURN_EV_1.json/17598825","TURN_EV_2.json/18032587","TURN_EV_3.json/19787973","TURN_EV_4.json/18622556","TURN_EV_5.json/18423232"]],"mods",["audio",["multi_freq_worklet.js/1502","random_walk_worklet.js/3039"],"games",["GBEmulator.js/9708","NESEmulator.js/222309","binjgb.wasm/87232"],"help",["shell.js/3591"],"hw",["midi.js/2323"],"term",["email.js/10406","less.js/19368","log.js/13262","vim.js/150516"],"util",["math.js/12125","nn",["snake",["worker.js/29373"]],"pretty.js/93856","walt.js/204893","wasm.js/42764","wasmparser.js/34331","webmparser.js/58730"],"workers",["poker.js/37420"]],"node",["server.js/7198","svcs",["imap.js/17772","mount.js/16553","smtp.js/1359","template.js/1831","ws.js/2156","ytdl.js/11982"]],"sys",["config.js/8812","desk.js/216683","fs.js/66130","util.js/20006"],"www",["blog.css/181","config",["bashrc.txt/692","desert.vim/2952","nano-hack.txt/2324","vimrc.txt/1443"],"desk.css/1898","docs",["blog-template.html/291","help.html/9104","what-it-is.html/4370"],"examples",["test.sh/66"],"favicon.ico/15086","lotw256.png/41075","lotw48.png/2966","stuff",["noise.html/1669"]],"zzhold",["DESK/1306","SHELL/17941","noisecraft",["audiograph.js/22588","audioview.js/5086","audioworklet.js/1319","compiler.js/15169","dialog.js/3578","editor.js/72623","eventable.js/965","knob.js/10041","midi.js/2044","model.js/57480","music.js/7887","synth.js/6652","utils.js/6876","zhold",["audioworklet.js/2980","compiler.js/37421","model.js/57645"]],"writes",["RUNTIME.js/4583","Terminal.js/80662"]]]

0 commit comments

Comments
 (0)