more configuration options

master
Alessandro Mauri 5 years ago
parent 91e6e7fd28
commit 2d35c0b522
  1. 1
      .gitignore
  2. 12
      src/config.h
  3. 44
      src/ste.c

1
.gitignore vendored

@ -1,3 +1,4 @@
ste ste
.sconsign.dblite .sconsign.dblite
src/*.o src/*.o
src/#ste.c#

@ -3,6 +3,16 @@
#define TABSIZE 4 // Tab size as used in render #define TABSIZE 4 // Tab size as used in render
#define MAX_LINE 1024 // maximum line length on screen #define MAX_LINE 1024 // maximum line length on screen
#define PGK_DELTA 15 #define PGK_DELTA 15 // Step of jump
#define KEY_JUMP_UP KEY_PPAGE
#define KEY_JUMP_DOWN KEY_NPAGE
#define KEY_ROW_BEG KEY_HOME
#define KEY_ROW_END KEY_END
#define KEY_MOVE_LEFT KEY_LEFT
#define KEY_MOVE_RIGHT KEY_RIGHT
#define KEY_MOVE_UP KEY_UP
#define KEY_MOVE_DOWN KEY_DOWN
#define KEY_FILE_FIND CTRL('f')
#endif #endif

@ -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)

Loading…
Cancel
Save