diff --git a/fn b/fn index 3982dfe..957b745 100755 Binary files a/fn and b/fn differ diff --git a/fn.c b/fn.c index 526728a..1037cff 100644 --- a/fn.c +++ b/fn.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "fn.h" #include "terminal.h" @@ -847,6 +848,18 @@ void editorProcessKeypress() { /*** init ***/ +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; @@ -861,12 +874,14 @@ void initEditor() { E.statusmsg_time = 0; E.syntax = NULL; - if (getWindowSize(&E.screenrows, &E.screencols) == -1) - die("getWindowSize"); + if (setWindowSize(&E.screenrows, &E.screencols) == -1) { + die("setWindowSize"); + } E.screenrows -= 2; } int main(int argc, char *argv[]) { + enableRawMode(); initEditor(); if (argc >= 2) { @@ -875,6 +890,8 @@ int main(int argc, char *argv[]) { editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = Quit | Ctrl-F = find"); + signal(SIGWINCH, windowResizeCallback); + while (1) { editorRefreshScreen(); editorProcessKeypress(); diff --git a/terminal.c b/terminal.c index 318bacf..3e2ed31 100644 --- a/terminal.c +++ b/terminal.c @@ -107,7 +107,7 @@ int getCursorPosition(int *rows, int *cols) { return 0; } -int getWindowSize(int *rows, int *cols) { +int setWindowSize(int *rows, int *cols) { struct winsize ws; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) { @@ -123,3 +123,4 @@ int getWindowSize(int *rows, int *cols) { return 0; } } + diff --git a/terminal.h b/terminal.h index 05a5cb0..6131349 100644 --- a/terminal.h +++ b/terminal.h @@ -8,6 +8,6 @@ void enableRawMode(); int editorReadKey(); int getCursorPosition(int *rows, int *cols); -int getWindowSize(int *rows, int *cols); +int setWindowSize(int *rows, int *cols); #endif