diff --git a/functions/vendors/templates.js b/functions/vendors/templates.js index 2bbc7ed68..ca34eaa3a 100644 --- a/functions/vendors/templates.js +++ b/functions/vendors/templates.js @@ -693,7 +693,7 @@ int main() { return 0; } -`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var j={name:"cpp-wasm",aliases:["clang"],title:"C++ (Wasm) Starter",thumbnail:"assets/templates/cpp.svg",activeEditor:"script",markup:{language:"html",content:` +`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var j={name:"cpp-wasm",aliases:["clang"],title:getTemplateName("templates.starter.cpp-wasm","C++ (Wasm) Starter"),thumbnail:"assets/templates/cpp.svg",activeEditor:"script",markup:{language:"html",content:`
Current count: 0
@@ -1224,37 +1224,32 @@ func greet() { const incrementBtn = document.querySelector("#increment-btn"); const greetBtn = document.querySelector("#greet-btn"); - // Enable buttons and update text incrementBtn.disabled = false; incrementBtn.textContent = "Increment"; greetBtn.disabled = false; greetBtn.textContent = "Greet"; - // Counter demo incrementBtn.onclick = async () => { - const currentCount = parseInt(document.querySelector("#counter").textContent); - - const {output, error} = await livecodes.goWasm.run(currentCount.toString()); + const currentCount = document.querySelector("#counter").textContent; + const {output, error} = await livecodes.goWasm.run(currentCount); if (error) { console.error('Error:', error); } else { - document.querySelector("#counter").textContent = output.trim(); + document.querySelector("#counter").textContent = output; } }; - // Greeting demo greetBtn.onclick = async () => { const name = document.querySelector("#name-input").value; - if (!name) { + if (!name.trim()) { alert('Please enter your name'); return; } - const {output, error} = await livecodes.goWasm.run(name); if (error) { console.error('Error:', error); } else { - document.querySelector("#greeting").textContent = output.trim(); + document.querySelector("#greeting").textContent = output; } }; @@ -1331,38 +1326,30 @@ input[type="text"], input[type="number"] { package main import ( - "bufio" - "fmt" - "os" - "strconv" - "strings" + "bufio" + "fmt" + "os" + "strconv" + "strings" ) func main() { - // Read input from stdin - scanner := bufio.NewScanner(os.Stdin) - - if scanner.Scan() { - input := strings.TrimSpace(scanner.Text()) - - // Try to parse as number (for counter demo) - if count, err := strconv.Atoi(input); err == nil { - // Counter demo - increment and return the new number - newCount := count + 1 - fmt.Println(newCount) - return - } - - - - // Greeting demo - treat as name - fmt.Printf("Hello, %s! Welcome to Go WebAssembly!\\n", input) - fmt.Println("This is running in your browser using Go compiled to WebAssembly.") - } else { - // No input provided - fmt.Println("Hello from Go WebAssembly!") - fmt.Println("This program demonstrates stdin handling in Go WASM.") - } + // Read input from stdin + scanner := bufio.NewScanner(os.Stdin) + + if scanner.Scan() { + input := strings.TrimSpace(scanner.Text()) + + if count, err := strconv.Atoi(input); err == nil { + newCount := count + 1 + fmt.Println(newCount) + return + } + + fmt.Printf("Hello, %s!\\n", input) + } else { + fmt.Println("Hello from Go WebAssembly!") + } } `.trimStart()}};var H={name:"imba",title:getTemplateName("templates.starter.imba","Imba Starter"),thumbnail:"assets/templates/imba.svg",activeEditor:"script",markup:{language:"html",content:""},style:{language:"css",content:""},script:{language:"imba",content:` tag app-counter @@ -1484,7 +1471,7 @@ button.addEventListener("click", () => { count++; counter.innerText = count; }); -`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var A={name:"jest-react",title:getTemplateName("templates.starter.jest-react","Jest/React Starter"),thumbnail:"assets/templates/jest.svg",activeEditor:"script",autotest:!0,markup:{language:"html",content:""},style:{language:"css",content:` +`.trimStart()},stylesheets:[],scripts:[],cssPreset:"",imports:{},types:{}};var O={name:"jest-react",title:getTemplateName("templates.starter.jest-react","Jest/React Starter"),thumbnail:"assets/templates/jest.svg",activeEditor:"script",autotest:!0,markup:{language:"html",content:""},style:{language:"css",content:` .container, .container button { text-align: center; @@ -1656,7 +1643,7 @@ describe("Page", () => { ); }); }); -`.trimStart()},tools:{enabled:"all",active:"tests",status:"open"}};var O={name:"jquery",title:getTemplateName("templates.starter.jquery","jQuery Starter"),thumbnail:"assets/templates/jquery.svg",activeEditor:"script",markup:{language:"html",content:` +`.trimStart()},tools:{enabled:"all",active:"tests",status:"open"}};var Y={name:"jquery",title:getTemplateName("templates.starter.jquery","jQuery Starter"),thumbnail:"assets/templates/jquery.svg",activeEditor:"script",markup:{language:"html",content:`