yterm

commit 6e98dc03f2368296f888d71d8f614d46d3a064a3

Author: mesyeti <mesyeti@mesyeti.uk>

fix the clear sequence

 source/app.c | 2 +-
 source/buffer.c | 16 ++++++++++------
 source/buffer.h | 7 ++++---
 source/interpreter/vt100.c | 23 ++++++++++++++---------


diff --git a/source/app.c b/source/app.c
index 0ea86677576d5b754e8003e7d23ea1de8f5dbfb7..5f7351c8dd8b0452e2628757718ecdc82b741657 100644
--- a/source/app.c
+++ b/source/app.c
@@ -129,7 +129,7 @@ 		Pane_Update(&app.tabs[i]);
 	}
 
 	// render
-	Buffer_Clear(&screen.buffer);
+	Buffer_Clear(&screen.buffer, BufAttr_Default());
 	BufCell bar;
 	bar.ch          = ' ';
 	bar.attr.fgMode = BUF_16COL;




diff --git a/source/buffer.c b/source/buffer.c
index 17b718ac73366eb9ccaf435beb7d23ec4ef83d91..f0f2ad075606c1b1aa66698c05fcd4f1e2243372 100644
--- a/source/buffer.c
+++ b/source/buffer.c
@@ -9,8 +9,12 @@ 		.invert = false
 	};
 }
 
-BufCell BufAttr_BlankCell(void) {
+BufCell BufCell_Blank(void) {
 	return (BufCell) {0, BufAttr_Default()};
+}
+
+BufCell BufCell_New(UChar ch, BufAttr attr) {
+	return (BufCell) {ch, attr};
 }
 
 static BufCell FromChar(char ch) {
@@ -90,15 +94,15 @@
 	cell->attr.invert = !cell->attr.invert;
 }
 
-void Buffer_ClearLine(Buffer* buf, int line) {
+void Buffer_ClearLine(Buffer* buf, int line, BufAttr attr) {
 	for (int i = 0; i < buf->width; ++ i) {
-		Buffer_Set(buf, i, line, BufAttr_BlankCell());
+		Buffer_Set(buf, i, line, BufCell_New(' ', attr));
 	}
 }
 
-void Buffer_Clear(Buffer* buf) {
+void Buffer_Clear(Buffer* buf, BufAttr attr) {
 	for (int i = 0; i < buf->width * buf->height; ++ i) {
-		buf->buf[i] = FromChar(0);
+		buf->buf[i] = BufCell_New(' ', attr);
 	}
 }
 
@@ -141,7 +145,7 @@ 		for (int y = 0; y < h; ++ y) {
 			BufCell* old = Buffer_Get(buf, x, y);
 
 			if (!old) {
-				new[(y * w) + x] = BufAttr_BlankCell();
+				new[(y * w) + x] = BufCell_Blank();
 			}
 			else {
 				new[(y * w) + x] = *old;




diff --git a/source/buffer.h b/source/buffer.h
index bba44f9bef42764a797cacf0235d34ff095c1520..eaabcad15f6d51459579efc0af588fb31e839a77 100644
--- a/source/buffer.h
+++ b/source/buffer.h
@@ -37,7 +37,8 @@ 	int      height;
 } Buffer;
 
 BufAttr BufAttr_Default(void);
-BufCell BufAttr_BlankCell(void);
+BufCell BufCell_Blank(void);
+BufCell BufCell_New(UChar ch, BufAttr attr);
 
 Buffer   Buffer_New(int width, int height);
 void     Buffer_Free(Buffer* buf);
@@ -46,8 +47,8 @@ bool     Buffer_CellEq(BufCell a, BufCell b);
 BufCell* Buffer_Get(Buffer* buf, int x, int y);
 void     Buffer_Set(Buffer* buf, int x, int y, BufCell cell);
 void     Buffer_InvertCell(Buffer* buf, int x, int y);
-void     Buffer_ClearLine(Buffer* buf, int line);
-void     Buffer_Clear(Buffer* buf);
+void     Buffer_ClearLine(Buffer* buf, int line, BufAttr attr);
+void     Buffer_Clear(Buffer* buf, BufAttr attr);
 void     Buffer_Print(Buffer* buf, int x, int y, BufAttr attr, const char* str);
 void     Buffer_Blit(Buffer* dest, Buffer* src, int x, int y, Rect clip);
 void     Buffer_HLine(Buffer* buf, int x, int y, int len, BufCell cell);




diff --git a/source/interpreter/vt100.c b/source/interpreter/vt100.c
index c121826c52d746cb092436388ab9ecdd57d4f420..aa46f49a03e9b551a6598c99f79392ce372fa23f 100644
--- a/source/interpreter/vt100.c
+++ b/source/interpreter/vt100.c
@@ -287,10 +287,13 @@ 			int len = terminal->buffer.width - terminal->cursor.x - amount;
 
 			memmove(to, from, len * sizeof(BufCell));
 
+			BufCell blank;
+			blank.ch   = ' ';
+			blank.attr = terminal->attr;
+
 			for (int i = 0; i < amount; ++ i) {
 				Buffer_Set(
-					&terminal->buffer, terminal->cursor.x + i, terminal->cursor.y,
-					BufAttr_BlankCell()
+					&terminal->buffer, terminal->cursor.x + i, terminal->cursor.y, blank
 				);
 			}
 			break;
@@ -372,18 +375,18 @@
 			switch (op) {
 				case 0: {
 					for (int i = terminal->cursor.y; i < terminal->buffer.height; ++ i) {
-						Buffer_ClearLine(&terminal->buffer, i);
+						Buffer_ClearLine(&terminal->buffer, i, terminal->attr);
 					}
 					break;
 				}
 				case 1: {
 					for (int i = 0; i < terminal->cursor.y; ++ i) {
-						Buffer_ClearLine(&terminal->buffer, i);
+						Buffer_ClearLine(&terminal->buffer, i, terminal->attr);
 					}
 					break;
 				}
 				case 2: {
-					Buffer_Clear(&terminal->buffer);
+					Buffer_Clear(&terminal->buffer, terminal->attr);
 					terminal->cursor = (Vec2) {0, TermTop(terminal)};
 					break;
 				}
@@ -396,24 +399,26 @@
 			if (num >= 1) {
 				op = atoi(parts[0]);
 			}
+
+			BufCell cell = BufCell_New(' ', terminal->attr);
 
 			switch (op) {
 				case 0: {
 					// TODO: compare with other impls
 					for (int i = terminal->cursor.x + 1; i < terminal->buffer.width; ++ i) {
-						Buffer_Set(&terminal->buffer, i, terminal->cursor.y, BufAttr_BlankCell());
+						Buffer_Set(&terminal->buffer, i, terminal->cursor.y, cell);
 					}
 					break;
 				}
 				case 1: {
 					for (int i = 0; i < terminal->cursor.x; ++ i) {
-						Buffer_Set(&terminal->buffer, i, terminal->cursor.y, BufAttr_BlankCell());
+						Buffer_Set(&terminal->buffer, i, terminal->cursor.y, cell);
 					}
 					break;
 				}
 				case 2: {
 					for (int i = 0; i < terminal->buffer.width; ++ i) {
-						Buffer_Set(&terminal->buffer, i, terminal->cursor.y, BufAttr_BlankCell());
+						Buffer_Set(&terminal->buffer, i, terminal->cursor.y, cell);
 					}
 					break;
 				}
@@ -429,7 +434,7 @@ 				if (i + terminal->cursor.x >= terminal->buffer.width) break;
 
 				Buffer_Set(
 					&terminal->buffer, terminal->cursor.x + i, terminal->cursor.y,
-					BufAttr_BlankCell()
+					BufCell_New(' ', terminal->attr)
 				);
 			}
 			break;