added loading files

This commit is contained in:
FantasyPvP
2024-11-08 10:36:07 +00:00
parent be32741af2
commit e7ecffa65a
8 changed files with 283 additions and 29 deletions
+18 -4
View File
@@ -1,6 +1,7 @@
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "editor.h"
void help() {
@@ -14,7 +15,7 @@ void help() {
printf(" cmd log // prints a list of all changes made to the file\n");
}
int open_editor() {
int open_editor(char* filename) {
initscr();
raw();
noecho();
@@ -22,9 +23,14 @@ int open_editor() {
int max_y, max_x;
getmaxyx(stdscr, max_y, max_x);
Editor editor = editor_from("this is some text to edit\nthis is the second line\nand this is the third lol");
move(0, 5);
Editor editor;
if (strcmp(filename, "") == 0) {
editor = new_editor();
} else {
editor = editor_from(str_from_file(fopen(filename, "r")));
}
while (true) {
refresh();
int c = getch();
@@ -79,8 +85,16 @@ int open_editor() {
}
}
int main() {
open_editor();
int main(int argc, char* argv[]) {
if (argc == 1) {
Editor e = new_editor();
open_editor("");
} else if (argc == 3) {
if (strcmp(argv[1], "open") == 0) {
fprintf(stderr, "starting editor openiing file %s", argv[2]);
open_editor(argv[2]);
}
}
return 0;
}