From: khamidou Date: Thu, 9 Jul 2009 17:08:18 +0000 (+0200) Subject: no message X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bc2ab07441f14f974dec2808232119e11c8e1b93;p=te.git no message --- diff --git a/Makefile b/Makefile index 757b300..222c065 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=gcc -CFLAGS=-c -g `lua-config --include` -LDFLAGS=-lcurses `lua-config --libs` -OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o lua-api.o +CFLAGS=-c -g +LDFLAGS=-lcurses +OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o te: $(OBJS) $(CC) $(LDFLAGS) -o te $(OBJS) @@ -24,9 +24,6 @@ keyb.o: keyb.c bstrlib.o: bstrlib.c $(CC) $(CFLAGS) bstrlib.c -lua-api.o: lua-api.c - $(CC) $(CFLAGS) lua-api.c - clean: rm $(OBJS) rm *~ diff --git a/keyb.c b/keyb.c index c227ac2..52c8c7a 100644 --- a/keyb.c +++ b/keyb.c @@ -1,50 +1,108 @@ #include "keyb.h" +int command_mode = 1; /* command mode = 1, input mode = 0 */ +char *str; + void input_loop(void) { while(1) { int c = getch(); - switch(c) { - case 'q': - exit(0); - - case KEY_LEFT: - screen_move_left(current_buf); - break; - - case KEY_RIGHT: - screen_move_right(current_buf); - break; - - case KEY_DOWN: - screen_move_down(current_buf); - break; - - case KEY_UP: - screen_move_up(current_buf); - break; - - case KEY_BACKSPACE: - screen_delete_char(current_buf); - break; - - case 'w': - write_buffer(current_buf); - break; - default: - screen_insert_char(current_buf, c); - refresh(); - break; - } - + if (command_mode) + process_command(c); + else + process_input(c); + refresh(); - miniprintf("%c, line length: %d, y: %d, x%d", - (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), - screen_line_length(current_buf->contents, current_buf->point), - current_buf->y, current_buf->x); +/* miniprintf("%c, line length: %d, y: %d, x%d", */ +/* (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), */ +/* screen_line_length(current_buf->contents, current_buf->point), */ +/* current_buf->y, current_buf->x); */ } } + + +void process_command(int c) +{ + switch(c) { + case 'q': + exit(0); + + case 'h': + case KEY_LEFT: + screen_move_left(current_buf); + break; + + case 'l': + case KEY_RIGHT: + screen_move_right(current_buf); + break; + + case 'j': + case KEY_DOWN: + screen_move_down(current_buf); + break; + + case 'k': + case KEY_UP: + screen_move_up(current_buf); + break; + + case 'w': + write_buffer(current_buf); + break; + + case 'i': + case KEY_END: + /* switch between command and input mode */ + command_mode = 0; + break; + + case 'v': + str = read_user_input(); + miniprintf("you entered : %s", str); + break; + + default: + miniprintf("%c - invalid command", c); + break; + } +} + +void process_input(int c) +{ + switch(c) { + case KEY_BACKSPACE: + screen_delete_char(current_buf); + break; + + case KEY_LEFT: + screen_move_left(current_buf); + break; + + case KEY_RIGHT: + screen_move_right(current_buf); + break; + + case KEY_DOWN: + screen_move_down(current_buf); + break; + + case KEY_UP: + screen_move_up(current_buf); + break; + + case KEY_END: + command_mode = 1; + break; + + default: + screen_insert_char(current_buf, c); + refresh(); + break; + } + +} diff --git a/keyb.h b/keyb.h index 003c365..eec90ca 100644 --- a/keyb.h +++ b/keyb.h @@ -6,6 +6,8 @@ #include "screen.h" void input_loop(void); +void process_command(int c); /* process a command */ +void process_input(int c); /* process a normal char - that is, not a command */ struct te_buffer *current_buf; diff --git a/py2c.py b/py2c.py deleted file mode 100755 index a813612..0000000 --- a/py2c.py +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env python -# -# py2c takes as parameters a list of python files and creates one big C file -# that contains strings that are fed to the python interpreter. - -import sys - -try: - ofile = open("py2cout.c", "w+") -except IOError: - print "Unable to open py2cout.c" - sys.exit(-1) - -skel = -"/* This code has been generated by py2c.py -#include " - -ofile.write(skel) - -for i in sys.argv[1:]: - try: - f = open(i, "r") - except IOError: - print "Unable to open " + i - sys.exit(-1) - - c = f.read() - - diff --git a/screen.c b/screen.c index dcf1acb..ac1cebd 100644 --- a/screen.c +++ b/screen.c @@ -1,3 +1,4 @@ +#include "zalloc.h" #include "screen.h" #include "util.h" @@ -269,6 +270,11 @@ void screen_delete_char(struct te_buffer *buf) move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */ } +void screen_switch_buffer(struct te_buffer *buf) +{ + +} + /* display a message in the status bar. */ @@ -332,6 +338,26 @@ void notifyprintf(char *fmt, ...) getch(); /* discard input */ } +char *read_user_input(void) +{ + char *s = zalloc(255); + int c = 0; + int i = 0; + + for (i = 0; i < 255 && c != KEY_ENTER; i++) { + c = getch(); + waddch(minibuffer_win, c); + *(s + i) = c; + } + + if ((void *) c == NULL) + fail("Unable to allocate memory at __FILE__:__LINE__\n"); + + if (getnstr(c, 255) == ERR) + return (char *) ERR; + + return (char *) c; +} void console_signal_handler(int sig) { diff --git a/screen.h b/screen.h index 96dd6aa..bcb31a3 100644 --- a/screen.h +++ b/screen.h @@ -27,6 +27,7 @@ void screen_move_down(struct te_buffer *buf); void statusprintf(char *fmt, ...); void miniprintf(char *fmt, ...); void notifyprintf(char *fmt, ...); +char *read_user_input(void); void console_signal_handler(int sig);