added loading files
This commit is contained in:
+18
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user