summaryrefslogtreecommitdiff
path: root/core/Kind.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Kind.zig')
-rw-r--r--core/Kind.zig55
1 files changed, 41 insertions, 14 deletions
diff --git a/core/Kind.zig b/core/Kind.zig
index 4e1aa469..e220ead7 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -137,7 +137,7 @@ pub const Slot = struct {
// jobs' inputs, its file's hash, a placeholder's record), and what
// a frame makes (the thumb, the pointer, whether one was drawn: a
// view's, never a step's).
- .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used" },
+ .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used", "drawn_from", "size" },
};
/// Its kind's code here; null in a placeholder (`live` false: its kind
/// not in the registry, its record kept for the day it comes) or a
@@ -215,6 +215,13 @@ pub const Slot = struct {
/// A client's join: its plain kind's file, until the pane is opened
/// from it (dump.plainHere).
file: ?[]u8 = null,
+ /// This process's draws made before it (`drawn` then): an answer to
+ /// one of them is another slot's, of a pane that showed something
+ /// else (a picker's preview of the row before), and is dropped.
+ drawn_from: u32 = 0,
+ /// Its file's bytes, as a picker's line naming it says them until its
+ /// kind's picture is drawn (Pick.preview).
+ size: u64 = 0,
/// Debug: the kind's allocations, which paint must leave as they are.
/// The slot's allocator's, as the slot is: a client's rollback puts
/// the list back with the slot that holds it (on the page allocator,
@@ -259,16 +266,12 @@ fn caps(p: *const Pardes, s: *const Slot) Caps {
/// word opened) from `bytes`: made whatever the kind says, with what it
/// refused in `slot.refused` for the caller to say.
pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) !*Pane {
- const e = &p.kinds.kinds[k];
- // A plain kind's slot and block are the core's (a client's epoch).
- const gpa = if (e.caps.plain) p.gpa else p.image_gpa;
- const s = try gpa.create(Slot);
- s.* = .{ .ops = p.kinds.ops[k], .live = true, .gpa = gpa, .arena = .init(gpa), .version = e.version, .gen = e.gen, .name = e.name };
+ const s = try newSlot(p, k, path orelse "");
errdefer {
+ const gpa = s.gpa;
s.free();
gpa.destroy(s);
}
- s.path = try gpa.dupe(u8, path orelse "");
const pane = try p.newDocPane(id);
pane.addon = s;
_ = reopen(p, id, s, bytes);
@@ -278,6 +281,23 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8)
return pane;
}
+/// A slot of kind `k` for `path`, its kind's state not made yet (`reopen`
+/// makes it): a pane's, or a picker's preview's in the pane it lands in
+/// (Pick.preview), that pane's own text set aside meanwhile.
+pub fn newSlot(p: *Pardes, k: u8, path: []const u8) !*Slot {
+ const e = &p.kinds.kinds[k];
+ // A plain kind's slot and block are the core's (a client's epoch).
+ const gpa = if (e.caps.plain) p.gpa else p.image_gpa;
+ const s = try gpa.create(Slot);
+ s.* = .{ .ops = p.kinds.ops[k], .live = true, .gpa = gpa, .arena = .init(gpa), .version = e.version, .gen = e.gen, .name = e.name, .drawn_from = drawn };
+ errdefer {
+ s.free();
+ gpa.destroy(s);
+ }
+ s.path = try gpa.dupe(u8, path);
+ return s;
+}
+
/// `open` of the file at `path`, read here (a file that cannot be read
/// is no bytes: its kind may refuse it). The slot stays ours across the
/// read: another request may make a pane meanwhile.
@@ -418,9 +438,10 @@ pub fn close(p: *Pardes, pane: *Pane) void {
/// The pane's body painted over the `cols` x `rows` cells at (x, y):
/// its cells into `s`, its placements after the frame's others. A pane
/// whose kind has no code here, or a placeholder, says why in a line.
-pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pane, id: usize, x: u16, y: u16, cols: u16, rows: u16) void {
- const slot = pane.addon orelse return;
- if (cols == 0 or rows == 0) return;
+/// False when its kind painted nothing (its picture not drawn yet).
+pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pane, id: usize, x: u16, y: u16, cols: u16, rows: u16) bool {
+ const slot = pane.addon orelse return true;
+ if (cols == 0 or rows == 0) return true;
const th = p.theme();
const fg: surface.Color = if (th.fg) |f| .{ .rgb = f } else .default;
const bg: surface.Color = if (th.bg) |b| .{ .rgb = b } else .default;
@@ -431,17 +452,17 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
const why = if (caps(p, slot).plain) "it is not in its addons nor the session's library at its path here, or it broke its promise here" else "its state is not plain (PA_PLAIN), so it runs in the session alone";
var line: [200]u8 = undefined;
_ = s.print(x, y, cols, std.fmt.bufPrint(&line, "addon {s} {d} does not run in this client: {s}", .{ slot.nameOf(), slot.version, why }) catch &line, .{ .fg = fg, .bg = bg });
- return;
+ return true;
} else if (slot.ops == null) {
var line: [160]u8 = undefined;
const why = if (slot.refused.len > 0) slot.refused.slice() else "Addon load <path>";
// Its kind here, it waits for its file (`<path> is not here`).
const text = if (p.kinds.byName(slot.nameOf()) != null) why else std.fmt.bufPrint(&line, "addon {s} {d} is not loaded: {s}", .{ slot.nameOf(), slot.version, why }) catch &line;
_ = s.print(x, y, cols, text, .{ .fg = fg, .bg = bg });
- return;
+ return true;
} else for (0..8) |_| {
if (ready.items.len > 0) deliver(p, slot, pane, id);
- frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return);
+ frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return true);
// No workers here (a test's, a bench's core): a draw that paint
// asked was done at once, and is this frame's, painted again.
if (drawer != null) break;
@@ -450,9 +471,11 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
} else break;
}
if (frame.gpu.len != 0) s.gpu_frames[id] = .{ .bytes = frame.gpu, .serial = pane.serial, .dst = .{ .x = x, .y = y, .w = cols, .h = rows } };
+ var painted = frame.gpu.len != 0 or frame.n > 0;
for (0..@min(rows, frame.rows)) |r| for (0..@min(cols, frame.cols)) |col| {
const cell = &frame.cells[r * frame.cols + col];
if (cell.flags & c.PA_PAINTED == 0) continue;
+ painted = true;
const len = @min(cell.len, 7);
s.set(x + @as(u16, @intCast(col)), y + @as(u16, @intCast(r)), if (len == 0) " " else cell.text[0..len], styleOf(cell, fg, bg));
};
@@ -471,6 +494,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
.art = slot.art,
});
}
+ return painted;
}
/// A frame of a kind's pane: its cells, `cols` a row, and its placements.
@@ -1012,6 +1036,9 @@ const Call = struct {
return o;
};
const p = cl.p orelse return o;
+ // A picker's preview shows its file and does nothing more: what its
+ // kind says, looks at or runs meanwhile is dropped (Pick.showKind).
+ if (pardes.Pick.previewing(p, cl.id)) return o;
if (o.said.len > 0) if (o.err) p.reportFailure(cl.id, o.said) else p.setMessage(.at(cl.id), o.said);
if (o.pane_name.len > 0) textPane(p, cl.id, cl.slot, o.pane_name, o.pane_text);
if (o.look.len > 0) @import("look.zig").lookAt(p, cl.id, o.look);
@@ -1289,7 +1316,7 @@ fn deliver(p: *const Pardes, slot: *Slot, pane: *const Pane, id: usize) void {
}
_ = ready.orderedRemove(i);
defer j.drop();
- if (pane.serial != j.serial or slot.gen != j.gen or slot.ops != j.ops) continue;
+ if (pane.serial != j.serial or slot.gen != j.gen or slot.ops != j.ops or j.token & ~c.PA_DRAWN <= slot.drawn_from) continue;
var cl: Call = .{ .p = null, .id = id, .slot = slot, .quiet = true, .core = p };
const prev = cl.begin("job_done");
const before = if (checked) usedHash(slot);