Skip to content

Commit 83eceeb

Browse files
committed
Wheee! What a lineup!!!
1 parent 81d2ec1 commit 83eceeb

7 files changed

Lines changed: 207 additions & 127 deletions

File tree

apps/Terminal.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ Now scrutinizing handleBackspace @MSKEUTJDK. Just want to enable basic multi-lin
106106
//»
107107

108108
//This means that the terminal app window is reloaded by Ctrl+r (there is no onreload on the app)
109-
//let NO_ONRELOAD = true;
109+
//let USE_ONRELOAD = false;
110110

111111
let RELOAD_TERM_ONRELOAD = false;
112+
112113
//This means that the terminal app's onreload method is set to _onreload (to reload the shell)
113-
let NO_ONRELOAD = false;
114+
let USE_ONRELOAD = true;
115+
//let NO_ONRELOAD = false;
114116
//Terminal Imports«
115117
const NS = LOTW;
116118
const util = LOTW.api.util;
@@ -235,8 +237,6 @@ if (dev_mode){
235237

236238
//Terminal«
237239

238-
//let USE_ONDEVRELOAD = false;
239-
240240
export const app = class {
241241

242242
//Private Vars«
@@ -2626,9 +2626,6 @@ async respInit(addMessage){//«
26262626

26272627
let init_prompt = `LOTW shell`;
26282628
if (!Desk.isFake) init_prompt +=`\x20(${this.winid.replace("_","#")})`
2629-
// if(dev_mode){
2630-
// init_prompt+=`\nReload terminal: ${!USE_ONDEVRELOAD}`;
2631-
// }
26322629
if (admin_mode){
26332630
init_prompt+=`\nAdmin mode: true`;
26342631
}
@@ -3608,8 +3605,13 @@ if (RELOAD_TERM_ONRELOAD) await this.Win.reload({appOnly: true});
36083605
}//»
36093606
async _onreload(){
36103607

3611-
await this._reloadShell();
3612-
// await this.ShellMod.util.deleteMods(["term.vim"]);
3608+
// await this._reloadShell();
3609+
3610+
let mod = "games.poker";
3611+
if (!this.ShellMod.allLibs[mod]) return;
3612+
this.doOverlay(`Delete: ${mod}`);
3613+
await this.ShellMod.util.deleteMods([mod]);
3614+
await this.ShellMod.util.doImports([mod], cerr);
36133615

36143616
}
36153617

@@ -3669,10 +3671,10 @@ async onappinit(appargs={}){//«
36693671
if (!reInit) {
36703672
reInit = {};
36713673
}
3672-
if (!NO_ONRELOAD) this.onreload = this._onreload;
3674+
// if (!NO_ONRELOAD) this.onreload = this._onreload;
3675+
if (USE_ONRELOAD) this.onreload = this._onreload;
36733676
// let {termBuffer, addMessage, commandStr, histories, useOnDevReload} = reInit;
36743677
let {termBuffer, addMessage, commandStr, histories} = reInit;
3675-
// if (isBool(useOnDevReload)) USE_ONDEVRELOAD = useOnDevReload;
36763678
await this.initHistory(termBuffer);
36773679
await this.respInit(addMessage);
36783680
this.didInit = true;
@@ -3685,7 +3687,6 @@ async onappinit(appargs={}){//«
36853687
for (let c of commandStr) this.handleLetterPress(c);
36863688
this.handleEnter({noSave: true});
36873689
};
3688-
// if (USE_ONDEVRELOAD) this.ondevreload = this._ondevreload;
36893690
}//»
36903691

36913692
onescape(){//«

coms/games/poker.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Imports«
2+
3+
const {Com} = LOTW.globals.ShellMod.comClasses;
4+
const{isArr,isStr,isEOF,log,jlog,cwarn,cerr}=LOTW.api.util;
5+
6+
//»
7+
8+
//Commands«
9+
const com_poker = class extends Com {
10+
run(){
11+
this.ok("Hello Poker2: That was honslerativity!!!!!");
12+
}
13+
}
14+
//»
15+
16+
const coms = {//«
17+
poker: com_poker,
18+
}//»
19+
20+
export { coms };
21+

mods/lang/shell.js

Lines changed: 98 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ const make_sh_err_com = (name, mess, com_env)=>{//«
734734
};//»
735735

736736
const get_options = (args, com, opts={}) => {//«
737-
const getlong = opt => {
737+
const getlong = opt => {//«
738738
let re = new RegExp("^" + opt);
739739
let numhits = 0;
740740
let okkey;
@@ -747,15 +747,16 @@ const get_options = (args, com, opts={}) => {//«
747747
if (!numhits) {
748748
err.push(`invalid option: '${opt}'`);
749749
return null;
750-
} else if (numhits == 1) return okkey;
750+
}
751+
else if (numhits == 1) return okkey;
751752
else {
752-
err.push(`option: '${opt}' has multiple hits`);
753+
err.push(`option '${opt}' has multiple hits`);
753754
return null;
754755
}
755-
};
756+
};//»
756757
let err = [];
757-
let sopts = opts.SHORT || opts.s;
758-
let lopts = opts.LONG || opts.l;
758+
let sopts = opts.short || opts.SHORT || opts.s;
759+
let lopts = opts.long || opts.LONG || opts.l;
759760
let getall = opts.ALL;
760761
// let getall = true;
761762
let obj = {};
@@ -777,7 +778,8 @@ const get_options = (args, com, opts={}) => {//«
777778
args.splice(i, 1);
778779
return [obj, err];
779780
}
780-
else if (marr = args[i].match(/^-([a-zA-Z0-9][a-zA-Z0-9]+)$/)) {
781+
//Short opts
782+
else if (marr = args[i].match(/^-([a-zA-Z0-9][a-zA-Z0-9]+)$/)) {//«
781783
let arr = marr[1].split("");
782784
for (let j = 0; j < arr.length; j++) {
783785
ch = arr[j];
@@ -791,8 +793,8 @@ const get_options = (args, com, opts={}) => {//«
791793
else err.push(`option: '${ch}' has an invalid option definition: ${sopts[ch]}`);
792794
}
793795
args.splice(i, 1);
794-
}
795-
else if (marr = args[i].match(/^-([a-zA-Z0-9])$/)) {
796+
}//»
797+
else if (marr = args[i].match(/^-([a-zA-Z0-9])$/)) {//«
796798
ch = marr[1];
797799
if (getall){
798800
if (!args[i + 1]) err.push(`option: '${ch}' requires an arg`);
@@ -802,47 +804,69 @@ const get_options = (args, com, opts={}) => {//«
802804
else if (!sopts[ch]) {
803805
err.push(`invalid option: '${ch}'`);
804806
args.splice(i, 1);
805-
} else if (sopts[ch] === 1) {
807+
}
808+
else if (sopts[ch] === 1) {
806809
obj[ch] = true;
807810
args.splice(i, 1);
808-
} else if (sopts[ch] === 2) {
809-
err.push(`option: '${ch}' is an optional arg`);
811+
}
812+
else if (sopts[ch] === 2) {
813+
// err.push(`option: '${ch}' is an optional arg`);
810814
args.splice(i, 1);
811-
} else if (sopts[ch] === 3) {
815+
if (args[i]&&!args[i].match(/^-/)){
816+
obj[ch] = args[i];
817+
}
818+
else obj[ch] = true;
819+
}
820+
else if (sopts[ch] === 3) {
812821
if (!args[i + 1]) err.push(`option: '${ch}' requires an arg`);
813822
obj[ch] = args[i + 1];
814823
args.splice(i, 2);
815-
} else {
824+
}
825+
else {
816826
err.push(`option: '${ch}' has an invalid option definition: ${sopts[ch]}`);
817827
args.splice(i, 1);
818828
}
819-
} else if (marr = args[i].match(/^--([a-zA-Z0-9][-a-zA-Z0-9]+)=(.+)$/)) {
820-
if (getall || (ret = getlong(marr[1]))) {
821-
if (getall) ret = marr[1];
829+
}//»
830+
831+
//Long opts
832+
else if (marr = args[i].match(/^--([a-zA-Z0-9][-a-zA-Z0-9]+)=(.+)$/)) {//«
833+
let lopt = marr[1];
834+
if (lopts[lopt] === 1){
835+
err.push(`option '${lopt}' requires no arg`);
836+
}
837+
// if (getall || (ret = getlong(marr[1]))) {
838+
else {
839+
if (getall || (ret = getlong(lopt))) {
840+
if (getall) ret = lopt;
822841
obj[ret] = marr[2];
823842
}
824-
args.splice(i, 1);
825-
} else if (marr = args[i].match(/^--([a-zA-Z0-9][-a-zA-Z0-9]+)=$/)) {
843+
}
844+
args.splice(i, 1);
845+
}//»
846+
else if (marr = args[i].match(/^--([a-zA-Z0-9][-a-zA-Z0-9]+)=$/)) {//«
826847
if (getall || (ret = getlong(marr[1]))) {
827848
if (getall) ret = marr[1];
828849
obj[ret] = args[i + 1];
829850
if (args[i + 1]) args.splice(i + 1, 2);
830851
else args.splice(i, 1);
831-
} else args.splice(i, 1);
832-
} else if (marr = args[i].match(/^--([a-zA-Z0-9][-a-zA-Z0-9]+)$/)) {
852+
}
853+
else args.splice(i, 1);
854+
}//»
855+
else if (marr = args[i].match(/^--([a-zA-Z0-9][-a-zA-Z0-9]+)$/)) {//«
833856
if (getall || (ret = getlong(marr[1]))) {
834857
if (getall) ret = marr[1];
835858
if (getall || (lopts[marr[1]] === 1 || lopts[marr[1]] === 2)) obj[ret] = true;
836859
else if (lopts[marr[1]] === 3) err.push(`long option: '${marr[1]}' requires an arg`);
837860
else if (lopts[marr[1]]) err.push(`long option: '${marr[1]}' has an invalid option definition: ${lopts[marr[1]]}`);
838861
else if (!lopts[marr[1]]) err.push(`invalid long option: '${marr[1]}`);
839862
args.splice(i, 1);
840-
} else args.splice(i, 1);
841-
}
842-
else if (marr = args[i].match(/^(---+[a-zA-Z0-9][-a-zA-Z0-9]+)$/)) {
863+
}
864+
else args.splice(i, 1);
865+
}//»
866+
else if (marr = args[i].match(/^(---+[a-zA-Z0-9][-a-zA-Z0-9]+)$/)) {//«
843867
err.push(`invalid option: '${marr[1]}'`);
844868
args.splice(i, 1);
845-
}
869+
}//»
846870
else i++;
847871
}
848872
return [obj, err];
@@ -922,10 +946,7 @@ cwarn(`The option ${opt} already exists!`);
922946
sh_opts[opt] = opts[opt];
923947
}
924948
NS.coms[libname] = {coms, opts};
925-
926949
return ok_coms.length;
927-
// NS.libs[libname] = {coms, opts};
928-
929950
}//»
930951
const do_imports = async(arr, err_cb) => {//«
931952
if (!err_cb) err_cb = ()=>{};
@@ -994,12 +1015,13 @@ const delete_mods=(arr)=>{//«
9941015
if (scr) {
9951016
scr._del();
9961017
}
997-
else{
998-
//cwarn(`The module ${m} was not loaded!`);
999-
continue;
1000-
}
10011018
delete NS.mods[m];
1002-
//log(`Deleted module: ${m}`);
1019+
let coms = this.allLibs[m];
1020+
for (let com of coms){
1021+
delete globals.shell_commands[com];
1022+
}
1023+
delete this.allLibs[m];
1024+
10031025
}
10041026
}//»
10051027
this.util={
@@ -2044,7 +2066,7 @@ run(){
20442066
/*
20452067
continue's and break's *ALWAYS* break the "circuitry" of the logic lists.
20462068
*/
2047-
2069+
/*Now in Grok.js
20482070
const com_devtest = class extends Com{//«
20492071
init(){
20502072
}
@@ -2073,7 +2095,47 @@ log(resps);
20732095
this.ok();
20742096
}
20752097
}//»
2098+
*/
2099+
2100+
const com_devtest = class extends Com{//«
2101+
2102+
static getOpts(){
2103+
//Option values
2104+
//1: no arguments
2105+
//2: optional arguments
2106+
//3: required argument
2107+
return {
2108+
"long": {"longa": 1, "longb": 2, "longc": 3},
2109+
"short": {"a": 1, "b": 2, "c": 3}
2110+
}
2111+
}
2112+
async init(){
2113+
//Initialiation: option validation or resource loading may go here
2114+
}
2115+
async run(){
2116+
const{args, opts, term} = this;
2117+
2118+
// args: e.g. [ "arg1", "arg2", ... , "argn" ]
2119+
// opts: e.g. {a: true, longb: "hello world", c: 42}
2120+
// term: a handle to the terminal object with many members
2121+
2122+
this.wrn("Warnings are printed to the terminal in yellow");
2123+
this.inf("Info messages are printed in blue");
2124+
this.err("Errors are printed in red");
2125+
this.suc("This is printed in green");
2126+
2127+
this.out("This gets sent to pipes, command substitutions or stdout");
20762128

2129+
// The following methods end the command by internally resolving a promise
2130+
// this.end(123);//Allows for arbitrary error codes to be returned
2131+
2132+
// The following are convenience functions which can be called with an optional string to be printed to the terminal
2133+
this.ok();//This returns a success code and any string arg printed to the terminal in green
2134+
// this.no();//This returns the standard error code (1) and any string is printed in red
2135+
// this.nok();//This calls this.ok() or this.no() depending on whether this.numErrors > 0
2136+
2137+
}
2138+
}//»
20772139
const com_wat2wasm = class extends Com{//«
20782140

20792141
async init(){//«
@@ -2458,19 +2520,10 @@ const com_echo = class extends Com{//«
24582520
return {s: {n: 1}};
24592521
}
24602522
async run(){
2461-
2462-
// this.out(this.args.join(" "));
24632523
let nl = this.opts.n ? "":"\n";
2464-
// let str = new String(this.args.join(" ")+"\n");
24652524
let str = new String(this.args.join(" ")+nl);
2466-
//log(str.length);
24672525
str.noChomp = true;
24682526
this.out(str);
2469-
2470-
//XQMNHI
2471-
//For some reason, this sleep is *required* in order to make this behave correctly:
2472-
// $ echo HELLO | while read LINE; do echo $LINE; done
2473-
// await sleep(0);
24742527
this.ok();
24752528
}
24762529
}//»
@@ -2708,12 +2761,12 @@ const com_stringify = class extends Com{/*«*/
27082761
}
27092762
}
27102763
}/*»*/
2711-
const com_clear = class extends Com{/*«*/
2764+
const com_clear = class extends Com{/
27122765
run(){
27132766
this.term.clear();
27142767
this.ok();
27152768
}
2716-
}/*»*/
2769+
}/
27172770
const com_colon = class extends Com{//«
27182771
run(){
27192772
this.ok();

0 commit comments

Comments
 (0)