Added golines playground
All checks were successful
/ publish (push) Successful in 2m43s

This commit is contained in:
Leon Mika 2026-09-06 09:23:55 +10:00
parent 09fceca2f9
commit 40e5379eb3
11 changed files with 250 additions and 2 deletions

41
site/golines/index.html Normal file
View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>Golines Playground - Tools</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body class="container">
<header><hgroup>
<h1>Golines Playground</h1>
<p>Format Go code with <a href="https://github.com/golangci/golines">golines</a>. Everything runs in your browser.</p>
</hgroup></header>
<main>
<label for="max-len">Maximum line width: <output id="width-value" for="max-len">100</output></label>
<input id="max-len" type="range" min="40" max="180" step="5" value="100" disabled aria-describedby="config">
<p id="config"><small>Tab width: <span id="tab-value">4</span>. Comment shortening, struct tag formatting, and splitting method chains at dots are enabled.</small></p>
<div class="grid">
<div>
<label for="source">Go source</label>
<textarea id="source" spellcheck="false" autocapitalize="off" autocomplete="off" disabled aria-describedby="message">package main
import "fmt"
func main() {
fmt.Println("Hello from golines!", "Move the slider to explore how longer function calls are formatted.")
}
</textarea>
</div>
<div>
<label for="output">Formatted output</label>
<textarea id="output" readonly spellcheck="false" aria-label="Formatted output"></textarea>
</div>
</div>
<p id="message" role="status" aria-live="polite">Loading formatter…</p>
</main>
<script src="main.js" type="module"></script>
</body>
</html>

12
site/golines/main.js Normal file
View file

@ -0,0 +1,12 @@
try {
await import("/wasm/wasm_exec.js");
const go = new Go();
const response = await fetch("/wasm/golines.wasm");
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = await WebAssembly.instantiate(await response.arrayBuffer(), go.importObject);
await go.run(result.instance);
} catch (error) {
document.getElementById("message").textContent = `Unable to load the formatter: ${error.message}. Please reload to try again.`;
document.getElementById("source").disabled = true;
document.getElementById("max-len").disabled = true;
}

13
site/golines/style.css Normal file
View file

@ -0,0 +1,13 @@
textarea {
height: 28rem;
font-family: monospace;
font-size: 0.8rem;
white-space: pre;
overflow-wrap: normal;
tab-size: 4;
}
#message {
white-space: pre-wrap;
overflow-wrap: anywhere;
}

View file

@ -20,6 +20,7 @@
<ul>
<li><a href="/clocks/">Clocks</a></li>
<li><a href="/freelens-logo/">Freelens Logo Maker</a></li>
<li><a href="/golines/">Golines Playground</a></li>
<li><a href="/gotemplate/">Go Template Playground</a></li>
<li><a href="/gradient-bands/">Gradient Bands</a></li>
<li><a href="/2lcc/">Two-letter Country Codes</a></li>