summary refs log tree commit diff
path: root/ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/ui.c b/ui.c
index 6d1338b..c738617 100644
--- a/ui.c
+++ b/ui.c
@@ -573,6 +573,34 @@ void uiShowNum(size_t num) {
 	windowShow(window);
 }
 
+static void windowClose(struct Window *window) {
+	if (window->id == Network) return;
+	if (windows.active == window) {
+		windowShow(window->prev ? window->prev : window->next);
+	}
+	if (windows.other == window) windows.other = NULL;
+	windowRemove(window);
+	for (size_t i = 0; i < BufferCap; ++i) {
+		free(window->buffer.lines[i]);
+	}
+	delwin(window->pad);
+	free(window);
+	statusUpdate();
+}
+
+void uiCloseID(size_t id) {
+	windowClose(windowFor(id));
+}
+
+void uiCloseNum(size_t num) {
+	struct Window *window = windows.head;
+	for (size_t i = 0; i < num; ++i) {
+		window = window->next;
+		if (!window) return;
+	}
+	windowClose(window);
+}
+
 static void keyCode(int code) {
 	size_t id = windows.active->id;
 	switch (code) {