summary refs log tree commit diff
path: root/v2
diff options
context:
space:
mode:
Diffstat (limited to 'v2')
-rw-r--r--v2/client.ts4
-rw-r--r--v2/elements.ts17
-rw-r--r--v2/screen.ts1
-rw-r--r--v2/screen/home.ts17
4 files changed, 26 insertions, 13 deletions
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,