summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2021-08-10 23:53:54 +0200
committernea <romangraef@gmail.com>2021-08-10 23:53:54 +0200
commit87f1eb3dc6c03a1369a71523a526c861efc25b80 (patch)
treed5ca03666dee38a124565e39533a921f91c409f0 /src/main
downloadwebos-87f1eb3dc6c03a1369a71523a526c861efc25b80.tar.gz
webos-87f1eb3dc6c03a1369a71523a526c861efc25b80.tar.bz2
webos-87f1eb3dc6c03a1369a71523a526c861efc25b80.zip
Initial commit
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/WebOS.kt64
-rw-r--r--src/main/resources/index.html17
2 files changed, 81 insertions, 0 deletions
diff --git a/src/main/kotlin/WebOS.kt b/src/main/kotlin/WebOS.kt
new file mode 100644
index 0000000..2ff0b62
--- /dev/null
+++ b/src/main/kotlin/WebOS.kt
@@ -0,0 +1,64 @@
+import kotlinx.browser.document
+import kotlinx.browser.window
+import org.w3c.dom.Element
+import org.w3c.dom.asList
+
+fun main() {
+ console.log("Hello from Kotlin")
+ val webos = WebOS()
+ document.body?.addEventListener("load", {
+ document.body?.querySelectorAll(".webosconsole")?.asList()?.forEach {
+ if (it !is Element) return@forEach
+ webos.registerConsole(it)
+ }
+ })
+}
+
+data class CharacterRun(val text: String, val color: String)
+
+
+abstract class Activity(val console: Console) {
+ abstract fun render(columns: Int, rows: Int): List<List<CharacterRun>>
+}
+
+class Console(val os: WebOS, val renderElement: Element?) {
+ val isVirtual get() = renderElement == null
+ val activityStack = ArrayDeque<Activity>()
+
+ var columns: Int = 80
+ var rows: Int = 46
+
+ var shouldRerender = true
+
+ fun openActivity(activity: Activity) {
+ activityStack.addLast(activity)
+ invalidateRender()
+ }
+
+ fun render() {
+ if (renderElement == null) return
+ if (!shouldRerender) return
+ shouldRerender = false
+ activityStack.last()
+ }
+
+ fun invalidateRender() {
+ shouldRerender = true
+ window.requestAnimationFrame { render() }
+ }
+
+ fun resize(newColumns: Int, newRows: Int) {
+ invalidateRender()
+ }
+
+ // TODO: Handle resizes of the renderElement
+
+}
+
+class WebOS {
+ private val _consoles = mutableListOf<Console>()
+ val consoles get() = _consoles.toList()
+ fun registerConsole(element: Element) {
+ _consoles.add(Console(this, element))
+ }
+}
diff --git a/src/main/resources/index.html b/src/main/resources/index.html
new file mode 100644
index 0000000..719506b
--- /dev/null
+++ b/src/main/resources/index.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport"
+ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
+ <title>WebOs</title>
+</head>
+<body>
+<noscript>tf you don't have js enabled? do you still live in the stone ages or what?</noscript>
+<div id="content">
+
+</div>
+<script src="/webos.js"></script>
+</body>
+</html>