|
849 | 849 | term.pause = false; |
850 | 850 |
|
851 | 851 | }//resume |
852 | | - |
853 | | - |
| 852 | + term.write.xy = (x,y,txt)=>{ |
| 853 | + |
| 854 | + term.write('\x1b[s'); // Save current spot |
| 855 | + term.write(`\x1b[${y};${x}H`); // Jump to top left |
| 856 | + term.write(txt); |
| 857 | + term.write('\x1b[u'); // Jump back to where we were |
| 858 | + |
| 859 | + }//xy |
| 860 | + |
| 861 | + |
| 862 | + |
| 863 | + |
854 | 864 | for(let key in colors){ |
855 | 865 |
|
856 | 866 | if (key === 'reset') continue; |
|
890 | 900 | term.loadAddon(fitAddon); |
891 | 901 | term.open(terminal); |
892 | 902 | fitAddon.fit(); |
| 903 | + |
893 | 904 | term.write('booting container ... ') |
894 | 905 | webcontainer = await WebContainer.boot(); |
895 | | - term.writeln.green('ok'); |
| 906 | + term.writeln.green('ok'); //24 |
896 | 907 |
|
897 | 908 | mod.stack.complete; |
898 | 909 |
|
899 | 910 |
|
| 911 | + var phase = {}; |
| 912 | + phase.ct = 1; |
| 913 | + phase.p1 = result=>{ |
| 914 | + |
| 915 | + var str = '??'; |
| 916 | + if(result.code==0)str = result.output; |
| 917 | + term.write.xy(30,1,'node '+str) |
| 918 | + phase.ct = 2 |
| 919 | + phase.p2() |
| 920 | + |
| 921 | + }//p1 |
| 922 | + phase.p2 = result=>{ |
| 923 | + |
| 924 | + if(result)phase.p2.result = result; |
| 925 | + if(phase.ct!=2)return; |
| 926 | + if(!phase.p2.result)return; |
| 927 | + var str = '??'; |
| 928 | + if(phase.p2.result.code==0)str = phase.p2.result.output; |
| 929 | + term.write.xy(50,1,'npm '+str); |
| 930 | + phase.ct = 3; |
| 931 | + phase.p3(); |
| 932 | + |
| 933 | + }//p2 |
| 934 | + phase.p3 = result=>{console.log('phase.p3',!!result); |
| 935 | + |
| 936 | + if(result)shell = result; |
| 937 | + if(phase.ct!=3)return; |
| 938 | + if(!shell)return; |
| 939 | + shell.output.pipeTo(output); |
| 940 | + input = shell.input.getWriter(); |
| 941 | + term.onData(data=>input.write(data)); |
| 942 | + //term.resize(); |
| 943 | + term.focus(); |
| 944 | + |
| 945 | + }//p3 |
| 946 | + |
| 947 | + |
| 948 | + spawn('node -v',true).then(phase.p1); |
| 949 | + spawn('npm -v',true).then(phase.p2); |
| 950 | + webcontainer.spawn('jsh').then(phase.p3); |
| 951 | + |
900 | 952 |
|
901 | | - var [result1,result2] = await Promise.all([spawn('node -v',{output:true}),spawn('npm -v',{output:true})]); |
902 | | - if(result1.code==0){ |
903 | | - term.write('node '+result1.output); |
904 | | - } |
905 | | - if(result2.code==0){ |
906 | | - term.write('npm '+result2.output); |
907 | | - } |
908 | 953 |
|
909 | | - webcontainer.on('server-ready',(port,url)=>{ |
910 | | - console.log('server-ready',url,port); |
911 | | - term.writeln('server-ready :'+url+' --- '+port); |
912 | | - |
913 | | - }); |
914 | | - webcontainer.on('port',(port,type,url)=>{ |
915 | | - console.log(port,type,url) |
916 | | - term.writeln('port :'+type+' --- '+url+' --- '+port); |
917 | | - |
918 | | - }); |
919 | 954 |
|
920 | 955 |
|
921 | 956 | if(0){ |
|
926 | 961 |
|
927 | 962 |
|
928 | 963 |
|
929 | | - term.write('spawn jsh ... ') |
930 | | - shell = await webcontainer.spawn('jsh'); |
931 | | - term.writeln.green('ok'); |
| 964 | + //term.write('spawn jsh ... ') |
| 965 | + //shell = await webcontainer.spawn('jsh'); |
| 966 | + //term.writeln.green('ok'); |
932 | 967 | output = new WritableStream({ |
933 | 968 | write(data){ |
934 | 969 | //console.log(data); |
|
981 | 1016 | }); |
982 | 1017 |
|
983 | 1018 |
|
984 | | - if(term.pause){ |
985 | | - term.buffer.push(data); |
| 1019 | + if(output.pause){ |
| 1020 | + output.buffer.push(data); |
986 | 1021 | }else{ |
987 | 1022 | term.write(data); |
988 | 1023 | } |
|
1008 | 1043 |
|
1009 | 1044 | }//resume |
1010 | 1045 |
|
1011 | | - shell.output.pipeTo(output); |
1012 | | - |
1013 | | - input = shell.input.getWriter(); |
1014 | | - term.onData(data=>input.write(data)); |
1015 | | - |
| 1046 | + |
1016 | 1047 | //term.resize(); |
1017 | 1048 | term.focus(); |
1018 | 1049 |
|
| 1050 | + |
| 1051 | + |
| 1052 | + |
| 1053 | + |
| 1054 | + |
| 1055 | + webcontainer.on('server-ready',(port,url)=>{ |
| 1056 | + console.log('server-ready',url,port); |
| 1057 | + term.writeln('server-ready :'+url+' --- '+port); |
| 1058 | + |
| 1059 | + }); |
| 1060 | + webcontainer.on('port',(port,type,url)=>{ |
| 1061 | + console.log(port,type,url) |
| 1062 | + term.writeln('port :'+type+' --- '+url+' --- '+port); |
| 1063 | + |
| 1064 | + }); |
| 1065 | + |
| 1066 | + |
1019 | 1067 | })(); |
1020 | 1068 |
|
1021 | 1069 |
|
1022 | 1070 | //: |
1023 | 1071 |
|
1024 | 1072 |
|
1025 | | - async function spawn(cmdline,{output}={}){ |
| 1073 | + async function spawn(cmdline,opts){ |
1026 | 1074 |
|
| 1075 | + if(opts===undefined){ |
| 1076 | + opts = {}; |
| 1077 | + } |
| 1078 | + var output; |
| 1079 | + if(typeof opts=='boolean'){ |
| 1080 | + output = opts; |
| 1081 | + }else{ |
| 1082 | + ({output} = opts); |
| 1083 | + } |
| 1084 | + |
| 1085 | + |
1027 | 1086 | var args = cmdline.split(' '); |
1028 | 1087 | var cmd = args.shift(); |
1029 | 1088 | var process = await webcontainer.spawn(cmd,args,{cwd,output:true}); |
|
0 commit comments