From: khamidou Date: Tue, 31 Mar 2009 06:23:27 +0000 (+0200) Subject: added a command loop embryo X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=334d88d7ab31871418711d6a09a2e77bac2f2b4e;p=te.git added a command loop embryo --- diff --git a/Makefile b/Makefile index 25b9103..ef7e3b8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=gcc CFLAGS=-c -g LDFLAGS=-lcurses -OBJS=main.o errors.o screen.o buffer.o +OBJS=main.o errors.o screen.o buffer.o keyb.o te: $(OBJS) $(CC) $(LDFLAGS) -o te $(OBJS) @@ -18,6 +18,9 @@ screen.o: screen.c buffer.o: buffer.c $(CC) $(CFLAGS) buffer.c +keyb.o: keyb.c + $(CC) $(CFLAGS) keyb.c + clean: $(OBJS) rm $(OBJS) rm te \ No newline at end of file diff --git a/buffer.c b/buffer.c index 4e2bb30..fc847e7 100644 --- a/buffer.c +++ b/buffer.c @@ -75,6 +75,7 @@ struct te_buffer* load_buffer(char *filename) c = getc(fp); } + statusprintf("%s", filename); return b; } diff --git a/keyb.c b/keyb.c new file mode 100644 index 0000000..189a22d --- /dev/null +++ b/keyb.c @@ -0,0 +1,14 @@ +#include "keyb.h" + +void input_loop(void) +{ + while(1) { + char c = getch(); + + switch(c) { + case 'q': + exit(0); + } + } + +} diff --git a/keyb.h b/keyb.h new file mode 100644 index 0000000..cdb75a1 --- /dev/null +++ b/keyb.h @@ -0,0 +1,8 @@ +#ifndef __KEYB_H__ +#define __KEYB_H__ + +#include + +void input_loop(void); + +#endif diff --git a/main.c b/main.c index 9065c17..5dc4c3f 100644 --- a/main.c +++ b/main.c @@ -10,13 +10,14 @@ 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) { - } + + + input_loop(); } diff --git a/screen.c b/screen.c index 5135c70..6e37e3d 100644 --- a/screen.c +++ b/screen.c @@ -5,7 +5,7 @@ void init_windows(void) initscr(); cbreak(); noecho(); - scrollok(stdscr, FALSE); + scrollok(stdscr, TRUE); keypad(stdscr, TRUE); buffer_win = subwin(stdscr, LINES - 2, COLS, 0, 0); @@ -17,6 +17,8 @@ void init_windows(void) if (signal(SIGWINCH, console_signal_handler) == SIG_ERR) fail("Unable to set up the SIGWINCH signal handler"); + + atexit(&cleanup_windows); } void cleanup_windows(void) @@ -65,12 +67,25 @@ void screen_move_down(void) void statusprintf(char *fmt, ...) { + werase(status_win); + wmove(status_win, 0, 0); + va_list ap; va_start(ap, fmt); vwprintw(status_win, fmt, ap); va_end(ap); - wclrtoeol(status_win); + /* We have to clear the screen to the end of line because for some unexpected + reason, curses doesn't want to do it + */ + + int y, x; + getyx(stdscr, y, x); + while(x <= COLS) { + waddch(status_win, ' '); + x++; + } + wrefresh(status_win); }