diff --git a/xource.c b/xource.c index c736e95..7aa3880 100644 --- a/xource.c +++ b/xource.c @@ -63,38 +63,50 @@ static void cursor_limits (void) { } } +static void mode_switch (void); + static void mode_none (void) { - return; + curses_bind (SIGNAL_ESCAPE, mode_switch); } static void mode_insert (void) { int signal; - for (signal = SIGNAL_A; signal != SIGNAL_9; ++signal) { + for (signal = SIGNAL_A; signal != SIGNAL_COUNT; ++signal) { + if ((signal == SIGNAL_ESCAPE) || (signal == SIGNAL_BACKSPACE) || (signal == SIGNAL_CAPS_LOCK)) { + continue; + } + curses_bind (signal, append_character); curses_bind (signal | SIGNAL_SHIFT, append_character); } + + curses_bind (SIGNAL_ESCAPE, mode_switch); + curses_bind (SIGNAL_BACKSPACE, remove_character); } static void mode_command (void) { - return; + curses_bind (SIGNAL_ESCAPE, mode_switch); } -static void mode_switch (int mode) { +static void mode_switch (void) { curses_action = deallocate (curses_action); curses_activator = deallocate (curses_activator); curses_action_count = 0; - switch (mode) { + mode_active += 1; + mode_active %= MODE_COUNT; + + switch (mode_active) { case MODE_INSERT: mode_insert (); break; case MODE_COMMAND: mode_command (); break; default: mode_none (); break; } - curses_bind (SIGNAL_ESCAPE, curses_exit); + curses_bind (SIGNAL_ESCAPE | SIGNAL_SHIFT, curses_exit); - mode_active = mode; + mode_active = mode_active; } static void render_status_bar (void) { @@ -135,11 +147,11 @@ static void render_source_code (void) { if (cursor_y < curses_screen_height) { for (offset = ++cursor_y; offset != curses_screen_height; ++offset) { - curses_render_string (" ~", COLOUR_WHITE, EFFECT_REVERSE, 0, offset); + curses_render_string (" ~", mode_active, EFFECT_REVERSE, 0, offset); } } } - +#include int main (int argc, char * * argv) { char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n"; @@ -172,7 +184,7 @@ int main (int argc, char * * argv) { curses_configure (); - mode_switch (MODE_INSERT); + /*mode_switch ();*/ do { curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL); @@ -180,56 +192,41 @@ int main (int argc, char * * argv) { render_status_bar (); render_source_code (); - cursor_x = 8; - cursor_y = 4; - curses_render_cursor (cursor_x, cursor_y); curses_synchronize (); - - if (curses_signal == ('Q' & 0X1F)) { +/* + dump ("a.log", number_to_string (curses_character)); + dump ("a.log", "\n"); +*/ + if (curses_character == ('Q' & 0X1F)) { curses_active = 0; - } else if (curses_signal == '\r') { + } else if (curses_character == '\r') { append_character (); - } else if (curses_signal == ('S' & 0X1F)) { + } else if (curses_character == ('S' & 0X1F)) { file_list_export (file_list_name [file_list_active]); - } else if (curses_signal == (char) 127) { + } else if (curses_character == (char) 127) { remove_character (); - } else if (curses_signal == '\033') { - in (& curses_signal, 1); - if (curses_signal == '[') { - in (& curses_signal, 1); - if (curses_signal == 'A') { - do { - --cursor; - } while ( - (cursor >= 0) && - (file_list_data [file_list_active] [cursor] != '\n') && - (file_list_data [file_list_active] [cursor] != '\0') - ); - --cursor; - } else if (curses_signal == 'B') { - do { - ++cursor; - } while ( - (cursor <= file_list_size [file_list_active] - 1) && - (file_list_data [file_list_active] [cursor] != '\n') && - (file_list_data [file_list_active] [cursor] != '\0') - ); - ++cursor; - } else if (curses_signal == 'C') { - ++cursor; - } else if (curses_signal == 'D') { - --cursor; - } - cursor_limits (); - } - } else if ((curses_signal >= ' ') && (curses_signal <= '~')) { + } else if (curses_character == 0X415B1B) { + do { + --cursor; + } while ((cursor >= 0) && (file_list_data [file_list_active] [cursor] != '\n') && (file_list_data [file_list_active] [cursor] != '\0')); + --cursor; + } else if (curses_character == 0X425B1B) { + do { + ++cursor; + } while ((cursor <= file_list_size [file_list_active] - 1) && (file_list_data [file_list_active] [cursor] != '\n') && (file_list_data [file_list_active] [cursor] != '\0')); + ++cursor; + } else if (curses_character == 0X435B1B) { + ++cursor; + } else if (curses_character == 0X445B1B) { + --cursor; + } else if ((curses_character >= ' ') && (curses_character <= '~')) { append_character (); - cursor_limits (); } else { continue; } + cursor_limits (); } while (curses_active != 0); file_list_delete ();