summaryrefslogtreecommitdiff
path: root/src/host/Host.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/Host.zig')
-rw-r--r--src/host/Host.zig19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/host/Host.zig b/src/host/Host.zig
index 81a5dc8..92d1b55 100644
--- a/src/host/Host.zig
+++ b/src/host/Host.zig
@@ -67,6 +67,7 @@ canvas: [2]u32 = .{ 0, 0 },
cursor: abi.Cursor = .arrow,
quit: bool = false,
reloaded: bool = true,
+started: bool = true,
last_now: u64 = 0,
/// Saved after the next frame is drawn (scripts).
screenshot: ?[:0]const u8 = null,
@@ -223,6 +224,8 @@ pub fn update(self: *Host, events: []const abi.Event) void {
if (events.len > 0 and self.timeline.mode != .live and self.timeline.mode != .recording) self.input.now = events[events.len - 1].time;
self.input.events = events;
self.input.mode = self.timeline.mode;
+ self.input.started = self.started;
+ self.started = false;
const ctx = self.context();
self.sketch.update(&ctx, self.live().ptr);
self.input.events = &.{};
@@ -307,7 +310,7 @@ pub fn route(self: *Host, e: abi.Event) !void {
},
.key_down => {
const key = consoleKey(e) orelse return;
- if (self.console.edit(key, self.completions)) |line| self.runLine(line, e.time);
+ if (self.console.edit(key, self.completions)) |line| self.runLine(line, e.time) catch {};
return;
},
.key_up => return,
@@ -319,17 +322,19 @@ pub fn route(self: *Host, e: abi.Event) !void {
try self.pending.append(self.gpa, e);
}
-/// Runs a console line now, replaying whatever a seek asks for.
-pub fn runLine(self: *Host, line: []const u8, now: u64) void {
+/// Runs a console line now, replaying whatever a seek asks for. An error is
+/// printed to the console, and returned for scripts to fail on.
+pub fn runLine(self: *Host, line: []const u8, now: u64) !void {
const replay = self.console.execute(self, line, now) catch |err| {
- self.console.print("{t}. Type help for usage.", .{err});
- return;
+ // The sketch has printed its own error already.
+ if (err != error.CommandFailed) self.console.print("{t}. Type help for usage.", .{err});
+ return err;
};
if (self.timeline.mode == .paused) self.update(replay);
}
-/// Offers a line to the sketch; false if it did not take it.
-pub fn forward(self: *Host, _: *Console, line: []const u8, now: u64) bool {
+/// Offers a line to the sketch.
+pub fn forward(self: *Host, _: *Console, line: []const u8, now: u64) abi.Outcome {
self.input.now = now;
const ctx = self.context();
return self.sketch.command(&ctx, self.live().ptr, self.session.bytes.ptr, &line);