summaryrefslogtreecommitdiff
path: root/src/Messages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
committerGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
commita479792a1ab2b593642d7f648194bfa23ce01dba (patch)
tree96ddee7d879a9084daa07db43b0b7910b072a785 /src/Messages.zig
parente179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff)
parent4c761893e5b3fdae422622cfa02104ab36633045 (diff)
downloadpardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz
pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/Messages.zig')
-rw-r--r--src/Messages.zig85
1 files changed, 58 insertions, 27 deletions
diff --git a/src/Messages.zig b/src/Messages.zig
index cb52907a..371ed168 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -31,6 +31,7 @@ len: usize = 0,
pub const LoggedMessage = struct {
pub const cap = 256;
+ pub const replica = .{ .len = .{.{ "text", "len" }} };
text: [cap]u8 = undefined,
len: u16 = 0,
/// The serial of the pane that said it, or 0 for none in particular. A
@@ -117,6 +118,24 @@ pub const Message = struct {
};
extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm;
+ fn timeOfDay() [8]u8 {
+ var clock: [8]u8 = "--:--:--".*;
+ const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false;
+ if (notime) return clock;
+ var ts: libc.timespec = undefined;
+ _ = libc.clock_gettime(.REALTIME, &ts);
+ const secs: libc.time_t = ts.sec;
+ var tm: Tm = undefined;
+ if (localtime_r(&secs, &tm) != null) {
+ _ = std.fmt.bufPrint(&clock, "{d:0>2}:{d:0>2}:{d:0>2}", .{
+ @as(u32, @intCast(tm.hour)),
+ @as(u32, @intCast(tm.min)),
+ @as(u32, @intCast(tm.sec)),
+ }) catch {};
+ }
+ return clock;
+ }
+
pub fn body(text: []const u8) []const u8 {
if (text.len < 10) return text;
if (text[2] != ':' or text[5] != ':' or text[8] != ' ' or text[9] != ' ') return text;
@@ -127,21 +146,9 @@ pub const Message = struct {
}
pub fn stamp(buf: []u8, verb: []const u8, subject: []const u8) []const u8 {
- var clock: [8]u8 = "--:--:--".*;
- const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false;
- if (!notime) {
- var ts: libc.timespec = undefined;
- _ = libc.clock_gettime(.REALTIME, &ts);
- const secs: libc.time_t = ts.sec;
- var tm: Tm = undefined;
- if (localtime_r(&secs, &tm) != null) {
- _ = std.fmt.bufPrint(&clock, "{d:0>2}:{d:0>2}:{d:0>2}", .{
- @as(u32, @intCast(tm.hour)),
- @as(u32, @intCast(tm.min)),
- @as(u32, @intCast(tm.sec)),
- }) catch {};
- }
- }
+ // The time of day as the session that said it read it, in its
+ // zone: a replica's clock and TZ are its own (src/tape.zig).
+ const clock = pardes.tape.value(.clock, timeOfDay, .{});
const head = std.fmt.bufPrint(buf, "{s} {s} ", .{ &clock, verb }) catch return buf[0..0];
const room = buf.len - head.len;
const tail = if (subject.len <= room) subject else subject[subject.len - room ..];
@@ -153,10 +160,14 @@ pub const Message = struct {
/// A status updates the message line in place (a progress count does not
/// pile up); a message is an event, and stacks.
pub fn setStatus(p: *Pardes, id: usize, text: []const u8) void {
+ const taped = pardes.tape.enter(p, .{ .set_status = .{ .id = id, .text = text } });
+ defer pardes.tape.leave(p, taped);
showMessage(p, id, text, false);
}
pub fn setMessage(p: *Pardes, id: usize, text: []const u8) void {
+ const taped = pardes.tape.enter(p, .{ .set_message = .{ .id = id, .text = text } });
+ defer pardes.tape.leave(p, taped);
logMessage(p, id, text);
showMessage(p, id, text, true);
}
@@ -186,7 +197,9 @@ fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void {
const arrives = pane.msg_len == 0 or pane.msg_life.phase == .leaving;
for (text[0..n], pane.msg[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c;
pane.msg_len = @intCast(n);
- pane.msg_said_ms = nowMs();
+ // The clock when it was said (the session clock is the last pump's,
+ // and a 9P write after an idle hour would say it an hour ago).
+ pane.msg_said_ms = pardes.tape.value(.clock, nowMs, .{});
p.needs_frame = true;
if (arrives) {
pane.msg_life = .{ .phase = if (p.settings.message_animation and n > 0) .entering else .shown };
@@ -200,6 +213,15 @@ fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void {
}
}
+/// With no frontend attached no input dismisses a message, and a detached
+/// session's /screen and messages kept what was said an hour ago: each
+/// pane's lines go once its newest has been up `message_linger_ms`, on the
+/// clock, checked as the core is stepped (each event, and each pump after
+/// its wait, which a message wakes) -- not as a 9P request is served, since
+/// a read is answered while a step is out and must change nothing, nor by
+/// the host, whose call is no input a replay makes.
+/// ponytail: a pane's older lines go with its newest, not each on its own
+/// clock; the render pipeline's clock will give every line its own.
fn nowMs() i64 {
if (comptime !pardes.hosted) return 0;
var ts: std.c.timespec = undefined;
@@ -207,17 +229,10 @@ fn nowMs() i64 {
return @as(i64, ts.sec) * 1000 + @divTrunc(@as(i64, ts.nsec), 1_000_000);
}
-/// With no frontend attached no input dismisses a message, and a detached
-/// session's /screen and messages kept what was said an hour ago: each
-/// pane's lines go once its newest has been up `message_linger_ms`, on the
-/// clock, checked as the core is stepped and by the detached session's loop
-/// between steps -- not as a 9P request is served, since a read is answered
-/// while a step is out and must change nothing.
-/// ponytail: a pane's older lines go with its newest, not each on its own
-/// clock; the render pipeline's clock will give every line its own.
pub fn expireUnattended(p: *Pardes) void {
if (!p.unattended) return;
- const now = nowMs();
+ // The clock as the session that recorded read it (src/tape.zig).
+ const now = pardes.tape.value(.clock, nowMs, .{});
for (p.panes) |slot| {
const pane = slot orelse continue;
if (pane.msg_len == 0 and pane.msg_older_len == 0) continue;
@@ -453,6 +468,8 @@ pub fn dialReason(err: anyerror) ?[]const u8 {
}
pub fn reportError(p: *Pardes, id: usize, operation: []const u8, err: anyerror) void {
+ const taped = pardes.tape.enter(p, .{ .report_error = .{ .id = id, .operation = operation, .err = err } });
+ defer pardes.tape.leave(p, taped);
// Room for an operation naming the longest path and the reason after
// it: a shorter one cut the reason off (`Save /long…`), and the reason
// is what a failure is for. Where it must be shorter, the path gives.
@@ -575,6 +592,19 @@ test "an error reads as words and a failure is cut between them" {
/// so it does not paint under them, and the paint pass so it can stack
/// them instead of letting the last one win the row.
pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
+ collectBands(p, pane, r, id);
+ // Each band's chip at the right edge, as wide as its own text: a click
+ // finds it whether or not a frame has drawn it.
+ const tx = r.x + config.GUTTER;
+ const tw = r.w -| config.GUTTER;
+ var leader_buf: [16]u8 = undefined;
+ for (0..pane.notices.len) |i| {
+ const chip = noticeCols(p, noticeText(p, pane, i, &leader_buf), tw);
+ pane.notices.left[i] = if (chip == 0) std.math.maxInt(u16) else tx + tw - chip;
+ }
+}
+
+fn collectBands(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
pane.notices.len = 0;
if (r.w <= config.GUTTER or r.h <= pane.tag_rows) return;
// Oldest message line on top, so lines already up do not move when a
@@ -713,10 +743,11 @@ test "with no frontend attached a message goes once it has lingered, on the cloc
// Detached with nobody attached: past its linger it is gone, and the
// line above it with it.
p.unattended = true;
- // A read served meanwhile changes nothing; the session's loop expires.
+ // A read served meanwhile changes nothing; the session's step after its
+ // wait expires, not the host (whose call no replay makes).
_ = p.serveFs(.{ .tag = 1, .op = .read, .node = @backingInt(ctlfs.TopFile.index), .size = 64 });
try std.testing.expect(pane.msg_len > 0);
- expireUnattended(p);
+ try p.pump(.{});
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
// A fresh one stays until its linger is up.