Skip to content
Myr

Handle SIGWINCH signal to properly resize editor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Leandro Pereira · committed by antirez · parent c1a27fa · Browse files · 1 file+21 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−7 removed

  • other:+21 added−7 removed

1 file+21 added−7 removed

modified:kilo.c+21 added-7 removed
32 unmodified lines
33 */3435#define KILO_VERSION "0.0.1"3637#ifdef __GLIBC__38#define _POSIX_C_SOURCE 200809L39#endif4041#include <termios.h>42#include <stdlib.h>43#include <stdio.h>
6 unmodified lines
50#include <sys/time.h>51#include <unistd.h>52#include <stdarg.h>53#include <fcntl.h>54#include <signal.h>5556/* Syntax highlight types */57#define HL_NORMAL 058#define HL_NONPRINT 1
1187 unmodified lines
1246int editorFileWasModified(void) {1247 return E.dirty;1248}12491250void updateWindowSize(void) {1251 if (getWindowSize(STDIN_FILENO,STDOUT_FILENO,1252 &E.screenrows,&E.screencols) == -1) {1253 perror("Unable to query the screen for size (columns / rows)");1254 exit(1);1255 }1256 E.screenrows -= 2; /* Get room for status bar. */1257}12581259void handleSigWinCh(int unused __attribute__((unused))) {1260 updateWindowSize();1261 if (E.cy > E.screenrows) E.cy = E.screenrows - 1;1262 if (E.cx > E.screencols) E.cx = E.screencols - 1;1263 editorRefreshScreen();1264}12651266void initEditor(void) {1267 E.cx = 0;1268 E.cy = 0;1269 E.rowoff = 0;
2 unmodified lines
1272 E.row = NULL;1273 E.dirty = 0;1274 E.filename = NULL;1275 E.syntax = NULL;1257 if (getWindowSize(STDIN_FILENO,STDOUT_FILENO,1258 &E.screenrows,&E.screencols) == -1)1259 {1260 perror("Unable to query the screen for size (columns / rows)");1261 exit(1);1262 }1263 E.screenrows -= 2; /* Get room for status bar. */1276 updateWindowSize();1277 signal(SIGWINCH, handleSigWinCh);1278}12791280int main(int argc, char **argv) {1281 if (argc != 2) {
16 unmodified lines