about summary refs log tree commit diff
path: root/ui.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-17 14:00:08 -0400
committerJune McEnroe <june@causal.agency>2018-08-17 14:00:08 -0400
commit38fc42f03d89693fc7e3951fd7257d394f417a6f (patch)
treede58f141248de2f1f25f1272f865495803490f16 /ui.c
parentDon't treat input as command if word contains extra slash (diff)
downloadtest-38fc42f03d89693fc7e3951fd7257d394f417a6f.tar.gz
test-38fc42f03d89693fc7e3951fd7257d394f417a6f.zip
Add UI "heat" for status/messages/pings
Bring back the beeps! Allow pings from notices. Also factor out
dequoting of part/quit messages.
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/ui.c b/ui.c
index 29b7b08..b4e48ba 100644
--- a/ui.c
+++ b/ui.c
@@ -75,6 +75,8 @@ struct View {
 	WINDOW *topic;
 	WINDOW *log;
 	int scroll;
+	int unread;
+	bool hot;
 	bool mark;
 	struct View *prev;
 	struct View *next;
@@ -145,6 +147,15 @@ static void viewClose(struct View *view) {
 	free(view);
 }
 
+static void viewMark(struct View *view) {
+	view->mark = true;
+}
+static void viewUnmark(struct View *view) {
+	view->unread = 0;
+	view->hot = false;
+	view->mark = false;
+}
+
 static struct {
 	bool hide;
 	struct View *view;
@@ -233,8 +244,8 @@ static void uiView(struct View *view) {
 	termTitle(view->tag.name);
 	if (view->topic) touchwin(view->topic);
 	touchwin(view->log);
-	ui.view->mark = true;
-	view->mark = false;
+	viewMark(ui.view);
+	viewUnmark(view);
 	ui.view = view;
 }
 
@@ -383,37 +394,40 @@ void uiTopic(struct Tag tag, const char *topic) {
 	free(wcs);
 }
 
-void uiLog(struct Tag tag, const wchar_t *line) {
+void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
 	struct View *view = viewTag(tag);
 	waddch(view->log, '\n');
-	if (view->mark) {
-		waddch(view->log, '\n');
-		view->mark = false;
+	if (view->mark && heat > UI_COLD) {
+		if (!view->unread++) waddch(view->log, '\n');
+		if (heat > UI_WARM) {
+			view->hot = true;
+			beep(); // TODO: Notification.
+		}
 	}
 	addIRC(view->log, line);
 }
 
-void uiFmt(struct Tag tag, const wchar_t *format, ...) {
+void uiFmt(struct Tag tag, enum UIHeat heat, const wchar_t *format, ...) {
 	wchar_t *wcs;
 	va_list ap;
 	va_start(ap, format);
 	vaswprintf(&wcs, format, ap);
 	va_end(ap);
 	if (!wcs) err(EX_OSERR, "vaswprintf");
-	uiLog(tag, wcs);
+	uiLog(tag, heat, wcs);
 	free(wcs);
 }
 
 static void logScrollUp(int lines) {
 	int height = logHeight(ui.view);
 	if (ui.view->scroll == height) return;
-	if (ui.view->scroll == LOG_LINES) ui.view->mark = true;
+	if (ui.view->scroll == LOG_LINES) viewMark(ui.view);
 	ui.view->scroll = MAX(ui.view->scroll - lines, height);
 }
 static void logScrollDown(int lines) {
 	if (ui.view->scroll == LOG_LINES) return;
 	ui.view->scroll = MIN(ui.view->scroll + lines, LOG_LINES);
-	if (ui.view->scroll == LOG_LINES) ui.view->mark = false;
+	if (ui.view->scroll == LOG_LINES) viewUnmark(ui.view);
 }
 static void logPageUp(void) {
 	logScrollUp(logHeight(ui.view) / 2);
@@ -426,8 +440,8 @@ static bool keyChar(wchar_t ch) {
 	if (iswascii(ch)) {
 		enum TermEvent event = termEvent((char)ch);
 		switch (event) {
-			break; case TERM_FOCUS_IN:  ui.view->mark = false;
-			break; case TERM_FOCUS_OUT: ui.view->mark = true;
+			break; case TERM_FOCUS_IN:  viewUnmark(ui.view);
+			break; case TERM_FOCUS_OUT: viewMark(ui.view);
 			break; default: {}
 		}
 		if (event) return false;
/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