fuNote/fn.c
2018-10-19 13:24:58 +02:00

83 lines
1.4 KiB
C

#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#define _GNU_SOURCE
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include "fn.h"
#include "terminal.h"
#include "output.h"
#include "row.h"
#include "hl.h"
#include "search.h"
#include "file.h"
#include "input.h"
// TODO: Put this somewhere else?
void windowResizeCallback(int signum);
void initEditor();
void windowResizeCallback(int signum) {
if (signum != SIGWINCH) {
return;
}
if (setWindowSize(&E.screenrows, &E.screencols) == -1) {
die("setWindowSize");
}
E.screenrows -= 2;
editorRefreshScreen();
}
void initEditor() {
E.cx = 0;
E.cy = 0;
E.rx = 0;
E.rowoff = 0;
E.coloff = 0;
E.numrows = 0;
E.row = NULL;
E.dirty = 0;
E.filename = NULL;
E.statusmsg[0] = '\0';
E.statusmsg_time = 0;
E.syntax = NULL;
if (setWindowSize(&E.screenrows, &E.screencols) == -1) {
die("setWindowSize");
}
E.screenrows -= 2;
}
int main(int argc, char *argv[]) {
enableRawMode();
initEditor();
if (argc >= 2) {
editorOpen(argv[1]);
}
editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = Quit | Ctrl-F = find");
signal(SIGWINCH, windowResizeCallback);
while (1) {
editorRefreshScreen();
editorProcessKeypress();
}
return 0;
}