Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
+19
-29
@@ -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,33 +23,14 @@ int open_editor() {
|
||||
int max_y, max_x;
|
||||
getmaxyx(stdscr, max_y, max_x);
|
||||
|
||||
|
||||
FILE* file = fopen("somecode.c", "r");
|
||||
if (file == NULL) {
|
||||
endwin();
|
||||
printf("Failed to open file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
String_t text = str_new();
|
||||
|
||||
// read from file char by char
|
||||
|
||||
while (true) {
|
||||
char line[1024];
|
||||
if (fgets(line, 1024, file) == NULL) {
|
||||
break;
|
||||
}
|
||||
String_t new_text = str_from_chars(line);
|
||||
text = str_merge(&text, &new_text);
|
||||
str_dealloc(&new_text);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
Editor editor = editor_from(text);
|
||||
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();
|
||||
@@ -102,8 +84,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