From 1fe8355928b1cdb97e64ed89d6a13de1d1b0a9e5 Mon Sep 17 00:00:00 2001 From: jmug Date: Mon, 26 Oct 2026 09:17:34 -0700 Subject: [PATCH] chore: MIsc comments. --- kilo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kilo.c b/kilo.c index d3ae504..4a5ba08 100644 --- a/kilo.c +++ b/kilo.c @@ -72,6 +72,8 @@ char editorReadKey() { } int getCursorPosition(int *rows, int *cols) { + // `n` is the "Device Status Report" command, the argument `6` + // asks for the active position. if (write(STDOUT_FILENO, "\x1b[6n", 4) != 4) { return -1; } @@ -82,6 +84,7 @@ int getCursorPosition(int *rows, int *cols) { while (i < sizeof(buf) - 1) { if (read(STDIN_FILENO, &buf[i], 1) != 1) break; + // `R` stands for "Cursor Position Report" if (buf[i] == 'R') break; i++; @@ -102,6 +105,7 @@ int getWindowSize(int *rows, int *cols) { if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) { // Fallback if ioctl can't query size: // Move cursor to the bottom right; + // (`C` is cursor forward, `B` is cursor down) if (write(STDOUT_FILENO, "\x1b[999C\x1b[999B", 12) != 12) { return -1; } @@ -120,7 +124,8 @@ void editorDrawRows() { for (int y = 0; y < E.screenrows; y++) { write(STDOUT_FILENO, "~", 1); - // Don't scroll on the last line. + // No new line on the last line, the terminal scrolls past the + // first line otherwise. if (y < E.screenrows - 1) { write(STDOUT_FILENO, "\r\n", 2); }