]> khamidou — GitHub mirrors - te.git/commitdiff
adding screen management routines
authorkhamidou <karim@lambda-expr.org>
Mon, 30 Mar 2009 19:03:25 +0000 (21:03 +0200)
committerkhamidou <karim@lambda-expr.org>
Mon, 30 Mar 2009 19:03:25 +0000 (21:03 +0200)
Makefile
buffer.c
buffer.h
main.c
screen.c [new file with mode: 0644]
screen.h [new file with mode: 0644]

index 2a00bf4ed2202c3b8d70ee799c6c32282178c7df..68c67c06a03422cb04b80c081a993a9eda612291 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
 CFLAGS=-c
 LDFLAGS=-lcurses
-OBJS=main.o
+OBJS=main.o errors.o screen.o buffer.o
 
 te: $(OBJS)
        $(CC) $(LDFLAGS) -o te $(OBJS)
@@ -9,3 +9,12 @@ te: $(OBJS)
 main.o: main.c
        $(CC) $(CFLAGS) main.c
 
+error.o: error.c
+       $(CC) $(CFLAGS) error.c
+
+screen.o: screen.c
+       $(CC) $(CFLAGS) screen.c
+
+buffer.o: buffer.c
+       $(CC) $(CFLAGS) buffer.c
+
index 326a170e3427a83f99df72598cc740a730fc94a7..686e5bff157bd93178cb41dbbb994e595dd7d1e8 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -36,7 +36,7 @@ void free_char(struct te_buffer *b, struct te_char *c)
        if (b == NULL || c == NULL)
                fail("One of the parameters to free_char() is NULL");
 
-       TAILQ_REMOVE(&b->chars, c, chars);
+       TAILQ_REMOVE(&b->chars_head, c, chars);
 
        free(c);
 }
index e8589a8453f70c8524ad5b802a32798253bc0dc0..bbba8753704886ac20fd2d308742842c15a7529c 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -17,11 +17,19 @@ struct te_buffer {
 
 TAILQ_HEAD(te_buffers_head, te_buffer) buffers_head;
 
-struct te_char                 *alloc_and_insert_char(struct te_buffer *buf);
-struct te_buffer       *alloc_and_insert_buffer(void);
-void                   free_char(struct te_buffer *b, struct te_char *c);
-void                   free_buffer(struct te_buffer *b);
+struct         te_char                 *alloc_and_insert_char(struct te_buffer *buf);
+struct te_buffer               *alloc_and_insert_buffer(void);
+void                           free_char(struct te_buffer *b, struct te_char *c);
+void                           free_buffer(struct te_buffer *b);
+
+void                           init_buffers(void);
+void                           scroll_up(struct te_buffer *buf);
+void                           scroll_down(struct te_buffer *buf);
+void                           move_left(struct te_buffer *buf);
+void                           move_right(struct te_buffer *buf);
+void                           move_up(struct te_buffer *buf);
+void                           move_down(struct te_buffer *buf);
+
 
-void init_buffers();
 
 #endif
diff --git a/main.c b/main.c
index 42f68f5107ea29823f131e908f2d97dd016695cc..c212b68699f3fa65118d461ed16ef2a25cf9cd5b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,7 +8,11 @@
 
 int main(int argc, char **argv)
 {
-       puts("Over the top!");
+       init_windows();
+       miniprintf("Over the top!");
+       while(1) {
+
+       }
 
 }
 
diff --git a/screen.c b/screen.c
new file mode 100644 (file)
index 0000000..68c2b97
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,66 @@
+#include "screen.h"
+
+void init_windows(void)
+{
+       initscr();
+       cbreak();
+       noecho();
+       keypad(stdscr, TRUE);
+
+       buffer_win = subwin(stdscr, LINES - 2, COLS - 2, 0, 0);
+       minibuffer_win = subwin(stdscr, 1, COLS, LINES - 1, 0);
+
+       if (signal(SIGWINCH, console_signal_handler) == SIG_ERR)
+               fail("Unable to set up the SIGWINCH signal handler");
+}
+
+void cleanup_windows(void)
+{
+       endwin();
+}
+
+void paint_buffer(struct te_buffer *buf)
+{
+
+}
+
+void screen_move_left(void)
+{
+
+}
+
+void screen_move_right(void)
+{
+
+}
+
+void screen_move_up(void)
+{
+
+}
+
+void screen_move_down(void)
+{
+
+}
+
+void miniprintf(char *fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       vwprintw(minibuffer_win, fmt, ap);
+       va_end(ap);
+
+       wrefresh(minibuffer_win);
+}
+
+void console_signal_handler(int sig)
+{
+       switch(sig) {
+       case SIGWINCH:
+       default:
+               refresh();
+               break;
+
+       }
+}
diff --git a/screen.h b/screen.h
new file mode 100644 (file)
index 0000000..ac65c86
--- /dev/null
+++ b/screen.h
@@ -0,0 +1,25 @@
+#ifndef __SCREEN_H__
+#define __SCREEN_H__
+
+#include <stdarg.h>
+#include <signal.h>
+#include <curses.h>
+
+#include "buffer.h"
+
+WINDOW *buffer_win, *minibuffer_win;
+
+void init_windows(void);
+void cleanup_windows(void);
+
+void paint_buffer(struct te_buffer *buf);
+void screen_move_left(void);
+void screen_move_right(void);
+void screen_move_up(void);
+void screen_move_down(void);
+
+void miniprintf(char *fmt, ...);
+
+void console_signal_handler(int sig);
+
+#endif