88 lines
2.6 KiB
C
88 lines
2.6 KiB
C
#include <ncurses.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "editor.h"
|
|
|
|
void help() {
|
|
printf("Usage:\n");
|
|
printf(" cmd open <path/to/file> // opens the specified file\n");
|
|
printf(" cmd rm <path/to/file> // deletes the specified file\n");
|
|
printf(" cmd new <path/to/file> // creates a new empty file at the specified path\n");
|
|
printf(" cmd mv <path/to/file> <new/path> // moves the specified file to the new path\n");
|
|
printf(" cmd cp <path/to/file> <new/path> // copies the specified file to the new path\n");
|
|
printf(" cmd len <path/to/file> // returns the length of the specified file\n");
|
|
printf(" cmd log // prints a list of all changes made to the file\n");
|
|
}
|
|
|
|
int open_editor() {
|
|
initscr();
|
|
raw();
|
|
noecho();
|
|
keypad(stdscr, true);
|
|
int max_y, max_x;
|
|
getmaxyx(stdscr, max_y, max_x);
|
|
|
|
move(0, 0);
|
|
|
|
Editor editor = editor_from("this is some text to edit\nthis is the second line\nand this is the third lol");
|
|
|
|
fprintf(stderr, "%d %d %d %d", editor.lines, editor.screen_line, editor.screen_col, editor.editmode);
|
|
|
|
while (true) {
|
|
refresh();
|
|
int c = getch();
|
|
if (editor.editmode == true) {
|
|
switch (c) {
|
|
case 27:
|
|
editor.editmode = false;
|
|
break;
|
|
case KEY_BACKSPACE:
|
|
delchar(&editor);
|
|
move_cursor(&editor, -1, 0);
|
|
break;
|
|
case KEY_DC:
|
|
delchar(&editor);
|
|
break;
|
|
case KEY_ENTER:
|
|
//TODO: next line
|
|
break;
|
|
case KEY_UP:
|
|
move_cursor(&editor, 0, -1);
|
|
break;
|
|
case KEY_DOWN:
|
|
move_cursor(&editor, 0, 1);
|
|
break;
|
|
case KEY_LEFT:
|
|
move_cursor(&editor, -1, 0);
|
|
break;
|
|
case KEY_RIGHT:
|
|
move_cursor(&editor, 1, 0);
|
|
break;
|
|
default:
|
|
addchar(&editor, c);
|
|
break;
|
|
}
|
|
} else {
|
|
switch (c) {
|
|
case 'q':
|
|
endwin();
|
|
return 0;
|
|
case 'i':
|
|
editor.editmode = true;
|
|
break;
|
|
case 'w':
|
|
// TODO: write function to save the data to a file
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
open_editor();
|
|
return 0;
|
|
}
|
|
|