chore: MIsc comments.

This commit is contained in:
jmug
2026-10-26 09:17:34 -07:00
parent 1cf32775cf
commit 1fe8355928
+6 -1
View File
@@ -72,6 +72,8 @@ char editorReadKey() {
} }
int getCursorPosition(int *rows, int *cols) { 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) { if (write(STDOUT_FILENO, "\x1b[6n", 4) != 4) {
return -1; return -1;
} }
@@ -82,6 +84,7 @@ int getCursorPosition(int *rows, int *cols) {
while (i < sizeof(buf) - 1) { while (i < sizeof(buf) - 1) {
if (read(STDIN_FILENO, &buf[i], 1) != 1) if (read(STDIN_FILENO, &buf[i], 1) != 1)
break; break;
// `R` stands for "Cursor Position Report"
if (buf[i] == 'R') if (buf[i] == 'R')
break; break;
i++; i++;
@@ -102,6 +105,7 @@ int getWindowSize(int *rows, int *cols) {
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) { if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
// Fallback if ioctl can't query size: // Fallback if ioctl can't query size:
// Move cursor to the bottom right; // Move cursor to the bottom right;
// (`C` is cursor forward, `B` is cursor down)
if (write(STDOUT_FILENO, "\x1b[999C\x1b[999B", 12) != 12) { if (write(STDOUT_FILENO, "\x1b[999C\x1b[999B", 12) != 12) {
return -1; return -1;
} }
@@ -120,7 +124,8 @@ void editorDrawRows() {
for (int y = 0; y < E.screenrows; y++) { for (int y = 0; y < E.screenrows; y++) {
write(STDOUT_FILENO, "~", 1); 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) { if (y < E.screenrows - 1) {
write(STDOUT_FILENO, "\r\n", 2); write(STDOUT_FILENO, "\r\n", 2);
} }