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