started C implementation, created custom library for handling strings

This commit is contained in:
FantasyPvP
2024-11-02 22:39:16 +00:00
parent 3d3eeb142f
commit 83a71ae0a1
10 changed files with 488 additions and 30 deletions
+54 -11
View File
@@ -1,17 +1,7 @@
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
typedef struct {
int file_line;
int file_col;
int buff_line;
int buff_col;
int editmode;
} EditorData;
#include "editor.h"
void help() {
printf("Usage:\n");
@@ -23,3 +13,56 @@ void help() {
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 = new_editor();
while (true) {
refresh();
int c = getch();
if (editor.editmode) {
switch (c) {
case 27:
editor.editmode = false;
break;
case KEY_BACKSPACE:
delchar(&editor);
break;
case KEY_ENTER:
editor.editmode = false;
break;
default:
addchar(&editor, c);
break;
}
} else {
switch (c) {
case 'q':
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;
}