nasmfm

sfm rewrite
git clone https://git.afify.dev/nasmfm.git
Log | Files | Refs | LICENSE

commit 33bd1a644eee0e0d3feb9e9dae562005f9d9194d
parent 0840e8d192a2cc5644e453a14c826807ef5ec28c
Author: afify <hassan@afify.dev>
Date:   Thu, 10 Mar 2022 16:50:38 +0300

[feat] add twrite

Diffstat:
Mnasmfm.c | 26++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/nasmfm.c b/nasmfm.c @@ -4,6 +4,7 @@ #include <ctype.h> #include <errno.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -147,20 +148,35 @@ editorReadKey() } return c; } -/*** input ***/ + +void +twrite(int x, int y, char *str, size_t len) +{ + if (x > term.rows || y > term.cols) + return; + char buf[term.cols]; + size_t full_buf; + + snprintf(buf, term.cols, "\x1b[%d;%df%s", x, y, str); + full_buf = strlen(buf); + write(STDOUT_FILENO, buf, full_buf); +} + void editorProcessKeypress() { char c = editorReadKey(); + char buf[50]; + snprintf(buf, sizeof(buf), "THIS IS LETTER %c [%ld]=>", c, sizeof(buf)); switch (c) { case 'q': write(STDOUT_FILENO, "\x1b[2J", 4); write(STDOUT_FILENO, "\x1b[H", 3); exit(0); break; - break; default: - printf("%d ('%c')\r\n", c, c); + twrite(10, 10, buf, strlen(buf)); + break; } } @@ -191,8 +207,10 @@ main(int argc, char *argv[]) { enableRawMode(); initEditor(); + write(STDOUT_FILENO, "\x1b[2J", 4); + write(STDOUT_FILENO, "\x1b[H", 3); while (1) { - editorRefreshScreen(); + //editorRefreshScreen(); editorProcessKeypress(); } return 0;