yterm

commit 063cf397d36843cc3a4b890fd7cfbb02b70e8676

Author: mesyeti <mesyeti@mesyeti.uk>

make resizing work better

 source/buffer.c | 2 +-
 source/interpreter.c | 4 ++--
 source/interpreter.h | 4 ++--
 source/interpreter/vt100.c | 22 ++++++++++++++++------
 source/terminal.c | 6 ++++--


diff --git a/source/buffer.c b/source/buffer.c
index 73ba50f8dbc3a5451c6988728eba1dc95b00b519..3d0923c36d605a036c88fd174bbe865cbfb94b6f 100644
--- a/source/buffer.c
+++ b/source/buffer.c
@@ -177,7 +177,7 @@ 	}
 	else if (by < 0) {
 		by = -by;
 
-		for (int i = buf->height - by; i --> 0;) {
+		for (int i = buf->height - by; i --> by;) {
 			BufCell* src  = Buffer_Get(buf, 0, i - by);
 			BufCell* dest = Buffer_Get(buf, 0, i);
 




diff --git a/source/interpreter/vt100.c b/source/interpreter/vt100.c
index 0c50f8a68a48bb9202588fb6ba4f43ca30c0bb70..84496a4d64a16e4e2e7733da00aa075931bdbdac 100644
--- a/source/interpreter/vt100.c
+++ b/source/interpreter/vt100.c
@@ -135,7 +135,7 @@ 	return buf;
 }
 
 static void SendInput(Interpreter* p_this, Terminal* terminal, Event* e) {
-	Vt100* this = (Vt100*) p_this->data;
+	(void) p_this;
 
 	switch (e->type) {
 		case EVENT_KEY_DOWN: {
@@ -502,7 +502,7 @@ 		}
 		case 'h': {
 			if (!q || (num < 1)) break;
 
-			for (int i = 0; i < num; ++ i) {
+			for (size_t i = 0; i < num; ++ i) {
 				int param = atoi(parts[i]);
 
 				switch (param) {
@@ -533,7 +533,7 @@ 		}
 		case 'l': {
 			if (!q || (num < 1)) break;
 
-			for (int i = 0; i < num; ++ i) {
+			for (size_t i = 0; i < num; ++ i) {
 				int param = atoi(parts[i]);
 
 				switch (param) {
@@ -743,10 +743,20 @@ 		}
 	}
 }
 
-static void OnResize(Interpreter* p_this, Terminal* terminal, int w, int h) {
-	Vt100* this = (Vt100*) p_this->data;
+static void OnResize(Interpreter* p_this, Terminal* terminal, int w, int h, int ow, int oh) {
+	(void) p_this;
+	(void) w;
+	(void) ow;
 
-	
+	// Buffer_Scroll(&terminal->buffer, -(h - oh));
+	if (h > oh) {
+		Buffer_Scroll(&terminal->buffer, h - oh);
+		terminal->cursor.y -= h - oh;
+	}
+	else if (h < oh) {
+		Buffer_Scroll(&terminal->buffer, -(oh - h));
+		terminal->cursor.y += oh - h;
+	}
 }
 
 static void OnPaste(Interpreter* p_this, Terminal* terminal, const char* data) {




diff --git a/source/interpreter.c b/source/interpreter.c
index f5cc7000a26c1d76b42aee1cdb5d7ecda9249cc6..f715fa0cb96aafa4f4ab5591f1fc970b31cdca06 100644
--- a/source/interpreter.c
+++ b/source/interpreter.c
@@ -9,8 +9,8 @@ void Interpreter_OnRead(Interpreter* this, Terminal* terminal, UChar ch) {
 	this->onRead(this, terminal, ch);
 }
 
-void Interpreter_OnResize(Interpreter* this, Terminal* terminal, int w, int h) {
-	this->onResize(this, terminal, w, h);
+void Interpreter_OnResize(Interpreter* this, Terminal* terminal, int w, int h, int ow, int oh) {
+	this->onResize(this, terminal, w, h, ow, oh);
 }
 
 void Interpreter_OnPaste(Interpreter* this, Terminal* terminal, const char* data) {




diff --git a/source/interpreter.h b/source/interpreter.h
index a51385f8f4d92ac5b50405ee4237abdcf7b1283a..ef3af9dcecbb064cd5c38eb896585846625d3a2f 100644
--- a/source/interpreter.h
+++ b/source/interpreter.h
@@ -10,13 +10,13 @@ 	void* data;
 
 	void (*sendInput)(Interpreter* this, Terminal* terminal, Event* e);
 	void (*onRead)(Interpreter* this, Terminal* terminal, UChar ch);
-	void (*onResize)(Interpreter* this, Terminal* terminal, int w, int h);
+	void (*onResize)(Interpreter* this, Terminal* terminal, int w, int h, int ow, int oh);
 	void (*onPaste)(Interpreter* this, Terminal* terminal, const char* data);
 };
 
 void Interpreter_SendInput(Interpreter* this, Terminal* terminal, Event* e);
 void Interpreter_OnRead(Interpreter* this, Terminal* terminal, UChar ch);
-void Interpreter_OnResize(Interpreter* this, Terminal* terminal, int w, int h);
+void Interpreter_OnResize(Interpreter* this, Terminal* terminal, int w, int h, int ow, int oh);
 void Interpreter_OnPaste(Interpreter* this, Terminal* terminal, const char* data);
 
 #endif




diff --git a/source/terminal.c b/source/terminal.c
index b4312d85edb82ba51d0f5cae601812f372c26d1f..74fbadd50cb897ea0c9a59c557f8614a9016995b 100644
--- a/source/terminal.c
+++ b/source/terminal.c
@@ -44,7 +44,7 @@
 		Interpreter_OnRead((Interpreter*) terminal->interpreter, terminal, (UChar) ch);
 
 		++ it;
-		if (it > 4096) return;
+		if (it >= 16384) return; // TODO: better way?
 	}
 }
 
@@ -62,6 +62,8 @@ 	}
 }
 
 void Terminal_Resize(Terminal* terminal, int w, int h) {
+	int ow   = terminal->buffer.width;
+	int oh   = terminal->height;
 	int diff = h - terminal->height;
 
 	terminal->scroll -= diff;
@@ -69,5 +71,5 @@ 	terminal->height  = h;
 
 	Buffer_Resize(&terminal->buffer,    w, terminal->buffer.height);
 	SysTerm_UpdateSize(&terminal->term, w, h);
-	Interpreter_OnResize((Interpreter*) terminal->interpreter, terminal, w, h);
+	Interpreter_OnResize((Interpreter*) terminal->interpreter, terminal, w, h, ow, oh);
 }