|
|
@ -19,7 +19,7 @@ |
|
|
|
#define MODE_MASK 0x1 |
|
|
|
#define MODE_MASK 0x1 |
|
|
|
#define COMMAND_MASK 0x06 |
|
|
|
#define COMMAND_MASK 0x06 |
|
|
|
|
|
|
|
|
|
|
|
#define NORMAL_M 0x0 |
|
|
|
#define NORMAL_MODE 0x0 |
|
|
|
#define COMMAND_M 0x1 |
|
|
|
#define COMMAND_M 0x1 |
|
|
|
|
|
|
|
|
|
|
|
#define FIND_C 0x1 |
|
|
|
#define FIND_C 0x1 |
|
|
@ -125,7 +125,7 @@ int main (int argc, char *argv[]) |
|
|
|
snprintf(t.statusbar, STAT_SIZE, "%s %d lines %dx%d", argv[1], rows.rownum, t.dim.y, t.dim.x); |
|
|
|
snprintf(t.statusbar, STAT_SIZE, "%s %d lines %dx%d", argv[1], rows.rownum, t.dim.y, t.dim.x); |
|
|
|
|
|
|
|
|
|
|
|
/* Main event loop */ |
|
|
|
/* Main event loop */ |
|
|
|
int c; |
|
|
|
static int c; |
|
|
|
while (1) { |
|
|
|
while (1) { |
|
|
|
updateInfo(); |
|
|
|
updateInfo(); |
|
|
|
/* Redraw the screen */ |
|
|
|
/* Redraw the screen */ |
|
|
@ -137,18 +137,18 @@ int main (int argc, char *argv[]) |
|
|
|
termExit(); |
|
|
|
termExit(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_LEFT): |
|
|
|
case (KEY_MOVE_UP): |
|
|
|
case (KEY_RIGHT): |
|
|
|
case (KEY_MOVE_DOWN): |
|
|
|
case (KEY_UP): |
|
|
|
case (KEY_MOVE_LEFT): |
|
|
|
case (KEY_DOWN): |
|
|
|
case (KEY_MOVE_RIGHT): |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_M) |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_MODE) |
|
|
|
cursorMove(c); |
|
|
|
cursorMove(c); |
|
|
|
else |
|
|
|
else |
|
|
|
switch (c) { |
|
|
|
switch (c) { |
|
|
|
case (KEY_LEFT): |
|
|
|
case (KEY_MOVE_LEFT): |
|
|
|
sbMove(&t.search_buffer, -1); |
|
|
|
sbMove(&t.search_buffer, -1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case (KEY_RIGHT): |
|
|
|
case (KEY_MOVE_RIGHT): |
|
|
|
sbMove(&t.search_buffer, 1); |
|
|
|
sbMove(&t.search_buffer, 1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -156,7 +156,7 @@ int main (int argc, char *argv[]) |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_BACKSPACE): |
|
|
|
case (KEY_BACKSPACE): |
|
|
|
case (KEY_DC): |
|
|
|
case (KEY_DC): |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_M) |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_MODE) |
|
|
|
handleDel(c); |
|
|
|
handleDel(c); |
|
|
|
else |
|
|
|
else |
|
|
|
sbPop(&t.search_buffer); |
|
|
|
sbPop(&t.search_buffer); |
|
|
@ -165,7 +165,7 @@ int main (int argc, char *argv[]) |
|
|
|
case (KEY_ENTER): |
|
|
|
case (KEY_ENTER): |
|
|
|
case (10): |
|
|
|
case (10): |
|
|
|
case ('\r'): |
|
|
|
case ('\r'): |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_M) { |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_MODE) { |
|
|
|
rowAddRow(&rows, t.cur.y, t.cur.x); |
|
|
|
rowAddRow(&rows, t.cur.y, t.cur.x); |
|
|
|
t.cur.y++; |
|
|
|
t.cur.y++; |
|
|
|
t.cur.x = 0; |
|
|
|
t.cur.x = 0; |
|
|
@ -177,23 +177,23 @@ int main (int argc, char *argv[]) |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_END): |
|
|
|
case (KEY_ROW_END): |
|
|
|
t.cur.x = rows.rw[t.cur.y].size; |
|
|
|
t.cur.x = rows.rw[t.cur.y].size; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_HOME): |
|
|
|
case (KEY_ROW_BEG): |
|
|
|
t.cur.x = 0; |
|
|
|
t.cur.x = 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_NPAGE): |
|
|
|
case (KEY_JUMP_DOWN): |
|
|
|
t.cur.y += PGK_DELTA; |
|
|
|
t.cur.y += PGK_DELTA; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_PPAGE): |
|
|
|
case (KEY_JUMP_UP): |
|
|
|
t.cur.y -= PGK_DELTA; |
|
|
|
t.cur.y -= PGK_DELTA; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (CTRL('f')): |
|
|
|
case (KEY_FILE_FIND): |
|
|
|
// Toggle mode
|
|
|
|
// Toggle mode
|
|
|
|
t.mode_b ^= MODE_MASK; |
|
|
|
t.mode_b ^= MODE_MASK; |
|
|
|
sbFlush (&t.search_buffer); |
|
|
|
sbFlush (&t.search_buffer); |
|
|
@ -201,7 +201,7 @@ int main (int argc, char *argv[]) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_M) { |
|
|
|
if ((t.mode_b & MODE_MASK) == NORMAL_MODE) { |
|
|
|
t.mode_b |= MODIFIED; |
|
|
|
t.mode_b |= MODIFIED; |
|
|
|
if (c == KEY_STAB) c = '\t'; |
|
|
|
if (c == KEY_STAB) c = '\t'; |
|
|
|
rowAddChar(&rows.rw[t.cur.y], c, t.cur.x); |
|
|
|
rowAddChar(&rows.rw[t.cur.y], c, t.cur.x); |
|
|
@ -302,7 +302,7 @@ void drawScreen () |
|
|
|
drawLines(); |
|
|
|
drawLines(); |
|
|
|
/* draw the bar */ |
|
|
|
/* draw the bar */ |
|
|
|
drawBar( |
|
|
|
drawBar( |
|
|
|
((t.mode_b & MODE_MASK) == NORMAL_M) ? t.statusbar : |
|
|
|
((t.mode_b & MODE_MASK) == NORMAL_MODE) ? t.statusbar : |
|
|
|
t.search_buffer.c |
|
|
|
t.search_buffer.c |
|
|
|
); |
|
|
|
); |
|
|
|
/* move back to the cursor position */ |
|
|
|
/* move back to the cursor position */ |
|
|
@ -414,7 +414,7 @@ void fileOpen (char *filename) |
|
|
|
void cursorMove (int a) |
|
|
|
void cursorMove (int a) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (a) { |
|
|
|
switch (a) { |
|
|
|
case (KEY_LEFT): |
|
|
|
case (KEY_MOVE_LEFT): |
|
|
|
if (t.cur.x <= 0) { |
|
|
|
if (t.cur.x <= 0) { |
|
|
|
if (t.cur.y) { |
|
|
|
if (t.cur.y) { |
|
|
|
t.cur.y--; |
|
|
|
t.cur.y--; |
|
|
@ -428,7 +428,7 @@ void cursorMove (int a) |
|
|
|
t.cur.x--; |
|
|
|
t.cur.x--; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_RIGHT): |
|
|
|
case (KEY_MOVE_RIGHT): |
|
|
|
if (t.cur.x >= rows.rw[t.cur.y].size) { |
|
|
|
if (t.cur.x >= rows.rw[t.cur.y].size) { |
|
|
|
if (t.cur.y < rows.rownum - 1) { |
|
|
|
if (t.cur.y < rows.rownum - 1) { |
|
|
|
t.cur.y++; |
|
|
|
t.cur.y++; |
|
|
@ -442,7 +442,7 @@ void cursorMove (int a) |
|
|
|
t.cur.x++; |
|
|
|
t.cur.x++; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_UP): |
|
|
|
case (KEY_MOVE_UP): |
|
|
|
if (t.cur.y) { |
|
|
|
if (t.cur.y) { |
|
|
|
t.cur.y--; |
|
|
|
t.cur.y--; |
|
|
|
if (t.cur.x > rows.rw[t.cur.y].size) |
|
|
|
if (t.cur.x > rows.rw[t.cur.y].size) |
|
|
@ -450,7 +450,7 @@ void cursorMove (int a) |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case (KEY_DOWN): |
|
|
|
case (KEY_MOVE_DOWN): |
|
|
|
if (t.cur.y < rows.rownum - 1) { |
|
|
|
if (t.cur.y < rows.rownum - 1) { |
|
|
|
t.cur.y++; |
|
|
|
t.cur.y++; |
|
|
|
if (t.cur.x > rows.rw[t.cur.y].size) |
|
|
|
if (t.cur.x > rows.rw[t.cur.y].size) |
|
|
|