|
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 | +
|
2 | 9 | */ |
| 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 | +»*/ |
3 | 56 | /*8/6/25:« |
4 | 57 |
|
5 | 58 | 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 |
158 | 211 | namespaces of globals.refs onto cur_refs (which potentially overwrites |
159 | 212 | references with the same name that are "exported" by other apps/mods/coms/etc). |
160 | 213 | »*/ |
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« |
162 | 215 | an application while editing your file, which should at least have this: |
163 | 216 |
|
164 | 217 | LOTW.apps["local.<AppNameHere>"] = function(Win){ |
@@ -195,7 +248,7 @@ to check for syntax errors (via test_js), using window.onerror. |
195 | 248 |
|
196 | 249 | »*/ |
197 | 250 | //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!"'; |
199 | 252 | //» |
200 | 253 | /*12/17/24: Yesterday I created the 'goto_matching_brace' functionality« |
201 | 254 | 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). |
283 | 336 |
|
284 | 337 | »*/ |
285 | 338 | //» |
| 339 | + |
286 | 340 | //Imports« |
287 | 341 |
|
288 | 342 | //import { util, api as capi } from "util"; |
@@ -333,13 +387,13 @@ const NUM=(v)=>Number.isFinite(v); |
333 | 387 |
|
334 | 388 | //» |
335 | 389 |
|
336 | | -//Vim« |
337 | | - |
338 | | -//export const mod = function(Term) {« |
| 390 | +//FSWOUXNM (reverse these) |
| 391 | +//LOTW.mods[MODNAME] = function(Term) { |
339 | 392 | export const mod = function(Term) { |
| 393 | + |
340 | 394 | //LOTW.mods["local.dev.vim"] = function(Term) { |
341 | 395 |
|
342 | | -//» |
| 396 | +//Vim« |
343 | 397 |
|
344 | 398 | //Imports« |
345 | 399 | this.comName="vim"; |
@@ -407,7 +461,7 @@ let splice_hold; |
407 | 461 | let is_root = false; |
408 | 462 |
|
409 | 463 | let app_cb; |
410 | | - |
| 464 | +let reload_script; |
411 | 465 | let reload_win; |
412 | 466 | let hold_overrides; |
413 | 467 |
|
@@ -1386,7 +1440,9 @@ const test_js=()=>{//« |
1386 | 1440 | let str = `()=>{\n${get_edit_str()}\n}`;; |
1387 | 1441 | scr.src = URL.createObjectURL(new Blob([str])); |
1388 | 1442 | };//» |
| 1443 | +/* |
1389 | 1444 | const toggle_reload_win=async()=>{//« |
| 1445 | +//SDHRYWOEL1 |
1390 | 1446 | if (!use_devreload){ |
1391 | 1447 | stat_warn("ondevreload was not enabled!"); |
1392 | 1448 | return; |
@@ -1425,22 +1481,87 @@ cerr("The reload_win was not in topwin.childWins!?!?!"); |
1425 | 1481 | reload_win.ownedBy = topwin; |
1426 | 1482 | topwin.childWins.push(reload_win); |
1427 | 1483 | };//» |
| 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 | +};//» |
1428 | 1532 | 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. |
1431 | 1533 | 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)`); |
1433 | 1535 | return; |
1434 | 1536 | } |
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; |
1440 | 1541 | } |
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); |
1444 | 1565 | }//» |
1445 | 1566 | const ondevreload=()=>{//« |
1446 | 1567 | return reload_dev_win(); |
@@ -1950,8 +2071,9 @@ if (marr = com.match(/^(%)?s(b)?\/(.*)$/)){//« |
1950 | 2071 | } |
1951 | 2072 | else if (marr = com.match(/^x +(.*)$/)){ |
1952 | 2073 | 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"); |
1955 | 2077 | return; |
1956 | 2078 | } |
1957 | 2079 | else if (marr = com.match(/^tab +(.*)$/)){ |
@@ -6434,11 +6556,7 @@ u_CA: ()=>{do_changecase(true);}, |
6434 | 6556 | //Non-editing (No Action needed below) |
6435 | 6557 |
|
6436 | 6558 | //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, |
6442 | 6560 | /* |
6443 | 6561 | w_CAS:()=>{//« |
6444 | 6562 | //get_all_words(); |
@@ -6862,6 +6980,10 @@ cwarn("Using ondevreload"); |
6862 | 6980 | //hold_screen_state = Term.initNewScreen(vim, appclass, lines, line_colors, num_stat_lines, {onescape, ondevreload: use_reload}); |
6863 | 6981 | hold_screen_state = Term.initNewScreen(vim, appclass, lines, line_colors, num_stat_lines, {onescape, onreload: ()=>{ |
6864 | 6982 | //cwarn("HI VIM RELOAD!!!"); |
| 6983 | +if (reload_win && use_devreload){ |
| 6984 | +ondevreload(); |
| 6985 | +return; |
| 6986 | +} |
6865 | 6987 | quit(true); |
6866 | 6988 | }}); |
6867 | 6989 | this.fname = edit_fname; |
@@ -6905,11 +7027,15 @@ return; |
6905 | 7027 |
|
6906 | 7028 | };//» |
6907 | 7029 | this.quit = quit; |
| 7030 | + |
| 7031 | + |
| 7032 | +//» |
| 7033 | + |
6908 | 7034 | //}; End vim mod« |
6909 | 7035 | } |
6910 | 7036 | //» |
6911 | 7037 |
|
6912 | | -//» |
| 7038 | +//})();//Comment this whole line OUT! |
6913 | 7039 |
|
6914 | 7040 |
|
6915 | 7041 |
|
|
0 commit comments