Update screen when terminal window will be changed #2
This commit is contained in:
parent
6b2c3a00a5
commit
45c0f51cb3
4 changed files with 22 additions and 4 deletions
BIN
fn
BIN
fn
Binary file not shown.
21
fn.c
21
fn.c
|
@ -16,6 +16,7 @@
|
|||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue