From: khamidou Date: Mon, 30 Mar 2009 19:03:25 +0000 (+0200) Subject: adding screen management routines X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a8b65f196ecde10f0fb4d39fd941d7d4d1562cd3;p=te.git adding screen management routines --- diff --git a/Makefile b/Makefile index 2a00bf4..68c67c0 100644 --- 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 + diff --git a/buffer.c b/buffer.c index 326a170..686e5bf 100644 --- 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); } diff --git a/buffer.h b/buffer.h index e8589a8..bbba875 100644 --- 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 42f68f5..c212b68 100644 --- 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 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 index 0000000..ac65c86 --- /dev/null +++ b/screen.h @@ -0,0 +1,25 @@ +#ifndef __SCREEN_H__ +#define __SCREEN_H__ + +#include +#include +#include + +#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