summary refs log tree commit diff
path: root/view.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-08-10 15:47:59 -0400
committerJune McEnroe <june@causal.agency>2019-08-10 15:47:59 -0400
commit6d7320a10ded22619ee49eb71e8380fd514b849b (patch)
tree40fa5e95e8c75e734cae9a33c10528a0aa68d845 /view.c
parentFlip enumerator-constant order for sorting (diff)
downloadstream-6d7320a10ded22619ee49eb71e8380fd514b849b.tar.gz
stream-6d7320a10ded22619ee49eb71e8380fd514b849b.zip
Rewrite terminal emulator
Diffstat (limited to 'view.c')
-rw-r--r--view.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/view.c b/view.c
index a5861c4..7a40123 100644
--- a/view.c
+++ b/view.c
@@ -27,7 +27,7 @@
 #include <sysexits.h>
 #include <unistd.h>
 
-#include "stream.h"
+#include "term.h"
 
 #ifndef A_ITALIC
 #define A_ITALIC A_UNDERLINE
@@ -86,10 +86,10 @@ static attr_t styleAttr(struct Style style) {
 	return attr;
 }
 
-static void render(WINDOW *win, struct Display term) {
-	for (uint y = 0; y < term.rows; ++y) {
-		for (uint x = 0; x < term.cols; ++x) {
-			struct Cell cell = term.cells[term.cols * y + x];
+static void render(WINDOW *win, const struct Term *term) {
+	for (uint y = 0; y < term->rows; ++y) {
+		for (uint x = 0; x < term->cols; ++x) {
+			struct Cell cell = term->cells[term->cols * y + x];
 			if (!cell.ch) continue;
 			wattr_set(
 				win,
@@ -100,9 +100,9 @@ static void render(WINDOW *win, struct Display term) {
 			mvwaddnwstr(win, y, x, &cell.ch, 1);
 		}
 	}
-	curs_set(term.cursor);
-	leaveok(win, !term.cursor);
-	wmove(win, term.y, term.x);
+	curs_set(!!(term->mode & Cursor));
+	leaveok(win, !(term->mode & Cursor));
+	wmove(win, term->y, term->x);
 }
 
 int main(void) {
@@ -111,7 +111,7 @@ int main(void) {
 
 	// TODO: Read info from file.
 	const char *path = "example.sock";
-	termInit(24, 80);
+	struct Term *term = termAlloc(24, 80);
 
 	int client = socket(PF_LOCAL, SOCK_STREAM, 0);
 	if (client < 0) err(EX_OSERR, "socket");
@@ -134,11 +134,11 @@ int main(void) {
 			wchar_t ch;
 			int n = mbtowc(&ch, &buf[pos], len - pos);
 			if (n <= 0) break;
-			termUpdate(ch);
+			termUpdate(term, ch);
 			pos += n;
 		}
 
-		render(win, termDisplay());
+		render(win, term);
 		wrefresh(win);
 	}
 }