aboutsummaryrefslogtreecommitdiff
path: root/src/tui.zig
diff options
context:
space:
mode:
authorJulien Dessaux2022-12-04 04:06:47 +0100
committerJulien Dessaux2022-12-04 04:06:47 +0100
commitb373cbffa11f5f1f86f15f0be29b21993b42a5d7 (patch)
treebab595392417cab23148ba46994d3607ca54cebc /src/tui.zig
parentBegan writing a debugging tui (diff)
downloadzigfunge98-b373cbffa11f5f1f86f15f0be29b21993b42a5d7.tar.gz
zigfunge98-b373cbffa11f5f1f86f15f0be29b21993b42a5d7.tar.bz2
zigfunge98-b373cbffa11f5f1f86f15f0be29b21993b42a5d7.zip
Improved tui debugger
Diffstat (limited to '')
-rw-r--r--src/tui.zig46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/tui.zig b/src/tui.zig
index 2867a71..8d60bce 100644
--- a/src/tui.zig
+++ b/src/tui.zig
@@ -64,6 +64,12 @@ pub fn main() anyerror!void {
break;
} else if (in.eqlDescription("s")) {
if (try intp.step(&ioContext)) |code| {
+ try term.cook();
+ term.deinit();
+ intp.deinit();
+ file.close();
+ std.process.argsFree(gpa.allocator(), args);
+ std.debug.assert(!gpa.deinit());
std.os.exit(@intCast(u8, code));
}
try render();
@@ -89,8 +95,6 @@ fn render() !void {
return;
}
- const pointer = intp.getPointer().getInfo();
-
try rc.moveCursorTo(0, 0);
var filename = rc.restrictedPaddingWriter(term.width);
try filename.writer().print("{s} | steps:{d}", .{ args[1], 0 });
@@ -99,38 +103,48 @@ fn render() !void {
try rc.setAttribute(.{ .fg = .green, .reverse = true });
var stack = rc.restrictedPaddingWriter(16);
try stack.writer().writeAll("---- Stack ----");
+ try rc.setAttribute(.{ .fg = .green, .reverse = false });
+ var n: usize = 0;
+ while (n < intp.pointer.ss.toss.data.items.len) : (n += 1) {
+ try rc.moveCursorTo(3 + n, 0);
+ var s = rc.restrictedPaddingWriter(16);
+ const v = intp.pointer.ss.toss.data.items[n];
+ if (v >= 32 and v < 127) {
+ try s.writer().print("{c} - {d}", .{ @intCast(u8, v), v });
+ } else {
+ try s.writer().print("{d}", .{v});
+ }
+ }
try rc.moveCursorTo(2, 18);
try rc.setAttribute(.{ .fg = .blue, .reverse = true });
var fieldTitle = rc.restrictedPaddingWriter(term.width - 17);
- const size = intp.getField().getSize();
+ const size = intp.field.getSize();
try fieldTitle.writer().print("Funge field | top left corner:({d},{d}) size:{d}x{d}", .{ size[0], size[1], size[2], size[3] });
try fieldTitle.pad();
try rc.setAttribute(.{ .fg = .blue, .reverse = false });
var y: usize = 0; // TODO negative lines
while (y < @min(@intCast(usize, size[3]), term.height - 3)) : (y += 1) {
var field = rc.restrictedPaddingWriter(term.width - 17);
- const line = intp.getField().getLine(y);
- const data = line.getData();
+ const line = intp.field.lines.items[y];
var x: usize = 0;
- if (line.getX() >= 0) {
- try rc.moveCursorTo(y + 3, 18 + @intCast(usize, line.getX()));
+ if (line.x >= 0) {
+ try rc.moveCursorTo(y + 3, 18 + @intCast(usize, line.x));
} else {
try rc.moveCursorTo(y + 3, 18); // TODO negative columns
}
- while (x < @min(data.items.len, term.width - 18)) : (x += 1) {
- if (x == pointer.x and y == pointer.y) {
- try rc.setAttribute(.{ .fg = .magenta, .reverse = true });
- }
- if (x == pointer.x + pointer.dx and y == pointer.y + pointer.dy) { // TODO optmize that?
- try rc.setAttribute(.{ .fg = .magenta, .reverse = false });
+ while (x < @min(line.data.items.len, term.width - 18)) : (x += 1) {
+ var reset = false;
+ if (x + @intCast(usize, line.x) == intp.pointer.x and y == intp.pointer.y) { // TODO negatives
+ try rc.setAttribute(.{ .fg = .red, .reverse = true });
+ reset = true;
}
- if (data.items[x] >= 32 and data.items[x] < 127) {
- try field.writer().print("{c}", .{@intCast(u8, data.items[x])});
+ if (line.data.items[x] >= 32 and line.data.items[x] < 127) {
+ try field.writer().print("{c}", .{@intCast(u8, line.data.items[x])});
} else {
try field.writer().writeAll("®");
}
- if (x == pointer.x and y == pointer.y or x == pointer.x + pointer.dx and y == pointer.y + pointer.dy) {
+ if (reset) {
try rc.setAttribute(.{ .fg = .blue, .reverse = false });
}
}