|
13 | 13 | {flex:1} |
14 | 14 |
|
15 | 15 |
|
| 16 | + .con-btn |
| 17 | + {display:flex;align-items:center;gap:10px;border:1px solid lightgray;padding:0 10px;cursor:pointer} |
| 18 | + |
| 19 | + |
16 | 20 | input |
17 | 21 | {font-size:16px;padding:5px 10px;box-sizing:border-box} |
| 22 | + input[type=button] |
| 23 | + {cursor:pointer} |
| 24 | + input[type=checkbox] |
| 25 | + {width:20px;height:20px;margin:0} |
18 | 26 |
|
19 | 27 | </style> |
20 | 28 |
|
|
27 | 35 | </web-editor> |
28 | 36 |
|
29 | 37 | <div id=btns> |
30 | | - <input value=test type=button> |
| 38 | + <input value=run type=button> |
| 39 | + <input value=kill type=button> |
| 40 | + <div id=persist class=con-btn> |
| 41 | + persist |
| 42 | + <input type=checkbox> |
| 43 | + </div> |
| 44 | + <div id=echo class=con-btn> |
| 45 | + echo |
| 46 | + <input type=checkbox checked> |
| 47 | + </div> |
| 48 | + <input value=clear type=button> |
| 49 | + |
31 | 50 | </div> |
32 | 51 |
|
33 | 52 | <web-console component> |
|
47 | 66 |
|
48 | 67 | var df=true,did='webcontainer-terminal'; |
49 | 68 |
|
50 | | - var $,vm |
| 69 | + var $,vm,ace,wc |
51 | 70 | ; |
52 | 71 |
|
53 | 72 | obj.initmod = function(params){ |
54 | 73 |
|
55 | 74 | $ = mod.rd(params,'$',$); |
56 | 75 | vm = mod.rd(params,'vm',vm); |
| 76 | + ace = mod.rd(params,'ace',ace); |
| 77 | + wc = mod.rd(params,'webcontainer',wc); |
57 | 78 | debug = mod.rd(params,'debug',debug); |
58 | 79 |
|
59 | 80 | }//initmod |
|
63 | 84 |
|
64 | 85 |
|
65 | 86 | var viewport; |
| 87 | + var editor; |
| 88 | + var cons; |
| 89 | + |
| 90 | + var tmpfile = '~/tmp.js'; |
| 91 | + |
| 92 | + var btn = {}; |
66 | 93 |
|
67 | 94 |
|
68 | 95 | //: |
|
73 | 100 |
|
74 | 101 | await mod.auto(); |
75 | 102 |
|
| 103 | + editor = mod['web-editor']; |
| 104 | + cons = mod['web-console']; |
| 105 | + cons.log('ready'); |
| 106 | + |
76 | 107 | await initdom(); |
77 | 108 |
|
78 | 109 |
|
|
91 | 122 |
|
92 | 123 | shadow = host.shadowRoot; |
93 | 124 |
|
94 | | - $(shadow,'[value=test]').onclick = e=>alert('test'); |
| 125 | + $(shadow,'[value=run]').onclick = btn.run; |
95 | 126 |
|
96 | 127 |
|
97 | 128 | }//initdom |
|
100 | 131 | //: |
101 | 132 |
|
102 | 133 |
|
| 134 | + btn.run = async function(){ |
| 135 | + |
| 136 | + var js = editor.get(); |
| 137 | + await wc.fs.writeFile(tmpfile,js); |
| 138 | + |
| 139 | + var cmdline = `node ${tmpfile}`; |
| 140 | + var args = cmdline.split(' '); |
| 141 | + var cmd = args.shift(); |
| 142 | + process = await webcontainer.spawn(cmd,args);//,{cwd,output:true}); |
| 143 | + |
| 144 | + var stream = new WritableStream({write(data){ |
| 145 | + |
| 146 | + console.log(data); |
| 147 | + cons.log(data); |
| 148 | + |
| 149 | + }}); |
| 150 | + process.output.pipeTo(stream) |
| 151 | + |
| 152 | + var code = await process.exit; |
| 153 | + |
| 154 | + console.log('process exited :',code); |
| 155 | + cons.log('process exited :',code); |
| 156 | + |
| 157 | + }//run |
| 158 | + |
| 159 | + |
| 160 | + btn.kill = function(){ |
| 161 | + |
| 162 | + if(!process){ |
| 163 | + cons.log('no process'); |
| 164 | + return; |
| 165 | + } |
| 166 | + |
| 167 | + await process.kill(); |
| 168 | + |
| 169 | + }//kill |
| 170 | + |
| 171 | + |
| 172 | + //: |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
103 | 177 | return obj; |
104 | 178 |
|
105 | 179 | }) |
|
0 commit comments