| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  | <!DOCTYPE html> <html lang="en"> | 
					
						
							|  |  |  |   <head> | 
					
						
							|  |  |  |     <meta charset="utf-8"> | 
					
						
							|  |  |  |     <title>FTXUI examples WebAssembly</title> | 
					
						
							|  |  |  |     <script src="https://cdn.jsdelivr.net/npm/xterm@4.11.0/lib/xterm.min.js"></script> | 
					
						
							|  |  |  |     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@4.11.0/css/xterm.css"></link> | 
					
						
							|  |  |  |   </head> | 
					
						
							|  |  |  |   <body> | 
					
						
							|  |  |  |     <script id="example_script"></script> | 
					
						
							|  |  |  |     <div class="page"> | 
					
						
							|  |  |  |       <h1>FTXUI WebAssembly Example </h1> | 
					
						
							|  |  |  |       <p> | 
					
						
							| 
									
										
										
										
											2021-03-22 00:26:52 +01:00
										 |  |  |         <a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a single | 
					
						
							| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  |         C++ library for terminal user interface. | 
					
						
							|  |  |  |       </p> | 
					
						
							|  |  |  |       <p> | 
					
						
							|  |  |  |         On this page, you can try all the examples contained in: <a | 
					
						
							|  |  |  |         href="https://github.com/ArthurSonzogni/FTXUI/tree/master/examples">./example/</a> | 
					
						
							|  |  |  |         Those are compiled using WebAssembly. | 
					
						
							|  |  |  |       </p> | 
					
						
							|  |  |  |       <select id="selectExample"></select> | 
					
						
							|  |  |  |       <div id="terminal"></div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   </body> | 
					
						
							|  |  |  |   <script> | 
					
						
							| 
									
										
										
										
											2021-07-31 22:02:48 +05:30
										 |  |  |     const example_list = "@EXAMPLES@".split(";"); | 
					
						
							| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const url_search_params = new URLSearchParams(window.location.search); | 
					
						
							| 
									
										
										
										
											2021-07-31 22:02:48 +05:30
										 |  |  |     const example = url_search_params.get("file") || "dom/color_gallery"; | 
					
						
							| 
									
										
										
										
											2021-04-25 16:58:16 +02:00
										 |  |  |     const select = document.getElementById("selectExample");  | 
					
						
							| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for(var i = 0; i < example_list.length; i++) { | 
					
						
							|  |  |  |         var opt = example_list[i]; | 
					
						
							|  |  |  |         var el = document.createElement("option"); | 
					
						
							|  |  |  |         el.textContent = opt; | 
					
						
							|  |  |  |         el.value = opt; | 
					
						
							|  |  |  |         select.appendChild(el); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-25 16:58:16 +02:00
										 |  |  |     select.selectedIndex = example_list.findIndex(path => path == example) || 0; | 
					
						
							| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  |     select.addEventListener("change", () => { | 
					
						
							| 
									
										
										
										
											2021-04-25 16:58:16 +02:00
										 |  |  |       location.href = (location.href).split('?')[0] + "?file=" + | 
					
						
							|  |  |  |             example_list[select.selectedIndex]; | 
					
						
							| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let stdin_buffer = []; | 
					
						
							|  |  |  |     let stdin = () => { | 
					
						
							|  |  |  |       return stdin_buffer.shift() || 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stdout_buffer = []; | 
					
						
							|  |  |  |     let stdout = code => { | 
					
						
							|  |  |  |       if (code == 0) { | 
					
						
							|  |  |  |         term.write(new Uint8Array(stdout_buffer)); | 
					
						
							|  |  |  |         stdout_buffer = []; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         stdout_buffer.push(code) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     let stderr = code => console.log(code); | 
					
						
							|  |  |  |     var term = new Terminal(); | 
					
						
							|  |  |  |     term.open(document.querySelector('#terminal')); | 
					
						
							|  |  |  |     term.resize(140,43); | 
					
						
							|  |  |  |     const onBinary = e => { | 
					
						
							|  |  |  |       for(c of e) | 
					
						
							|  |  |  |         stdin_buffer.push(c.charCodeAt(0)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     term.onBinary(onBinary); | 
					
						
							|  |  |  |     term.onData(onBinary) | 
					
						
							|  |  |  |     window.Module = { | 
					
						
							|  |  |  |       preRun: () => { FS.init(stdin, stdout, stderr); }, | 
					
						
							|  |  |  |       postRun: [], | 
					
						
							|  |  |  |       onRuntimeInitialized: () => {}, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-07-31 22:02:48 +05:30
										 |  |  |     document.querySelector("#example_script").src = example + '.js'; | 
					
						
							| 
									
										
										
										
											2021-03-21 22:54:39 +01:00
										 |  |  |   </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <style> | 
					
						
							|  |  |  |     body { | 
					
						
							|  |  |  |       background-color:#EEE; | 
					
						
							|  |  |  |       padding:20px; | 
					
						
							|  |  |  |       font-family: Helvetica, sans-serif; | 
					
						
							|  |  |  |       font-size: 130%; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     .page { | 
					
						
							|  |  |  |       max-width:1300px; | 
					
						
							|  |  |  |       margin: auto; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     h1 { | 
					
						
							|  |  |  |       text-decoration: underline; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     select { | 
					
						
							|  |  |  |       display:block; | 
					
						
							|  |  |  |       padding: .6em 1.4em .5em .8em; | 
					
						
							|  |  |  |       border-radius: 20px 20px 0px 0px; | 
					
						
							|  |  |  |       font-size: 16px; | 
					
						
							|  |  |  |       font-family: sans-serif; | 
					
						
							|  |  |  |       font-weight: 700; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       color: #444; | 
					
						
							|  |  |  |       line-height: 1.3; | 
					
						
							|  |  |  |       background-color:black; | 
					
						
							|  |  |  |       border:0px; | 
					
						
							|  |  |  |       color:white; | 
					
						
							|  |  |  |       transition: color 0.2s linear; | 
					
						
							|  |  |  |       transition: background-color 0.2s linear; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #terminal { | 
					
						
							|  |  |  |       padding:10px; | 
					
						
							|  |  |  |       border:none; | 
					
						
							|  |  |  |       background-color:black; | 
					
						
							|  |  |  |       padding:auto; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   </style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </html> |