pub fn abAppend(ab: *abuf, s: []const u8) !void {
if (ab.b) |buffer| {
const new_buff = try std.heap.c_allocator.realloc(buffer, ab.len + s.len);
@memcpy(new_buff[ab.len..], s);
ab.b = new_buff;
ab.len = ab.len + s.len;
}
}
this gives nothing it ab.b is empty
const abuf = struct { b: ?[]u8, len: usize };
const ABUF_INIT = abuf{
.b = null,
.len = 0,
};
pub fn editorRefreshScreen() !void {
var ab = ABUF_INIT;
try abAppend(&ab, "\x1b[2J");
try abAppend(&ab, "\x1b[2H");
try editorDrawRows(&ab);
try abAppend(&ab, "\x1b[H");
if (ab.b) |buffer| {
_ = c.write(std.io.getStdOut().handle, buffer.ptr, ab.len);
}
try abFree(&ab);
}
pub fn main() !void {
defer disableRawMode();
enableRawMode();
try initEditor();
while (true) {
editorRefreshScreen() catch {
std.debug.print("editor refresh screen", .{});
break;
};
editorProcessKeyPress() catch {
break;
};
}
}
anybody help me to do it correct way