fuNote/src/fn.c

70 lines
1.4 KiB
C
Raw Normal View History

2018-09-17 14:48:14 +02:00
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#define _GNU_SOURCE
#include <signal.h> // for signal, SIGWINCH
#include <stdio.h> // for NULL
2018-09-17 09:07:22 +02:00
#include "fn.h"
#include "file.h" // for editorOpen
#include "input.h" // for editorProcessKeypress
#include "output.h" // for editorRefreshScreen, editorSetStatusMessage
#include "terminal.h" // for die, setWindowSize, enableRawMode
// TODO: Put this somewhere else?
void windowResizeCallback(int signum);
void initEditor();
2018-10-09 10:29:14 +02:00
void windowResizeCallback(int signum) {
if (signum != SIGWINCH) {
return;
}
if (setWindowSize(&E.screenrows, &E.screencols) == -1) {
die("setWindowSize");
}
E.screenrows -= 2;
editorRefreshScreen();
}
2018-09-17 09:07:22 +02:00
void initEditor() {
E.cx = 0;
E.cy = 0;
2018-10-02 10:30:17 +02:00
E.rx = 0;
2018-09-21 17:05:22 +02:00
E.rowoff = 0;
2018-10-01 17:03:40 +02:00
E.coloff = 0;
2018-09-17 14:48:14 +02:00
E.numrows = 0;
2018-09-21 09:10:15 +02:00
E.row = NULL;
2018-10-05 11:59:27 +02:00
E.dirty = 0;
2018-10-02 10:30:17 +02:00
E.filename = NULL;
E.statusmsg[0] = '\0';
E.statusmsg_time = 0;
2018-10-16 16:59:23 +02:00
E.syntax = NULL;
if (setWindowSize(&E.screenrows, &E.screencols) == -1) {
die("setWindowSize");
}
2018-10-02 10:30:17 +02:00
E.screenrows -= 2;
2018-09-17 09:07:22 +02:00
}
2018-09-17 14:48:14 +02:00
int main(int argc, char *argv[]) {
2018-09-17 09:07:22 +02:00
enableRawMode();
initEditor();
2018-09-17 14:48:14 +02:00
if (argc >= 2) {
editorOpen(argv[1]);
}
2018-09-17 09:07:22 +02:00
2018-10-09 10:29:14 +02:00
editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = Quit | Ctrl-F = find");
2018-10-02 10:30:17 +02:00
signal(SIGWINCH, windowResizeCallback);
2018-09-17 09:07:22 +02:00
while (1) {
editorRefreshScreen();
editorProcessKeypress();
}
return 0;
}