summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-08-05 17:43:11 -0400
committerJune McEnroe <june@causal.agency>2019-08-05 17:43:11 -0400
commit2674e91561efab3333fe5b5dd98d19716cab7080 (patch)
tree790923cbad855ba3180e79fb1b457f6ae052bbd4
parentImplement ECH (diff)
downloadstream-2674e91561efab3333fe5b5dd98d19716cab7080.tar.gz
stream-2674e91561efab3333fe5b5dd98d19716cab7080.zip
Add termDisplay
-rw-r--r--stream.h20
-rw-r--r--term.c21
2 files changed, 30 insertions, 11 deletions
diff --git a/stream.h b/stream.h
index 56889c2..0bb7507 100644
--- a/stream.h
+++ b/stream.h
@@ -14,10 +14,30 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <stdbool.h>
 #include <wchar.h>
 
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
 typedef unsigned uint;
 
+struct Style {
+	bool bold, italic, underline, reverse;
+	int bg, fg;
+};
+
+struct Cell {
+	struct Style style;
+	wchar_t ch;
+};
+
+struct Display {
+	uint rows, cols;
+	uint y, x;
+	const struct Cell *cells;
+};
+
 void termInit(uint rows, uint cols);
 void termUpdate(wchar_t ch);
 int termSnapshot(int fd);
+struct Display termDisplay(void);
diff --git a/term.c b/term.c
index 97a3ee1..5d7a918 100644
--- a/term.c
+++ b/term.c
@@ -25,8 +25,6 @@
 
 #include "stream.h"
 
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
 enum {
 	NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL,
 	BS, HT, NL, VT, NP, CR, SO, SI,
@@ -35,17 +33,8 @@ enum {
 	DEL = 0x7F,
 };
 
-struct Style {
-	bool bold, italic, underline, reverse;
-	int bg, fg;
-};
 static const struct Style Default = { .bg = -1, .fg = -1 };
 
-struct Cell {
-	struct Style style;
-	wchar_t ch;
-};
-
 static uint rows, cols;
 static uint y, x;
 
@@ -470,3 +459,13 @@ fail:
 	fclose(file);
 	return -1;
 }
+
+struct Display termDisplay(void) {
+	return (struct Display) {
+		.rows = rows,
+		.cols = cols,
+		.y = y,
+		.x = x,
+		.cells = cells,
+	};
+}