esc

Externally Scriptable Editor

git clone git://mccd.space/esc

commit 78e6111b107e649a141e18a93994c22961b5cf8a
parent 39948dc11e80109d111907a157901f39e6814cb7
Author: Marc Coquand <marc@coquand.email>
Date:   Tue, 24 Feb 2026 11:52:25 +0100

Fix cursor to use byte position

This works better with tools like grep.

Diffstat:
MREADME.md | 8+++++---
Mfuse_ipc.c | 23+++++++++--------------
2 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
@@ -2,6 +2,8 @@
 
 Esc (**E**xternally **Sc**riptable Editor) is an extensible text editor written in C with it's own renderer.
 
+Instead of having a plugin system, esc leverages Linux for changes. 
+
 ## Goals
 
 * Support image rendering
@@ -11,9 +13,9 @@ Esc (**E**xternally **Sc**riptable Editor) is an extensible text editor written 
 
 ## Dependencies
 
-- SDL3
-- Some menu set to `$MENU`, defaults to wmenu
-- Wayland
+* SDL3
+* Some menu set to `$MENU`, defaults to wmenu
+* Wayland
 
 ## Compiling
 
diff --git a/fuse_ipc.c b/fuse_ipc.c
@@ -183,8 +183,8 @@ static int op_getattr(const char *path, struct stat *st) {
 			VisualPos sp = editor_byte_to_visual_pos(
 			    ed, ed->selection_anchor);
 			st->st_size =
-			    snprintf(tmp, sizeof(tmp), "%d %d %d %d\n",
-				     cp.row, cp.col, sp.row, sp.col);
+			    snprintf(tmp, sizeof(tmp), "%d\n%d",
+				     ed->cursor_idx, ed->selection_anchor);
 		} else if (strcmp(path, "/buffer/0/body") == 0) {
 			st->st_size = (off_t)ed->text.len;
 		} else if (strcmp(path, "/buffer/0/path") == 0) {
@@ -322,12 +322,8 @@ static int op_read(const char *path, char *buf, size_t size, off_t offset,
 	if (strcmp(path, "/cursor") == 0) {
 		editor_lock(ed);
 		char tmp[64];
-		VisualPos cp =
-		    editor_byte_to_visual_pos(ed, ed->cursor_idx);
-		VisualPos sp =
-		    editor_byte_to_visual_pos(ed, ed->selection_anchor);
-		int n = snprintf(tmp, sizeof(tmp), "%d %d %d %d\n",
-				 cp.row, cp.col, sp.row, sp.col);
+		int n = snprintf(tmp, sizeof(tmp), "%d %d\n",
+				 ed->cursor_idx, ed->selection_anchor);
 		editor_unlock(ed);
 
 		if (offset >= (off_t)n)
@@ -474,18 +470,17 @@ static int op_release(const char *path, struct fuse_file_info *fi) {
 
 	} else if (strcmp(path, "/cursor") == 0 && wb->data && wb->len > 0) {
 		char *tmp = malloc(wb->len + 1);
-		int crow = 0, ccol = 0, srow = 0, scol = 0;
+		int cidx = 0, sidx = 0;
 		if (tmp) {
 			memcpy(tmp, wb->data, wb->len);
 			tmp[wb->len] = '\0';
-			sscanf(tmp, "%d %d %d %d", &crow, &ccol, &srow, &scol);
+			sscanf(tmp, "%d %d", &cidx, &sidx);
 			free(tmp);
 		}
 		editor_lock(ed);
-		ed->cursor_idx = editor_visual_pos_to_byte(
-		    ed, (VisualPos){crow, ccol});
-		ed->selection_anchor = editor_visual_pos_to_byte(
-		    ed, (VisualPos){srow, scol});
+		// XXX HANDLE OVERFLOW
+		ed->cursor_idx = cidx;
+		ed->selection_anchor = sidx;
 		editor_unlock(ed);
 		wake_render();
 	}