summary refs log tree commit diff
path: root/ui.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-09-05 17:10:26 -0400
committerJune McEnroe <june@causal.agency>2018-09-05 17:10:26 -0400
commit0cf067315de4960522df360f8e1b2b04a23db7f0 (patch)
tree1d656c3196660e62df297e7edbfe5073ce6147d4 /ui.c
parentUse PascalCase for constants (diff)
downloadcatgirl-0cf067315de4960522df360f8e1b2b04a23db7f0.tar.gz
catgirl-0cf067315de4960522df360f8e1b2b04a23db7f0.zip
Preserve scroll position when new lines appear
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/ui.c b/ui.c
index 8d13ea5..879fea3 100644
--- a/ui.c
+++ b/ui.c
@@ -131,7 +131,7 @@ static struct View *viewTag(struct Tag tag) {
 	view->log = newpad(LogLines, COLS);
 	wsetscrreg(view->log, 0, lastLogLine());
 	scrollok(view->log, true);
-	wmove(view->log, lastLogLine() - logHeight(view) + 2, 0);
+	wmove(view->log, lastLogLine(), 0);
 	view->scroll = LogLines;
 	view->mark = true;
 
@@ -266,7 +266,7 @@ static const wchar_t *parseColor(short *pair, const wchar_t *str) {
 	return str;
 }
 
-static void wordWrap(WINDOW *win, const wchar_t *str) {
+static int wordWrap(WINDOW *win, const wchar_t *str) {
 	size_t len = wcscspn(str, L" ");
 	size_t width = 1;
 	for (size_t i = 0; i < len; ++i) {
@@ -279,8 +279,10 @@ static void wordWrap(WINDOW *win, const wchar_t *str) {
 
 	if (width >= (size_t)(xMax - x)) {
 		waddch(win, '\n');
+		return 1;
 	} else {
 		waddch(win, ' ');
+		return 0;
 	}
 }
 
@@ -295,9 +297,10 @@ static const wchar_t IRCCodes[] = {
 	L'\0',
 };
 
-static void addIRC(WINDOW *win, const wchar_t *str) {
+static int addIRC(WINDOW *win, const wchar_t *str) {
 	attr_t attr = A_NORMAL;
 	short pair = -1;
+	int lines = 0;
 	for (;;) {
 		size_t cc = wcscspn(str, IRCCodes);
 		wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL);
@@ -306,7 +309,7 @@ static void addIRC(WINDOW *win, const wchar_t *str) {
 
 		str = &str[cc];
 		switch (*str++) {
-			break; case L' ':          wordWrap(win, str);
+			break; case L' ':         lines += wordWrap(win, str);
 			break; case IRCBold:      attr ^= A_BOLD;
 			break; case IRCItalic:    attr ^= A_ITALIC;
 			break; case IRCUnderline: attr ^= A_UNDERLINE;
@@ -315,6 +318,7 @@ static void addIRC(WINDOW *win, const wchar_t *str) {
 			break; case IRCReset:     attr = A_NORMAL; pair = -1;
 		}
 	}
+	return lines;
 }
 
 static void uiStatus(void) {
@@ -412,16 +416,21 @@ void uiTopic(struct Tag tag, const char *topic) {
 
 void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
 	struct View *view = viewTag(tag);
+	int lines = 1;
 	waddch(view->log, '\n');
 	if (view->mark && heat > UICold) {
-		if (!view->unread++) waddch(view->log, '\n');
+		if (!view->unread++) {
+			lines++;
+			waddch(view->log, '\n');
+		}
 		if (heat > UIWarm) {
 			view->hot = true;
 			beep(); // TODO: Notification.
 		}
 		uiStatus();
 	}
-	addIRC(view->log, line);
+	lines += addIRC(view->log, line);
+	if (view->scroll != LogLines) view->scroll -= lines;
 }
 
 void uiFmt(struct Tag tag, enum UIHeat heat, const wchar_t *format, ...) {
107e96&follow=1'>Add C-n and C-p key bindings to switch windowsJune McEnroe 2019-02-23Change example command to join #ascii.town on freenodeJune McEnroe 2019-02-23Call def_prog_mode after termNoFlowJune McEnroe So that the settings get restored after /url or /man. 2019-02-22Move IRC formatting reset to C-sJune McEnroe Opens C-n for window switching. 2019-02-22Disable terminal flow controlJune McEnroe This opens up C-o, C-q and C-s for key bindings without C-v. 2019-02-22Bind up and down arrows to scrollJune McEnroe Honestly it's kind of weird that IRC clients usually use these for input history. 2019-02-22Remove topic TODOJune McEnroe I played around with it and it doesn't look right unless there is only one channel listed in the status. 2019-02-22Add /znc commandJune McEnroe Only because ZNC tells you to use it and expects it to work. 2019-02-22Update status line after scrolling and term eventsJune McEnroe 2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe It's actually in a good state now, I think. 2019-02-21Replace "view" with "window"June McEnroe I think originally I didn't want to use the same word as curses WINDOW but it's really much clearer for the user if they're just called windows. UI code probably needs yet another rewrite though. Still feels messy. 2019-02-21Remove ROT13June McEnroe It's just not convenient when it can only do the whole line... 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe Otherwise the "Traveling" message isn't visible while connecting. 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe