From a208528dff3109c4d04ed48bcddcf9ff67b2649b Mon Sep 17 00:00:00 2001
From: Alcor <alcor@tilde.club>
Date: Mon, 18 May 2026 20:14:20 +0200
Subject: [PATCH 18/19] add overflow indicator $

---
 chat.h  |  1 +
 input.c | 24 +++++++++++++++++++-----
 ui.c    | 16 ++++++++++++++--
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/chat.h b/chat.h
index 83cc138..beca89d 100644
--- a/chat.h
+++ b/chat.h
@@ -355,6 +355,7 @@ void inputWait(void);
 void inputUpdate(void);
 bool inputPending(uint id);
 void inputRead(void);
+bool inputOverflow(uint id);
 void inputCompletion(FILE *file);
 int inputSave(FILE *file);
 void inputLoad(FILE *file, size_t version);
diff --git a/input.c b/input.c
index 483af07..2c8017d 100644
--- a/input.c
+++ b/input.c
@@ -243,6 +243,11 @@ static char *inputStop(
 
 static size_t cap;
 static char *buf;
+static bool overflows[IDCap];
+
+bool inputOverflow(uint id) {
+	return overflows[id];
+}
 
 void inputUpdate(void) {
 	uint id = windowID();
@@ -289,16 +294,25 @@ void inputUpdate(void) {
 		skip = buf;
 	}
 
-	int y, x;
+	assert(skip >= buf);
+	assert(edits[id].len >= (size_t)(skip - buf));
+	size_t len = strlen(prefix) + strlen(prompt) + strlen(suffix);
+	len += edits[id].len;
+	len -= skip - buf;
+	int shift = 0;
+	if (windowTimeEnable() && id != Network) shift += windowTime.width;
+	len += shift;
+	overflows[id] = len + 1 >= InputCols;
+
 	wmove(uiInput, 0, 0);
-	if (windowTimeEnable() && id != Network) {
-		whline(uiInput, ' ', windowTime.width);
-		wmove(uiInput, 0, windowTime.width);
-	}
+	if (shift) whline(uiInput, ' ', shift);
+	wmove(uiInput, 0, shift);
 	wattr_set(uiInput, uiAttr(stylePrompt), uiPair(stylePrompt), NULL);
 	waddstr(uiInput, prefix);
 	waddstr(uiInput, prompt);
 	waddstr(uiInput, suffix);
+
+	int y, x;
 	getyx(uiInput, y, x);
 
 	int posx;
diff --git a/ui.c b/ui.c
index 4de65c3..0dc1139 100644
--- a/ui.c
+++ b/ui.c
@@ -56,6 +56,7 @@
 WINDOW *uiStatus;
 WINDOW *uiMain;
 WINDOW *uiInput;
+static WINDOW *uiBar;
 
 static short colorPairs;
 
@@ -129,6 +130,9 @@ void uiInit(void) {
 	uiInput = newpad(InputLines, InputCols);
 	if (!uiInput) err(1, "newpad");
 
+	uiBar = newwin(InputLines, 0 /* FILL */, LINES < InputLines ? 0 : LINES - InputLines, 0);
+	if (!uiBar) err(1, "newwin");
+
 	windowInit();
 	uiShow();
 }
@@ -142,13 +146,19 @@ void uiDraw(void) {
 	if (hidden) return;
 	wnoutrefresh(uiStatus);
 	wnoutrefresh(uiMain);
+
+	werase(uiBar);
+	bool overflow = inputOverflow(windowID());
+	if (overflow) mvwaddch(uiBar, InputLines - 1, RIGHT, '$');
+	wnoutrefresh(uiBar);
+
 	int y, x;
 	getyx(uiInput, y, x);
 	pnoutrefresh(
 		uiInput,
-		0, (x + 1 > RIGHT ? x + 1 - RIGHT : 0),
+		0, (x + !overflow > RIGHT ? x + !overflow - RIGHT : 0),
 		LINES - InputLines, 0,
-		BOTTOM, RIGHT
+		BOTTOM, RIGHT - overflow
 	);
 	(void)y;
 	doupdate();
@@ -274,6 +284,8 @@ void uiFormat(
 void uiResize(void) {
 	wclear(uiMain);
 	wresize(uiMain, MAIN_LINES <= 0 ? 1 : MAIN_LINES, COLS <= 0 ? 1 : COLS);
+	wresize(uiBar, InputLines, COLS <= 0 ? 1 : COLS);
+	mvwin(uiBar, LINES < InputLines ? 0 : LINES - InputLines, 0);
 	windowResize();
 }
 
-- 
2.47.3

