main: print some stuff

This commit is contained in:
torque 2024-08-10 09:15:33 -07:00
parent 351b5ccf59
commit 33adcfc104
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -132,6 +132,7 @@ pub const RotInt = struct {
.get_position => |pos| {
self.current_posture = pos;
if (self.state == .rotator_connected) self.stateEvent(.rotator_ready);
self.draw() catch {};
},
.status => |code| if (code != .okay)
self.warn("rotctl error {s}", .{@tagName(code)}),
@ -162,6 +163,7 @@ pub const RotInt = struct {
.set_position => |pos| {
self.requested_posture = pos;
self.server.respond(self.loop, .okay);
self.draw() catch {};
},
.stop => self.server.respond(self.loop, .okay),
@ -174,44 +176,33 @@ pub const RotInt = struct {
}
fn draw(self: *RotInt) !void {
const Static = struct {
const lower_limit: u8 = 30;
const next_ms: u64 = 8;
var color_idx: u8 = lower_limit;
var dir: enum { up, down } = .up;
};
const style: vaxis.Style = .{
.fg = .{ .rgb = [_]u8{ Static.color_idx, Static.color_idx, Static.color_idx } },
};
const segment: vaxis.Segment = .{
.text = "yeah ok",
.style = style,
};
const win = self.vx.window();
win.clear();
const y_off = (win.height / 2) -| (6 / 2);
const x_off = (win.width / 2) -| (30 / 2);
const center = win.child(.{
.x_off = x_off + win.x_off,
.y_off = y_off + win.y_off,
.width = .{ .limit = 30 },
.height = .{ .limit = 6 },
.border = .{ .where = .all, .style = style },
});
_ = try center.printSegment(segment, .{ .wrap = .grapheme });
switch (Static.dir) {
.up => {
Static.color_idx += 1;
if (Static.color_idx == 255) Static.dir = .down;
},
.down => {
Static.color_idx -= 1;
if (Static.color_idx == Static.lower_limit) Static.dir = .up;
},
}
var lines: [3][128]u8 = undefined;
const offsets: vaxis.Segment = .{ .text = try std.fmt.bufPrint(
lines[0][0..],
"Offsets: Az: {d: >6.1}, El: {d: >6.1}",
.{ self.offsets.az, self.offsets.el },
) };
const requested: vaxis.Segment = .{ .text = try std.fmt.bufPrint(
lines[1][0..],
"Requested: Az: {d: >6.1}, El: {d: >6.1}",
.{ self.requested_posture.az, self.requested_posture.el },
) };
const current: vaxis.Segment = .{ .text = try std.fmt.bufPrint(
lines[2][0..],
"Current: Az: {d: >6.1}, El: {d: >6.1}",
.{ self.current_posture.az, self.current_posture.el },
) };
const center = vaxis.widgets.alignment.center(win, offsets.text.len, 1);
_ = try center.printSegment(offsets, .{});
const center_up = win.initChild(center.x_off, center.y_off + 1, .{ .limit = requested.text.len }, .{ .limit = 1 });
_ = try center_up.printSegment(requested, .{});
const center_down = win.initChild(center.x_off, center.y_off - 1, .{ .limit = current.text.len }, .{ .limit = 1 });
_ = try center_down.printSegment(current, .{});
try self.vx.render(self.termbuffer.writer().any());
try self.termbuffer.flush();
}
@ -300,6 +291,9 @@ fn eventCallback(
self.offsets.az += delta.az;
self.offsets.el += delta.el;
self.draw() catch {
self.warn("draw failure", .{});
};
},
.winsize => |ws| {
watcher.vx.resize(self.allocator, watcher.tty.anyWriter(), ws) catch