summary refs log tree commit diff
path: root/screen/login.ts
blob: 57b269fba1df43d061fd149bd156f1f82435be35 (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
66
67
68
69
70
import { ElemType } from "../screenbuilder.ts";
import { Screen } from "../screen.ts";
import { build } from "../screenbuilder.ts";
import HomeScreen from "./home.ts";
import { Input } from "../elements.ts";
import process from "node:process"

function changeTitle(title: string) {
    if (process.platform == 'win32') {
        process.title = title;
    } else {
        process.stdout.write(`\x1b]2;${title}\x1b\x5c`);
    }
}

export default {
    elements: [
        {
            type: ElemType.TextElem,
            id: 'username-label',
            data: ["Username: \n"]
        },
        {
            type: ElemType.InputElem,
            id: 'username-input',
            data: [false]
        },
        {
            type: ElemType.BR,
            id: 'naoiuou'
        },
        {
            type: ElemType.TextElem,
            id: 'password-label',
            data: ["Password: \n"]
        },
        {
            type: ElemType.InputElem,
            id: 'password-input',
            data: [true]
        },
        {
            type: ElemType.BR,
            id: 'faij0ifsj'
        },
        {
            type: ElemType.ButtonElem,
            id: 'done-btn',
            data: ["Done", async function (this: Screen) {
                this.client.setScreen(this)
                this.off()
                this.logs.push(`clicked button`)
                console.clear()
                changeTitle('maelink - logging in...')
                this.logs.push("logging in...")
                const usernameInput = this.elements.get("username-input") as Input;
                const passwordInput = this.elements.get("password-input") as Input;
                await this.client.login(usernameInput.value, passwordInput.value)
                changeTitle('maelink - logged in as ' + usernameInput.value)
                build(HomeScreen, this.client);
                this.client
            }]
        }
    ],
    focus: "username-input",
    name: 'login',
    onload() {
        changeTitle(`maelink - log in`)
    }
}