]> khamidou — GitHub mirrors - te.git/commitdiff
screen modifications
authorkhamidou <karim@lambda-expr.org>
Mon, 30 Mar 2009 20:45:50 +0000 (22:45 +0200)
committerkhamidou <karim@lambda-expr.org>
Mon, 30 Mar 2009 20:45:50 +0000 (22:45 +0200)
Makefile
buffer.c
buffer.h
main.c
screen.c
screen.h

index 68c67c06a03422cb04b80c081a993a9eda612291..25b91036cb3143f078377178fdad771cb2605bc5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 CC=gcc
-CFLAGS=-c
+CFLAGS=-c -g
 LDFLAGS=-lcurses
 OBJS=main.o errors.o screen.o buffer.o
 
@@ -18,3 +18,6 @@ screen.o: screen.c
 buffer.o: buffer.c
        $(CC) $(CFLAGS) buffer.c
 
+clean: $(OBJS)
+       rm $(OBJS)
+       rm te
\ No newline at end of file
index 686e5bff157bd93178cb41dbbb994e595dd7d1e8..4e2bb300e2ad6d1db7fb8d184347930081e7d9fb 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -4,7 +4,12 @@
 #include "error.h"
 #include "buffer.h"
 
-struct te_char *alloc_and_insert_char(struct te_buffer *buf)
+void init_buffers(void)
+{
+       TAILQ_INIT(&buffers_head);
+}
+
+struct te_char *alloc_and_insert_char(struct te_buffer *buf, char contents)
 {
        if (buf == NULL)
                fail("The buffer parameter to alloc_and_insert_char is NULL");
@@ -16,6 +21,7 @@ struct te_char *alloc_and_insert_char(struct te_buffer *buf)
 
        TAILQ_INSERT_TAIL(&buf->chars_head, c, chars);
 
+       c->contents = contents;
        return c;
 }
 
@@ -26,6 +32,7 @@ struct te_buffer *alloc_and_insert_buffer(void)
        if (b == NULL)
                fail("Unable to allocate memory for te_buffer struct");
 
+       TAILQ_INIT(&b->chars_head);
        TAILQ_INSERT_TAIL(&buffers_head, b, buffers);
 
        return b;
@@ -50,3 +57,54 @@ void free_buffer(struct te_buffer *b)
 
        free(b);
 }
+
+
+struct te_buffer* load_buffer(char *filename)
+{
+       FILE *fp = fopen(filename, "r");
+
+       if (fp == NULL)
+               fail("Unable to open %s", filename);
+
+       struct te_buffer *b = alloc_and_insert_buffer();
+
+       char c = getc(fp);
+
+       while(!feof(fp)) {
+               alloc_and_insert_char(b, c);
+               c = getc(fp);
+       }
+
+       return b;
+}
+
+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)
+{
+
+}
+
index bbba8753704886ac20fd2d308742842c15a7529c..47248ee2b5fa7c8b0aad347b3c7c9e41e53b55a1 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -1,6 +1,7 @@
 #ifndef __BUFFER_H__
 #define __BUFFER_H__
 
+#include <stdio.h>
 #include "queue.h"
 
 struct te_char {
@@ -11,16 +12,19 @@ struct te_char {
 struct te_buffer {
        char *name;
        int dirty;
+       int x, y;
+       struct te_char *point;
        TAILQ_HEAD(te_chars_head, te_char) chars_head;
        TAILQ_ENTRY(te_buffer) buffers;
 };
 
 TAILQ_HEAD(te_buffers_head, te_buffer) buffers_head;
 
-struct         te_char                 *alloc_and_insert_char(struct te_buffer *buf);
+struct te_char                         *alloc_and_insert_char(struct te_buffer *buf, char contents);
 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_buffer*              load_buffer(char *filename);
 
 void                           init_buffers(void);
 void                           scroll_up(struct te_buffer *buf);
diff --git a/main.c b/main.c
index c212b68699f3fa65118d461ed16ef2a25cf9cd5b..9065c1743dfed520206507bed4569f2dc9cffcc8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,8 +8,12 @@
 
 int main(int argc, char **argv)
 {
+       init_buffers();
        init_windows();
+       struct te_buffer *b = load_buffer("screen.c");
+       paint_buffer(b);
        miniprintf("Over the top!");
+       statusprintf("Reverse video !");
        while(1) {
 
        }
index 68c2b97f0c4b29213d1bfbd1a5212a5c969b6f09..5135c7012cc62c0c3d697ea5c18d6820919cc452 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -5,9 +5,14 @@ void init_windows(void)
        initscr();
        cbreak();
        noecho();
+       scrollok(stdscr, FALSE);
        keypad(stdscr, TRUE);
 
-       buffer_win = subwin(stdscr, LINES - 2, COLS - 2, 0, 0);
+       buffer_win = subwin(stdscr, LINES - 2, COLS, 0, 0);
+
+       status_win = subwin(stdscr, 1, COLS, LINES - 2, 0);
+       wattron(status_win, A_REVERSE);
+
        minibuffer_win = subwin(stdscr, 1, COLS, LINES - 1, 0);
 
        if (signal(SIGWINCH, console_signal_handler) == SIG_ERR)
@@ -21,7 +26,21 @@ void cleanup_windows(void)
 
 void paint_buffer(struct te_buffer *buf)
 {
+       if (buf == NULL)
+               return;
+
+       struct te_char *c;
+       int y, x;
+
+       TAILQ_FOREACH(c, &buf->chars_head, chars) {
+               getyx(stdscr, y, x);
+               if (y >= LINES -2)
+                       break;
 
+               waddch(buffer_win, c->contents);
+       }
+       
+       refresh();
 }
 
 void screen_move_left(void)
@@ -44,6 +63,18 @@ void screen_move_down(void)
 
 }
 
+void statusprintf(char *fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       vwprintw(status_win, fmt, ap);
+       va_end(ap);
+
+       wclrtoeol(status_win);
+       wrefresh(status_win);
+}
+
+
 void miniprintf(char *fmt, ...)
 {
        va_list ap;
index ac65c86acd30b2edc9974b967c9efeaa4b14645b..0d95fb1e2ce95dad97c4af797ae6dffbea58b2a6 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -7,7 +7,7 @@
 
 #include "buffer.h"
 
-WINDOW *buffer_win, *minibuffer_win;
+WINDOW *buffer_win, *status_win, *minibuffer_win;
 
 void init_windows(void);
 void cleanup_windows(void);
@@ -18,6 +18,7 @@ void screen_move_right(void);
 void screen_move_up(void);
 void screen_move_down(void);
 
+void statusprintf(char *fmt, ...);
 void miniprintf(char *fmt, ...);
 
 void console_signal_handler(int sig);