Finished working on playground and added a CI/CD step

This commit is contained in:
Leon Mika 2024-04-26 10:31:41 +10:00
parent 35f45caaaf
commit c7a4013641
8 changed files with 91 additions and 23 deletions

26
.github/workflows/build.yaml vendored Normal file
View File

@ -0,0 +1,26 @@
name: Build
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21.6
- name: Build
run: |
make test
- name: Site
run: |
make site-deploy
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}

3
.gitignore vendored
View File

@ -1 +1,4 @@
.idea
build
# Local Netlify folder
.netlify

14
Makefile Normal file
View File

@ -0,0 +1,14 @@
clean:
-rm -r build
test:
go test ./cmdlang/...
site: clean
mkdir build
mkdir build/site
cp -r _site/* build/site/.
GOOS=js GOARCH=wasm go build -o build/site/playwasm.wasm ./cmd/playwasm/.
site-deploy: site
netlify deploy --dir build/site --prod

33
_site/index.html Normal file
View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<link rel="stylesheet" href="https://unpkg.com/@xterm/xterm/css/xterm.css">
<link rel="stylesheet" href="/style.css">
</head>
<body>
<header>
<h1>UCL</h1>
</header>
<main>
<h3>Playground</h3>
<div class="terminal" id="terminal"></div>
<script type="importmap">
{
"imports": {
"xterm": "https://unpkg.com/@xterm/xterm/lib/xterm.js",
"wasm_exec": "./wasm_exec.js"
}
}
</script>
<script src="/main.js" type="module"></script>
</main>
<footer>
<p>By Leon Mika. Terminal control using <a href="https://xtermjs.org">xterm.js</a></p>
</footer>
</body>
</html>

View File

@ -2,14 +2,15 @@ import "xterm";
import "wasm_exec";
var term = new Terminal();
var term = new Terminal({
lineHeight: 1.2,
});
term.open(document.getElementById('terminal'));
function startSession(term) {
let buffer = "";
let lineBuffer = "";
term.writeln('Interactive mode');
term.write('> ');
term.onKey((ev, dom) => {
@ -53,6 +54,7 @@ function startSession(term) {
}
ucl.onOutLine = (line) => { term.writeln(line); }
ucl.onError = (err) => { term.writeln('error: ' + err); }
term.focus();
}
const go = new Go();

View File

@ -1,21 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/@xterm/xterm/css/xterm.css">
</head>
<body>
<h1>Playground</h1>
<div class="terminal" id="terminal"></div>
<script type="importmap">
{
"imports": {
"xterm": "https://unpkg.com/@xterm/xterm/lib/xterm.js",
"wasm_exec": "./wasm_exec.js"
}
}
</script>
<script src="/main.js" type="module"></script>
</body>
</html>

5
_site/style.css Normal file
View File

@ -0,0 +1,5 @@
#terminal {
border: solid 4px black;
border-radius: 5px;
scrollbar-color: white black;
}

View File

@ -276,6 +276,12 @@ func (ia invocationArgs) invokableArg(i int) (invokable, error) {
switch v := ia.args[i].(type) {
case invokable:
return v, nil
case strObject:
iv := ia.ec.lookupInvokable(string(v))
if iv == nil {
return nil, errors.New("'" + string(v) + "' is not invokable")
}
return iv, nil
}
return nil, errors.New("expected an invokable arg")
}