fuNote/fn.c

76 lines
1.5 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 <stdlib.h> // for exit
#include <stdio.h> // for NULL
#include <unistd.h> // for STDOUT_FILENO
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
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
}
void exitEditor() {
// Restore from raw mode and exit
write(STDOUT_FILENO, "\x1b[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3);
exit(0);
}
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
editorSetStatusMessage("Ctrl-C = Quit, Ctrl-S = save, 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();
}
exitEditor();
2018-09-17 09:07:22 +02:00
return 0;
}