70 lines
1.4 KiB
C
70 lines
1.4 KiB
C
#define _DEFAULT_SOURCE
|
|
#define _BSD_SOURCE
|
|
#define _GNU_SOURCE
|
|
|
|
#include <signal.h> // for signal, SIGWINCH
|
|
#include <stdio.h> // for NULL
|
|
|
|
#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();
|
|
|
|
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;
|
|
}
|