seamus

commit 6fdaf78c83f61b246d4da8f9a39a9fe3fe679fa4

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

ui: reduce main window space so we can fit status

 src/ui.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--


diff --git a/src/ui.c b/src/ui.c
index 817d2e3fdc08b6b40b0c0ec7ef60d98e04a4ffa7..27c191c21e22ed6633e903eaddf54873ec6f624e 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -2,6 +2,7 @@ #include 
 #include <stdio.h>
 #include "ui.h"
 #include "queue.h"
+#include "status.h"
 
 int
 tickit_init(struct seamus_frontend *s)
@@ -18,11 +19,17 @@
 	s->t = t;
 
 	TickitWindow *main_window = tickit_window_new(root, (TickitRect){
-		.top = 2, .left = 2, .lines = tickit_window_lines(root) - 2,
+		.top = 2, .left = 2, .lines = tickit_window_lines(root) - 5,
+		.cols = tickit_window_cols(root) - 2
+	}, 0);
+
+	TickitWindow *status_window = tickit_window_new(root, (TickitRect){
+		.top = tickit_window_lines(root) - 5, .left = 2, .lines = 5,
 		.cols = tickit_window_cols(root) - 2
 	}, 0);
 
 	s->main_window = main_window;
+	s->status_window = status_window;
 
 	return 0;
 }
@@ -30,10 +37,10 @@
 int
 tickit_start(struct seamus_frontend *s)
 {
-
 	TickitWindow *root = tickit_get_rootwin(s->t);
 
 	tickit_window_bind_event(s->main_window, TICKIT_WINDOW_ON_EXPOSE, 0, &render_main_window, s);
+	tickit_window_bind_event(s->status_window, TICKIT_WINDOW_ON_EXPOSE, 0, &render_status_window, s);
 	tickit_window_bind_event(root, TICKIT_WINDOW_ON_EXPOSE, 0, &render_root, s);
 
 	tickit_run(s->t);
@@ -52,10 +59,57 @@ 	int right = tickit_window_cols(win) - 1;
 	int bottom = tickit_window_lines(win) - 1;
 
 	tickit_renderbuffer_eraserect(render_buffer, &(TickitRect){
-		.top = 0, .left = 0, .lines = bottom+1, .cols = right+1,
+		.top = 0, .left = 0, .lines = bottom + 1, .cols = right + 1,
 	});
 
 	return 1;
+}
+
+static int
+render_status_window(TickitWindow *win, TickitEventFlags flags, void *_info, void *data)
+{
+	log_info("Bootstraping status window");
+	TickitExposeEventInfo *info = _info;
+	TickitRenderBuffer *render_buffer = info->rb;
+	struct seamus_frontend *seamus = (struct seamus_frontend*) data;
+
+	int r = fetch_current_status(seamus);
+
+	if (r != 0) {
+		log_fatal("We had some trouble");
+
+		tickit_renderbuffer_goto(render_buffer, 0, 0);
+		{
+			tickit_renderbuffer_savepen(render_buffer);
+
+			TickitPen *pen = tickit_pen_new_attrs(
+					TICKIT_PEN_FG, 1,
+					TICKIT_PEN_BOLD, 1,
+					0);
+
+			tickit_renderbuffer_setpen(render_buffer, pen);
+			tickit_renderbuffer_text(render_buffer, "We had some error fetching the status");
+			tickit_renderbuffer_restore(render_buffer);
+		}
+
+	} else {
+		log_debug("Should have returned %d", r);
+		log_debug("Status: %s", seamus->current_status);
+
+		tickit_renderbuffer_goto(render_buffer, 0, 0);
+		{
+			tickit_renderbuffer_savepen(render_buffer);
+
+			TickitPen *pen = tickit_pen_new_attrs(
+					TICKIT_PEN_FG, 4,
+					TICKIT_PEN_BOLD, 1,
+					0);
+
+			tickit_renderbuffer_setpen(render_buffer, pen);
+			tickit_renderbuffer_text(render_buffer, seamus->current_status);
+			tickit_renderbuffer_restore(render_buffer);
+		}
+	}
 }
 
 static int