Skip to content

Commit 8de7822

Browse files
Meeper mupper moooo
1 parent 40dfe50 commit 8de7822

1 file changed

Lines changed: 153 additions & 27 deletions

File tree

mods/term/vim.js

Lines changed: 153 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
1-
/*8/9/25:
1+
//(()=>{"use strict";const MODNAME="term.vim";//Comment this whole line OUT!
2+
3+
/*12/19/25: Just need to upload this to the site in order to start working on local commands.
4+
First, the outer wrapper function needs to be commented out, then the comments of the
5+
two lines under @FSWOUXNM need to be reversed. Then when the rest of the system has caught
6+
up to reverting back to this non-module-based method, then the comments can be reversed
7+
back to how they are right now.
8+
29
*/
10+
/*12/18/25: Developing commands internally with vim«
11+
12+
I want to iterate on the note (below) from 12/24/25 @SMERUTJ so that the file I
13+
am working on is interpreted as a command library, and the commands can get
14+
exported into some Terminal's shell as "dev.<comname>" (let's reserve
15+
"dev.WHATEVER") for only commands that go through this vim-based workflow. The
16+
relevant workflow begins @SDHRYWOEL1, upon hitting the r_CA hotkey. So instead
17+
of dealing in the LOTW.apps namespace, we want to use (something like)
18+
LOTW.coms["local.<base_filename>"].
19+
20+
Then by way of another terminal's API, I want to be able to automatically
21+
load/reload the library in its com_env and send a CLI string into it.
22+
23+
Now there is a very crude little workflow there (@SDHRYWOEL2) to use Ctrl+Alr+r to initialize
24+
a "slave terminal" (accessible as reload_win.app).
25+
26+
Then Alt+r will load/reload that terminal's command environment with the command
27+
libary we are editing in vim, such that each new command is accessible as dev.<modname>.<comname>.
28+
29+
Then ":x <command_goes_here>" will save <command_goes_here> into
30+
the global variable 'cur_background_command', so that
31+
the Ctrl+Alt+x shortcut @KSJTUSHF calls reload_win.app.autoTypeCommand(cur_background_command).
32+
33+
Sample file contents:
34+
35+
<FILE BEGIN>
36+
const {Com}=LOTW.globals.ShellMod.comClasses;
37+
class com_mycom extends Com{
38+
static getOpts(){return {q:{1}};}
39+
run(){
40+
this.ok("HI");
41+
}
42+
};
43+
const coms={
44+
mycom: com_mycom
45+
};
46+
LOTW.coms["local.<base_file_name>"]={coms};
47+
<FILE END>
48+
49+
If the file is named "newcoms.js" (or vim is invoked with --dev-name=newcoms),
50+
then after reloading with Alt+,r reload_win.app will have the command, 'dev.newcoms.mycom'
51+
in its command environment, and then running this in vim:
52+
:x dev.newcoms.mycom -q blah hoo fooey
53+
...will send the command string "dev.newcoms.mycom -q blah hoo fooey" to that
54+
controlled terminal.
55+
»*/
356
/*8/6/25:«
457
558
Now I am in LOTW, hacking on my vim with my vim!!!
@@ -158,7 +211,7 @@ that are "exported" via globals.refs.<SOME_NS>. We currently flatten out all the
158211
namespaces of globals.refs onto cur_refs (which potentially overwrites
159212
references with the same name that are "exported" by other apps/mods/coms/etc).
160213
»*/
161-
/*12/25/24: Just found out that you do r_CA in order to begin to create«
214+
/*12/25/24: SMERUTJ: Just found out that you do r_CA in order to begin to create«
162215
an application while editing your file, which should at least have this:
163216
164217
LOTW.apps["local.<AppNameHere>"] = function(Win){
@@ -195,7 +248,7 @@ to check for syntax errors (via test_js), using window.onerror.
195248
196249
»*/
197250
//12/24/24: I want to send backgrounded commands to the terminal here.«
198-
let DEF_BACKGROUND_COMMAND = "./hoom.sh";
251+
let DEF_BACKGROUND_COMMAND = 'echo "REPLACE THIS WITH A BETTER COMMAND!"';
199252
//»
200253
/*12/17/24: Yesterday I created the 'goto_matching_brace' functionality«
201254
that attempts to find the matching "}","]" or ")" when a "{", "[", or "("
@@ -283,6 +336,7 @@ keyup with that key while the browser window is in focus).
283336
284337
»*/
285338
//»
339+
286340
//Imports«
287341

288342
//import { util, api as capi } from "util";
@@ -333,13 +387,13 @@ const NUM=(v)=>Number.isFinite(v);
333387

334388
//»
335389

336-
//Vim«
337-
338-
//export const mod = function(Term) {«
390+
//FSWOUXNM (reverse these)
391+
//LOTW.mods[MODNAME] = function(Term) {
339392
export const mod = function(Term) {
393+
340394
//LOTW.mods["local.dev.vim"] = function(Term) {
341395

342-
//»
396+
//Vim«
343397

344398
//Imports«
345399
this.comName="vim";
@@ -407,7 +461,7 @@ let splice_hold;
407461
let is_root = false;
408462

409463
let app_cb;
410-
464+
let reload_script;
411465
let reload_win;
412466
let hold_overrides;
413467

@@ -1386,7 +1440,9 @@ const test_js=()=>{//«
13861440
let str = `()=>{\n${get_edit_str()}\n}`;;
13871441
scr.src = URL.createObjectURL(new Blob([str]));
13881442
};//»
1443+
/*
13891444
const toggle_reload_win=async()=>{//«
1445+
//SDHRYWOEL1
13901446
if (!use_devreload){
13911447
stat_warn("ondevreload was not enabled!");
13921448
return;
@@ -1425,22 +1481,87 @@ cerr("The reload_win was not in topwin.childWins!?!?!");
14251481
reload_win.ownedBy = topwin;
14261482
topwin.childWins.push(reload_win);
14271483
};//»
1484+
*/
1485+
const send_command_to_reload_win=()=>{//«
1486+
if (!reload_win){
1487+
return;
1488+
}
1489+
if (!cur_background_command) cur_background_command = DEF_BACKGROUND_COMMAND;
1490+
cwarn("UNCOMMENT THE LINE BELOW WHEN Terminal.js IS UPDATED");
1491+
// reload_win.app.autoTypeCommand(cur_background_command);
1492+
1493+
//When the above line is uncommented, delete everything below...
1494+
let term_app = reload_win.app;
1495+
if (term_app.sleeping || term_app.curShell){
1496+
cwarn(`Skipping: '${cur_background_command}'`);
1497+
return;
1498+
}
1499+
for (let c of cur_background_command) term_app.handleLetterPress(c);
1500+
term_app.handleEnter({noSave: true});
1501+
};//»
1502+
const toggle_reload_win=async()=>{//«
1503+
if (!use_devreload){
1504+
stat_warn("ondevreload was not enabled!");
1505+
return;
1506+
}
1507+
//SDHRYWOEL2
1508+
if (reload_win){
1509+
let ind = topwin.childWins.indexOf(reload_win);
1510+
if (ind < 0){
1511+
cerr("The reload_win was not in topwin.childWins!?!?!");
1512+
}
1513+
else{
1514+
topwin.childWins.splice(ind, 1);
1515+
}
1516+
delete reload_win.ownedBy;
1517+
reload_win.close();
1518+
reload_win = null;
1519+
stat("'reload_win' deleted");
1520+
return;
1521+
}
1522+
1523+
reload_win = await Desk.api.openApp("Terminal", {force: true});
1524+
if (!reload_win){
1525+
stat_err("Could not get the window");
1526+
return;
1527+
}
1528+
1529+
reload_win.ownedBy = topwin;
1530+
topwin.childWins.push(reload_win);
1531+
};//»
14281532
const reload_dev_win=async()=>{//«
1429-
//Want to be able to pass in a command line flag to delete the local app/mod
1430-
//that we are editing in this file.
14311533
if (!reload_win) {
1432-
stat_warn(`No "reload window" was found! (use Ctrl+Alt+r)`);
1534+
stat_warn(`No "reload window" was found! (use Ctrl+Alt+r)`);
14331535
return;
14341536
}
1435-
if (!reload_win._data_url){
1436-
cwarn("NO RELOAD_WIN._DATA_URL!!?");
1437-
}
1438-
else{
1439-
URL.revokeObjectURL(reload_win._data_url);
1537+
let devname = this.comOpts["dev-name"] || (edit_fobj && edit_fobj.baseName);
1538+
if (!devname){
1539+
stat_warn("No 'dev name' found!");
1540+
return;
14401541
}
1441-
stat("Reloading...");
1442-
let rv = await reload_win.reload({noShow: true, dataUrl: URL.createObjectURL(new Blob([`(function(){"use strict";${get_edit_str()}})()`]))});
1443-
stat("Done!");
1542+
if (reload_script) reload_script._del();
1543+
reload_script = document.createElement('script');
1544+
reload_script.onload=()=>{
1545+
let gotlib = LOTW.coms[`local.${devname}`];
1546+
if (!gotlib){
1547+
return stat_err(`LOTW.coms[local.${devname}]: not found!`);
1548+
}
1549+
let gotcoms = gotlib.coms;
1550+
let com_env = reload_win.app.env.coms;
1551+
let num = 0;
1552+
for (let comname in gotcoms){
1553+
let gotcom = gotcoms[comname];
1554+
com_env[`dev.${comname}`] = gotcom;
1555+
num++;
1556+
}
1557+
stat_ok(`Loaded ${num} commands`);
1558+
};
1559+
reload_script.onerror=(e)=>{
1560+
cerr(e);
1561+
};
1562+
let str = `function(){"use strict";${get_edit_str()}}`;
1563+
reload_script.src = URL.createObjectURL(new Blob([`(${str})()`]));
1564+
document.head.appendChild(reload_script);
14441565
}//»
14451566
const ondevreload=()=>{//«
14461567
return reload_dev_win();
@@ -1950,8 +2071,9 @@ if (marr = com.match(/^(%)?s(b)?\/(.*)$/)){//«
19502071
}
19512072
else if (marr = com.match(/^x +(.*)$/)){
19522073
cur_background_command = marr[1];
1953-
Term.execute_background_command(cur_background_command);
1954-
render();
2074+
// Term.executeBackgroundCommand(cur_background_command);
2075+
// render();
2076+
stat_ok("Saved to cur_background_command");
19552077
return;
19562078
}
19572079
else if (marr = com.match(/^tab +(.*)$/)){
@@ -6434,11 +6556,7 @@ u_CA: ()=>{do_changecase(true);},
64346556
//Non-editing (No Action needed below)
64356557

64366558
//KSJTUSHF
6437-
x_CA:()=>{
6438-
if (!cur_background_command) cur_background_command = DEF_BACKGROUND_COMMAND;
6439-
// if (!cur_background_command) return stat_err("No command (please use :x)");
6440-
Term.execute_background_command(cur_background_command);
6441-
},
6559+
x_CA: send_command_to_reload_win,
64426560
/*
64436561
w_CAS:()=>{//«
64446562
//get_all_words();
@@ -6862,6 +6980,10 @@ cwarn("Using ondevreload");
68626980
//hold_screen_state = Term.initNewScreen(vim, appclass, lines, line_colors, num_stat_lines, {onescape, ondevreload: use_reload});
68636981
hold_screen_state = Term.initNewScreen(vim, appclass, lines, line_colors, num_stat_lines, {onescape, onreload: ()=>{
68646982
//cwarn("HI VIM RELOAD!!!");
6983+
if (reload_win && use_devreload){
6984+
ondevreload();
6985+
return;
6986+
}
68656987
quit(true);
68666988
}});
68676989
this.fname = edit_fname;
@@ -6905,11 +7027,15 @@ return;
69057027

69067028
};//»
69077029
this.quit = quit;
7030+
7031+
7032+
//»
7033+
69087034
//}; End vim mod«
69097035
}
69107036
//»
69117037

6912-
//»
7038+
//})();//Comment this whole line OUT!
69137039

69147040

69157041

0 commit comments

Comments
 (0)