]> khamidou — GitHub mirrors - te.git/commitdiff
added a command loop embryo
authorkhamidou <karim@lambda-expr.org>
Tue, 31 Mar 2009 06:23:27 +0000 (08:23 +0200)
committerkhamidou <karim@lambda-expr.org>
Tue, 31 Mar 2009 06:23:27 +0000 (08:23 +0200)
Makefile
buffer.c
keyb.c [new file with mode: 0644]
keyb.h [new file with mode: 0644]
main.c
screen.c

index 25b91036cb3143f078377178fdad771cb2605bc5..ef7e3b80b0251e2cce15ccf14cc17a2904d13760 100644 (file)
--- 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
index 4e2bb300e2ad6d1db7fb8d184347930081e7d9fb..fc847e76926145ec73c142e9b52c2ad2a795cf34 100644 (file)
--- 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 (file)
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 (file)
index 0000000..cdb75a1
--- /dev/null
+++ b/keyb.h
@@ -0,0 +1,8 @@
+#ifndef __KEYB_H__
+#define __KEYB_H__
+
+#include <stdlib.h>
+
+void input_loop(void);
+
+#endif
diff --git a/main.c b/main.c
index 9065c1743dfed520206507bed4569f2dc9cffcc8..5dc4c3fcb34b7fc1778489926c161c470908b216 100644 (file)
--- 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();
 
 }
 
index 5135c7012cc62c0c3d697ea5c18d6820919cc452..6e37e3d758ada0ea718136299b5b49c8b1af38e3 100644 (file)
--- 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);
 }