authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-10-04 17:06:17 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-10-04 17:06:17 -07:00
log3e78c04989f399bea229645ee7734b2a5d8be102
tree2f7e7e1999ca837963898e26a809f7f65b99de69
parent47125b3d059731a9341ba078e2ae7bf524ffa444

improve perf of generate script runner

cursor now stays on the same line and only goes left to right

1 files changed, 8 insertions(+), 4 deletions(-)

scripts/_common.zig+8-4
...@@ -49,12 +49,15 @@ pub fn Main(comptime T: type) type {...@@ -49,12 +49,15 @@ pub fn Main(comptime T: type) type {
49 const r = req.reader();49 const r = req.reader();
5050
51 var line_num: usize = 1;51 var line_num: usize = 1;
52 std.debug.print("\n", .{});52 // std.debug.print("\n", .{});
5353
54 var arena = std.heap.ArenaAllocator.init(alloc);54 var arena = std.heap.ArenaAllocator.init(alloc);
55 defer arena.deinit();55 defer arena.deinit();
56 while (true) {56 while (true) {
57 const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |e| if (e == error.EndOfStream) break else return e;57 const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |err| switch (err) {
58 error.EndOfStream => break,
59 else => |e| return e,
60 };
58 defer alloc.free(line);61 defer alloc.free(line);
5962
60 if (line.len == 0) {63 if (line.len == 0) {
...@@ -66,11 +69,12 @@ pub fn Main(comptime T: type) type {...@@ -66,11 +69,12 @@ pub fn Main(comptime T: type) type {
6669
67 try T.exec(arena.allocator(), line, w);70 try T.exec(arena.allocator(), line, w);
6871
69 std.debug.print("{s}", .{ansi.csi.CursorUp(1)});72 std.debug.print("{s}", .{ansi.csi.CursorHorzAbs(1)});
70 std.debug.print("{s}", .{ansi.csi.EraseInLine(0)});73 std.debug.print("{s}", .{ansi.csi.EraseInLine(0)});
71 std.debug.print("{d}\n", .{line_num});74 std.debug.print("{d}", .{line_num});
72 line_num += 1;75 line_num += 1;
73 }76 }
77 std.debug.print("\n", .{});
74 try w.writeAll(T.dest_footer);78 try w.writeAll(T.dest_footer);
75 try bufw.flush();79 try bufw.flush();
76 }80 }