╭ Markdown.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const ui = @import("../../ui.zig"); 3 const md = @import("../../markdown.zig"); 4 const Files = @import("Files.zig"); 5 const xit = @import("xit"); 6 const xitui = xit.xitui; 7 const wgt = xitui.widget; 8 const layout = xitui.layout; 9 const Key = xitui.input.Key; 10 const Grid = xitui.grid.Grid; 11 const Focus = xitui.focus.Focus; 12 const RichText = ui.widget.RichText; 13 14 // a rendered markdown file: one child per block, word-wrapped to the width. 15 // without `data` (a file outside any repo), repo-relative links aren't clickable. 16 pub const View = struct { 17 box: wgt.Box(ui.Widget), 18 // where focus rests off the links, covering the whole document; it's 19 // registered after the links so they win hit-testing 20 body: *Focus, 21 22 pub fn init(allocator: std.mem.Allocator, doc: md.Document, data: ?*const Files, file_path: []const u8, page_arena: *std.heap.ArenaAllocator) !View { 23 const builder: Builder = .{ 24 .allocator = allocator, 25 .data = data, 26 .dir = if (std.mem.lastIndexOfScalar(u8, file_path, '/')) |slash| file_path[0..slash] else "", 27 .page_arena = page_arena, 28 .fonts = !hasUncoveredHeading(doc.blocks), 29 }; 30 var box = try builder.blocksBox(doc.blocks, true); 31 errdefer box.deinit(allocator); 32 const body = try Focus.create(allocator, .container); 33 body.mode = .all; 34 box.getFocus().child_id = body.id; 35 return .{ .box = box, .body = body }; 36 } 37 38 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 39 self.box.deinit(allocator); 40 self.body.destroy(allocator); 41 } 42 43 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 44 self.clearGrid(); 45 try self.box.build(allocator, constraint, root_focus); 46 const grid = self.box.getGrid() orelse return; 47 try self.box.getFocus().addChild(allocator, self.body, grid.size, 0, 0); 48 } 49 50 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 51 _ = self; 52 _ = allocator; 53 _ = key; 54 _ = root_focus; 55 } 56 57 pub fn clearGrid(self: *View) void { 58 self.box.clearGrid(); 59 } 60 61 pub fn getGrid(self: View) ?Grid { 62 return self.box.getGrid(); 63 } 64 65 pub fn getFocus(self: *View) *Focus { 66 return self.box.getFocus(); 67 } 68 69 // whether `id` is the body or one of the links 70 pub fn owns(self: *View, id: usize) bool { 71 return self.box.getFocus().children.contains(id); 72 } 73 74 // focus the next or previous link in document order, scrolling it into 75 // view; from the body, start at the first link in view. stepping past 76 // either end returns to the body. 77 pub fn stepLink(self: *View, allocator: std.mem.Allocator, root_focus: *Focus, scroll: *wgt.Scroll(ui.Widget), forward: bool) !void { 78 var stops: std.ArrayList(usize) = .empty; 79 defer stops.deinit(allocator); 80 try collectStops(allocator, &self.box, self.box.getFocus(), &stops); 81 const children = self.box.getFocus().children; 82 83 const current = if (root_focus.grandchild_id) |id| std.mem.indexOfScalar(usize, stops.items, id) else null; 84 const target: ?usize = if (current) |c| 85 (if (forward) (if (c + 1 < stops.items.len) c + 1 else null) else (if (c > 0) c - 1 else null)) 86 else entry: { 87 const top: usize = @intCast(@max(scroll.y, 0)); 88 if (forward) { 89 for (stops.items, 0..) |id, i| { 90 if ((children.get(id) orelse unreachable).rect.y >= top) break :entry i; 91 } 92 break :entry null; 93 } 94 const bottom: usize = if (scroll.grid) |g| top + g.size.height - scroll.bar_h else std.math.maxInt(usize); 95 var i = stops.items.len; 96 while (i > 0) { 97 i -= 1; 98 if ((children.get(stops.items[i]) orelse unreachable).rect.y < bottom) break :entry i; 99 } 100 break :entry null; 101 }; 102 103 const id = stops.items[target orelse return root_focus.setFocus(self.body.id)]; 104 root_focus.setFocus(id); 105 const rect = (children.get(id) orelse unreachable).rect; 106 scroll.scrollToRect(.{ .x = @intCast(rect.x), .y = @intCast(rect.y), .size = rect.size }); 107 } 108 }; 109 110 // the focus ids of the laid-out links under `box`, in document order 111 fn collectStops(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), view_focus: *Focus, stops: *std.ArrayList(usize)) !void { 112 for (box.children.values()) |*child| switch (child.widget) { 113 .rich_text => |*rich_text| try addStops(allocator, rich_text, view_focus, stops), 114 .markdown_heading => |*heading| try addStops(allocator, &heading.text, view_focus, stops), 115 .markdown_gutter => |*gutter| try collectStops(allocator, &gutter.child, view_focus, stops), 116 .box => |*inner| try collectStops(allocator, inner, view_focus, stops), 117 else => {}, 118 }; 119 } 120 121 // each link's first piece is its stop 122 fn addStops(allocator: std.mem.Allocator, rich_text: *RichText, view_focus: *Focus, stops: *std.ArrayList(usize)) !void { 123 for (rich_text.link_focuses) |focuses| { 124 if (focuses.items.len > 0 and view_focus.children.contains(focuses.items[0].id)) try stops.append(allocator, focuses.items[0].id); 125 } 126 } 127 128 // turns blocks into widgets, resolving links against the viewed file. 129 const Builder = struct { 130 allocator: std.mem.Allocator, 131 data: ?*const Files, 132 // the viewed file's directory, which relative links resolve against 133 dir: []const u8, 134 page_arena: *std.heap.ArenaAllocator, 135 // whether headings may use the title fonts 136 fonts: bool, 137 138 // a vertical box of `blocks`, with a blank row between them when `gap` 139 fn blocksBox(b: Builder, blocks: []const md.Block, gap: bool) anyerror!wgt.Box(ui.Widget) { 140 var box = try wgt.Box(ui.Widget).init(b.allocator, .{ .border_style = null, .direction = .vert, .gap = @intFromBool(gap) }); 141 errdefer box.deinit(b.allocator); 142 for (blocks) |block| try b.addBlock(&box, block); 143 return box; 144 } 145 146 fn addBlock(b: Builder, box: *wgt.Box(ui.Widget), block: md.Block) !void { 147 const allocator = b.allocator; 148 switch (block) { 149 .heading => |heading| { 150 const spans = try b.runSpans(heading.inlines, .{ .bold = true }); 151 try put(allocator, box, .{ .markdown_heading = try Heading.init(allocator, b.page_arena, heading.level, spans, b.fonts) }); 152 }, 153 .paragraph => |inlines| try put(allocator, box, .{ .rich_text = try RichText.init(allocator, try b.runSpans(inlines, .{})) }), 154 .code => |lines| { 155 const text = try std.mem.join(b.page_arena.allocator(), "\n", lines); 156 try put(allocator, box, .{ .text_box = try wgt.TextBox.init(allocator, text, .{ .border_style = .single, .round_corners = true, .wrap_kind = .char }) }); 157 }, 158 .quote => |blocks| { 159 const gutter = gutter: { 160 var inner = try b.blocksBox(blocks, true); 161 errdefer inner.deinit(allocator); 162 break :gutter try Gutter.init(allocator, "│ ", true, .{ .dim = true }, inner); 163 }; 164 try put(allocator, box, .{ .markdown_gutter = gutter }); 165 }, 166 .list => |list| { 167 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 168 errdefer list_box.deinit(allocator); 169 // ordered markers are right-aligned to the widest number 170 const number_width = std.fmt.count("{d}", .{list.start + list.items.len -| 1}); 171 for (list.items, 0..) |item, i| { 172 const marker = if (item.task) |checked| 173 (if (checked) "☑ " else "☐ ") 174 else if (list.ordered) 175 try std.fmt.allocPrint(b.page_arena.allocator(), "{[n]d:>[w]}. ", .{ .n = list.start + i, .w = number_width }) 176 else 177 "• "; 178 const gutter = gutter: { 179 var inner = try b.blocksBox(item.blocks, false); 180 errdefer inner.deinit(allocator); 181 break :gutter try Gutter.init(allocator, marker, false, .{}, inner); 182 }; 183 try put(allocator, &list_box, .{ .markdown_gutter = gutter }); 184 } 185 try put(allocator, box, .{ .box = list_box }); 186 }, 187 // wider than any pane, and clipped to the width 188 .rule => try put(allocator, box, .{ .text_box = try wgt.TextBox.init(allocator, "─" ** 512, .{ .border_style = null, .wrap_kind = .none, .style = .{ .dim = true } }) }), 189 .raw => |lines| { 190 const text = try std.mem.join(b.page_arena.allocator(), "\n", lines); 191 try put(allocator, box, .{ .text_box = try wgt.TextBox.init(allocator, text, .{ .border_style = null, .wrap_kind = .none }) }); 192 }, 193 } 194 } 195 196 // styled spans for `inlines` over `base`, with each link resolved 197 fn runSpans(b: Builder, inlines: []const md.Inline, base: Grid.Style) ![]const RichText.Span { 198 const out = try b.page_arena.allocator().alloc(RichText.Span, inlines.len); 199 for (inlines, out) |run, *span| { 200 const link = if (run.link) |dest| try b.resolveLink(dest) else ""; 201 var style = base; 202 style.bold = style.bold or run.style.bold; 203 style.italic = run.style.italic; 204 style.strikethrough = run.style.strike; 205 if (run.style.code) style.fg = .{ .ansi = .yellow }; 206 if (link.len > 0) { 207 style.fg = .{ .ansi = .cyan }; 208 style.underline = true; 209 } 210 span.* = .{ .text = run.text, .style = style, .link = link }; 211 } 212 return out; 213 } 214 215 // the focus kind a link follows, or "" when it isn't clickable: web links 216 // are raw links, and a repo path is a files route relative to this file 217 fn resolveLink(b: Builder, dest: []const u8) ![]const u8 { 218 const aa = b.page_arena.allocator(); 219 for ([_][]const u8{ "http:", "https:", "mailto:" }) |scheme| { 220 if (std.ascii.startsWithIgnoreCase(dest, scheme)) return std.fmt.allocPrint(aa, "{s}{s}", .{ ui.raw_link_prefix, dest }); 221 } 222 if (hasScheme(dest) or std.mem.startsWith(u8, dest, "//")) return ""; 223 const data = b.data orelse return ""; 224 const end = std.mem.indexOfAny(u8, dest, "?#") orelse dest.len; 225 if (end == 0) return ""; 226 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, dest[0..end])); 227 228 var segments: std.ArrayList([]const u8) = .empty; 229 if (decoded[0] != '/') { 230 var base = std.mem.tokenizeScalar(u8, b.dir, '/'); 231 while (base.next()) |segment| try segments.append(aa, segment); 232 } 233 var parts = std.mem.tokenizeScalar(u8, decoded, '/'); 234 while (parts.next()) |part| { 235 if (std.mem.eql(u8, part, ".")) continue; 236 if (std.mem.eql(u8, part, "..")) { 237 // climbing above the root isn't a repo path 238 if (segments.pop() == null) return ""; 239 continue; 240 } 241 try segments.append(aa, part); 242 } 243 const path = try std.mem.join(aa, "/", segments.items); 244 const route = data.filesRoute(path, 0) orelse return ""; 245 return std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(b.page_arena)}); 246 } 247 }; 248 249 // whether any heading the title fonts would draw, however nested, has a char 250 // they lack, in which case none use them so they all look alike 251 fn hasUncoveredHeading(blocks: []const md.Block) bool { 252 for (blocks) |block| switch (block) { 253 .heading => |heading| if (heading.level <= 2) for (heading.inlines) |run| { 254 if (!ui.Title.covers(run.text) or !ui.SubTitle.covers(run.text)) return true; 255 }, 256 .quote => |inner| if (hasUncoveredHeading(inner)) return true, 257 .list => |list| for (list.items) |item| { 258 if (hasUncoveredHeading(item.blocks)) return true; 259 }, 260 else => {}, 261 }; 262 return false; 263 } 264 265 // whether `dest` starts with a url scheme 266 fn hasScheme(dest: []const u8) bool { 267 const colon = std.mem.indexOfScalar(u8, dest, ':') orelse return false; 268 if (colon == 0 or !std.ascii.isAlphabetic(dest[0])) return false; 269 for (dest[0..colon]) |c| { 270 if (!std.ascii.isAlphanumeric(c) and c != '+' and c != '.' and c != '-') return false; 271 } 272 return true; 273 } 274 275 fn put(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), widget: ui.Widget) !void { 276 var owned = widget; 277 errdefer owned.deinit(allocator); 278 try box.children.put(allocator, owned.getFocus().id, .{ .widget = owned, .rect = null, .min_size = null }); 279 } 280 281 // a heading in the title font when it fits, else the subtitle font, else 282 // bold text. 283 pub const Heading = struct { 284 focus: *Focus, 285 text: RichText, 286 title: ?ui.Title.View = null, 287 title_width: usize = 0, 288 sub_title: ?ui.SubTitle.View = null, 289 sub_title_width: usize = 0, 290 shown: enum { title, sub_title, text } = .text, 291 292 fn init(allocator: std.mem.Allocator, page_arena: *std.heap.ArenaAllocator, level: u3, spans: []const RichText.Span, fonts: bool) !Heading { 293 var self: Heading = .{ 294 .focus = try Focus.create(allocator, .container), 295 .text = undefined, 296 }; 297 errdefer self.focus.destroy(allocator); 298 // the bold fallback leads with the level's #s, so levels stay apart 299 const marked = try page_arena.allocator().alloc(RichText.Span, spans.len + 1); 300 marked[0] = .{ .text = try std.fmt.allocPrint(page_arena.allocator(), "{s} ", .{"######"[0..level]}), .style = .{ .bold = true } }; 301 @memcpy(marked[1..], spans); 302 self.text = try RichText.init(allocator, marked); 303 errdefer self.text.deinit(allocator); 304 305 var plain: std.ArrayList(u8) = .empty; 306 var has_links = false; 307 for (spans) |span| { 308 try plain.appendSlice(page_arena.allocator(), span.text); 309 has_links = has_links or span.link.len > 0; 310 } 311 const text = std.mem.trim(u8, plain.items, " "); 312 if (!fonts or level > 2 or has_links or text.len == 0) return self; 313 314 if (level == 1) { 315 const title = try ui.Title.init(page_arena, text, .solid); 316 self.title_width = try title.width(); 317 self.title = try ui.Title.View.init(allocator, &title); 318 } 319 errdefer if (self.title) |*title| title.deinit(allocator); 320 const sub_title = try ui.SubTitle.init(page_arena, text); 321 self.sub_title_width = try sub_title.width(); 322 self.sub_title = try ui.SubTitle.View.init(allocator, &sub_title); 323 return self; 324 } 325 326 pub fn deinit(self: *Heading, allocator: std.mem.Allocator) void { 327 self.focus.destroy(allocator); 328 self.text.deinit(allocator); 329 if (self.title) |*title| title.deinit(allocator); 330 if (self.sub_title) |*sub_title| sub_title.deinit(allocator); 331 } 332 333 pub fn build(self: *Heading, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 334 self.clearGrid(); 335 self.focus.clear(); 336 const max_width = constraint.max_size.width orelse std.math.maxInt(usize); 337 self.shown = if (self.title != null and self.title_width <= max_width) 338 .title 339 else if (self.sub_title != null and self.sub_title_width <= max_width) 340 .sub_title 341 else 342 .text; 343 switch (self.shown) { 344 .title => try self.buildShown(allocator, constraint, root_focus, if (self.title) |*title| title else unreachable), 345 .sub_title => try self.buildShown(allocator, constraint, root_focus, if (self.sub_title) |*sub_title| sub_title else unreachable), 346 .text => try self.buildShown(allocator, constraint, root_focus, &self.text), 347 } 348 } 349 350 fn buildShown(self: *Heading, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus, widget: anytype) !void { 351 try widget.build(allocator, constraint, root_focus); 352 const grid = widget.getGrid() orelse return; 353 try self.focus.addChild(allocator, widget.getFocus(), grid.size, 0, 0); 354 } 355 356 pub fn input(self: *Heading, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 357 _ = self; 358 _ = allocator; 359 _ = key; 360 _ = root_focus; 361 } 362 363 pub fn clearGrid(self: *Heading) void { 364 self.text.clearGrid(); 365 if (self.title) |*title| title.clearGrid(); 366 if (self.sub_title) |*sub_title| sub_title.clearGrid(); 367 } 368 369 pub fn getGrid(self: Heading) ?Grid { 370 return switch (self.shown) { 371 .title => if (self.title) |title| title.getGrid() else null, 372 .sub_title => if (self.sub_title) |sub_title| sub_title.getGrid() else null, 373 .text => self.text.getGrid(), 374 }; 375 } 376 377 pub fn getFocus(self: *Heading) *Focus { 378 return self.focus; 379 } 380 }; 381 382 // a marker column beside a child, so wrapped lines hang under the child's 383 // first line: a list item's bullet, or a quote's bar on every row. 384 pub const Gutter = struct { 385 focus: *Focus, 386 grid: ?Grid, 387 child: wgt.Box(ui.Widget), 388 marker: []const u8, 389 // draw the marker on every row rather than only the first 390 repeat: bool, 391 style: Grid.Style, 392 393 // takes ownership of `child` on success 394 fn init(allocator: std.mem.Allocator, marker: []const u8, repeat: bool, style: Grid.Style, child: wgt.Box(ui.Widget)) !Gutter { 395 return .{ .focus = try Focus.create(allocator, .container), .grid = null, .child = child, .marker = marker, .repeat = repeat, .style = style }; 396 } 397 398 pub fn deinit(self: *Gutter, allocator: std.mem.Allocator) void { 399 self.focus.destroy(allocator); 400 self.clearGrid(); 401 self.child.deinit(allocator); 402 } 403 404 pub fn build(self: *Gutter, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 405 self.clearGrid(); 406 self.focus.clear(); 407 const marker_width = try xitui.width.displayWidth(self.marker); 408 if (constraint.max_size.width) |w| if (w <= marker_width) return; 409 if (constraint.max_size.height == 0) return; 410 411 try self.child.build(allocator, .{ 412 .min_size = .{ .width = null, .height = null }, 413 .max_size = .{ .width = if (constraint.max_size.width) |w| w - marker_width else null, .height = constraint.max_size.height }, 414 }, root_focus); 415 const child_grid = self.child.getGrid(); 416 const child_size: layout.Size = if (child_grid) |g| g.size else .{ .width = 0, .height = 0 }; 417 418 var grid = try Grid.init(allocator, .{ .width = marker_width + child_size.width, .height = @max(1, child_size.height) }); 419 errdefer grid.deinit(); 420 for (0..if (self.repeat) grid.size.height else 1) |y| { 421 var x: usize = 0; 422 var utf8 = (try std.unicode.Utf8View.init(self.marker)).iterator(); 423 while (utf8.nextCodepoint()) |rune| { 424 (try grid.cell(x, y)).style = self.style; 425 try grid.setRune(x, y, rune); 426 x += xitui.width.cellWidth(rune); 427 } 428 } 429 if (child_grid) |g| { 430 try grid.drawGrid(g, marker_width, 0); 431 try self.focus.addChild(allocator, self.child.getFocus(), g.size, marker_width, 0); 432 } 433 self.grid = grid; 434 } 435 436 pub fn input(self: *Gutter, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 437 _ = self; 438 _ = allocator; 439 _ = key; 440 _ = root_focus; 441 } 442 443 pub fn clearGrid(self: *Gutter) void { 444 if (self.grid) |*grid| { 445 grid.deinit(); 446 self.grid = null; 447 } 448 self.child.clearGrid(); 449 } 450 451 pub fn getGrid(self: Gutter) ?Grid { 452 return self.grid; 453 } 454 455 pub fn getFocus(self: *Gutter) *Focus { 456 return self.focus; 457 } 458 }; 459