From a2cab186316b4c46839cb5f9ad51b693edb194f6 Mon Sep 17 00:00:00 2001 From: wlodekm Date: Sun, 10 Nov 2024 21:03:01 +0200 Subject: add build script, possibly fix a bug ( v1.0.1 ) --- buildall.sh | 22 ++++++++++++++++++++++ deno.json | 7 ++++++- v2/client.ts | 4 +++- v2/elements.ts | 17 +++++++---------- v2/screen.ts | 1 + v2/screen/home.ts | 17 +++++++++++++++-- 6 files changed, 54 insertions(+), 14 deletions(-) create mode 100755 buildall.sh diff --git a/buildall.sh b/buildall.sh new file mode 100755 index 0000000..a1afb5d --- /dev/null +++ b/buildall.sh @@ -0,0 +1,22 @@ +echo "Welcome to the meower CL build script" + +echo "Building windows..." +deno task build-win + +echo "Building mac..." +deno task build-mac-x86 +deno task build-mac-arm + +echo "Building linux..." +deno task build-linux-x86 +deno task build-linux-arm + +echo "All platforms built, starting compression" + +mkdir build/compressed + +zip build/compressed/win.zip build/win.exe +zip build/compressed/mac.zip build/mac-x86 build/mac-arm + +tar -kczf build/compressed/linux.tar.gz build/linux-x86 build/linux-arm +echo "All builds compressed, build finished" \ No newline at end of file diff --git a/deno.json b/deno.json index 330f2ce..85a748f 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,11 @@ { "tasks": { "dev": "deno run --allow-net --allow-env main.ts", - "build": "deno compile --allow-net --allow-env --no-check main.ts" + "build": "deno compile --allow-net --allow-env --no-check main.ts", + "build-win": "deno compile --allow-net --allow-env --no-check -o build/win.exe --target x86_64-pc-windows-msvc main.ts", + "build-mac-x86": "deno compile --allow-net --allow-env --no-check -o build/mac-x86 --target x86_64-apple-darwin main.ts", + "build-mac-arm": "deno compile --allow-net --allow-env --no-check -o build/mac-arm --target aarch64-apple-darwin main.ts", + "build-linux-x86": "deno compile --allow-net --allow-env --no-check -o build/linux-x86 --target x86_64-unknown-linux-gnu main.ts", + "build-linux-arm": "deno compile --allow-net --allow-env --no-check -o build/linux-arm --target aarch64-unknown-linux-gnu main.ts" } } \ No newline at end of file diff --git a/v2/client.ts b/v2/client.ts index 6eb9523..16358c8 100644 --- a/v2/client.ts +++ b/v2/client.ts @@ -34,7 +34,7 @@ export async function login(username: string, password: string) { const data = JSON.parse(ev.data.toString()); screen.logs.push("INC: " + JSON.stringify(data)) if(data.cmd != "post") return; - home.push(data.val) + home.push(data.val); const textHome: string[] = home.map(p => `[${strftime("%H:%M:%S")}] ${p.u}: ${p.p}`); const homeElem: Text = screen.elements.get("home") as Text; homeElem.text = textHome.join("\n")+"\n"; @@ -47,10 +47,12 @@ export async function loadHome(screen: Screen) { const textHome: string[] = home.map(p => `[${strftime("%H:%M:%S")}] ${p.u}: ${p.p}`); const homeElem: Text = screen.elements.get("home") as Text; homeElem.text = textHome.join("\n")+"\n"; + screen.logs.push("loadHome ran", home.length.toString()) screen.render() } export async function sendHome(post:string) { + screen.logs.push("sendHome ran", home.length.toString()) fetch("https://api.meower.org/home", { method: "POST", headers: { diff --git a/v2/elements.ts b/v2/elements.ts index 8c3d58a..c364930 100644 --- a/v2/elements.ts +++ b/v2/elements.ts @@ -15,12 +15,16 @@ export abstract class Element { export class Text extends Element { text: string; br: boolean; - constructor(text: string, br = false) { + + processText: (text: string) => string; + + constructor(text: string, processText = (t:string)=>t) { super(); this.text = text; + this.processText = processText } render() { - process.stdout.write(this.text) + process.stdout.write(this.processText(this.text)) } } @@ -46,10 +50,6 @@ export class Input extends Element { focusable: boolean = true; value: string = ""; - height: number = 1; - heightOffser: number = 1; - grow: number = 1; - textarea = false; br = false; @@ -96,14 +96,11 @@ export class Input extends Element { this.screen.render() } - constructor(isPassword: boolean = false, br: boolean = false, textarea: boolean = false, height: number = 1, heightOffset: boolean = false, grow: boolean = false) { + constructor(isPassword: boolean = false, br: boolean = false, textarea: boolean = false) { super() this.br = br this.isPassword = isPassword; this.textarea = textarea; - this.height = height; - this.heightOffset = heightOffset; - this.grow = grow; } } diff --git a/v2/screen.ts b/v2/screen.ts index 7a1e265..4c399e8 100644 --- a/v2/screen.ts +++ b/v2/screen.ts @@ -74,6 +74,7 @@ export class Screen { render() { console.clear() + process.stdout.write("\e[2J") // use an ansi escape code to clear the screen if console.clear doesn't clear fully this.elements.forEach(element => { element.render() }); diff --git a/v2/screen/home.ts b/v2/screen/home.ts index 4c8a7cc..4de3c5b 100644 --- a/v2/screen/home.ts +++ b/v2/screen/home.ts @@ -1,6 +1,6 @@ import { ElemType } from "../screenbuilder.ts"; import { Screen } from "../screen.ts"; -import type { Input } from "../elements.ts"; +import type { Input, Element, Text } from "../elements.ts"; import * as client from "../client.ts" export default { @@ -8,7 +8,20 @@ export default { { type: ElemType.TextElem, id: 'home', - data: ["Loading home posts...\n"] + 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 - 1)); + + return splitText.join("\n") + }] }, { type: ElemType.HR, -- cgit 1.4.1-2-gfad0