diff options
author | wlodekm <[email protected]> | 2024-11-15 09:46:47 +0200 |
---|---|---|
committer | wlodekm <[email protected]> | 2024-11-15 09:46:47 +0200 |
commit | d28d8333ebe71e2937660b13d9afb1d516cf14f0 (patch) | |
tree | 6c941712ec80b785a940b37aec52b2cea7861835 /screen | |
parent | d51dbb974d83125f4bfb017188de6a013b7f746c (diff) |
v1.0.2
Diffstat (limited to 'screen')
-rw-r--r-- | screen/home.ts | 53 | ||||
-rw-r--r-- | screen/login.ts | 55 |
2 files changed, 108 insertions, 0 deletions
diff --git a/screen/home.ts b/screen/home.ts new file mode 100644 index 0000000..0be3ef9 --- /dev/null +++ b/screen/home.ts @@ -0,0 +1,53 @@ +import { ElemType } from "../screenbuilder.ts"; +import { Screen } from "../screen.ts"; +import type { Input, Element, Text } from "../elements.ts"; +import * as client from "../client.ts" + +export default { + elements: [ + { + type: ElemType.TextElem, + id: 'home', + data: ["Loading home posts...\n", function (this: Text, text: string) { + const msgInput: Input = this.screen.elements.get("msg-input") as Input; + const inputValueHeight = msgInput.value.split("\n").length + 1; + const termHeight = process.stdout.rows; + const termWidth = process.stdout.columns; + + let splitText = this.text.split("\n"); + splitText = splitText.map(t => t.replace(new RegExp(`([^]){${termWidth}}`, "g"),"$1\n")); + splitText = splitText.join("\n").split("\n") + + splitText = splitText.slice(-(termHeight - inputValueHeight)); + + return splitText.join("\n") + }] + }, + { + type: ElemType.HR, + id: 'hr', + data: [] + }, + { + type: ElemType.InputElem, + id: 'msg-input', + data: [false, false, true] + }, + { + type: ElemType.ButtonElem, + id: 'done-btn', + data: ["Send", async function (this: Screen) { + const msgInput: Input = this.elements.get('msg-input') as Input + client.sendHome(msgInput.value); + msgInput.value = "" + this.render() + }] + } + ], + focus: "msg-input", + name: 'home', + onload (screen: Screen) { + client.setScreen(screen) + client.loadHome(screen) + } +} \ No newline at end of file diff --git a/screen/login.ts b/screen/login.ts new file mode 100644 index 0000000..bc39655 --- /dev/null +++ b/screen/login.ts @@ -0,0 +1,55 @@ +import { ElemType } from "../screenbuilder.ts"; +import { Screen } from "../screen.ts"; +import * as client from "../client.ts" +import { build } from "../screenbuilder.ts"; +import HomeScreen from "./home.ts"; + +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) { + client.setScreen(this) + this.off() + this.logs.push(`clicked button`) + console.clear() + console.log("logging in...") + //@ts-ignore + await client.login(this.elements.get("username-input").value, this.elements.get("password-input").value) + build(HomeScreen); + client + }] + } + ], + focus: "username-input", + name: 'login' +} \ No newline at end of file |