summaryrefslogtreecommitdiff
path: root/example/src/main/kotlin/moe/nea89/website/test/index.kt
blob: 846b0db9879ff3da9a439240695021e3c68ea42a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package moe.nea89.website.test

import kotlinext.js.require
import kotlinx.browser.document
import kotlinx.css.*
import kotlinx.html.dom.append
import kotlinx.html.js.div
import moe.nea89.website.*
import styled.injectGlobal

val defaultFileSystem = fileSystem {
    "etc" {
        "passwd" text "hunter2"
    }
    "home/nea" {
        "todo" text """
                | - git gud
                | - finish this website
                | - convince the general public that comic sans is a viable font
            """.trimMargin()
        "moisturized" image require("images/moisturized.jpg")
        "download" download require("images/me.jpeg")
    }
    "flag" text "CTF{12345abcdefghijklmonp3.1.4.1.5.9.2.8}"
}

fun main() {

    require("@fontsource/comic-mono/index.css")
    val root = document.body!!.append.div()
    val console = KConsole.createFor(root, fileSystem = defaultFileSystem)
    console.text.id = "myconsole"
    console.fileAccessor!!.cd("home/nea")
    injectGlobal {
        body {
            backgroundColor = Styles.bgColor.lighten(30)
        }
        ".${Styles.consoleClass}" {
            margin(LinearDimension.auto)
            width = 50.vw
            height = 50.vh
            marginTop = 25.vh
            boxSizing = BoxSizing.borderBox
            backgroundClip = BackgroundClip.contentBox
            overflowY = Overflow.scroll
        }

    }
    console.addLine("Starting up terminal.")
    console.PS1 = { "${this.fileAccessor?.currentDir?.joinToString("/", "/") ?: ""} >" }
    console.rerender()
    console.registerCommand(defaultCwdCommand("cwd", "pwd"))
    console.registerCommand(defaultCdCommand("cd"))
    console.registerCommand(defaultLsCommand("ls"))
    console.registerCommand(command("color") {
        console.addLine("This is a ", red("red"), " word: ", green("1.0"), " ", blue("BLUUEEE"))
    })
    console.registerCommand(defaultCatCommand("cat"))
    console.registerCommand(command("dick", "cock") {
        console.addMultilineText("Hehe")
    })
    console.registerCommand(command("boob", "booob") {
        console.addMultilineText(boobs)
    })
}