├── .gitignore ├── LICENSE ├── README.md ├── build.zig ├── build.zig.zon ├── screenshot.png └── src └── main.zig /.gitignore: -------------------------------------------------------------------------------- 1 | zig-out/ 2 | .zig-cache/ 3 | *.log 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2024 Tim Culverhouse 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vaxis-launcher 2 | 3 | vaxis-launcher is a TUI launcher based on [pop-launcher](https://github.com/pop-os/launcher) 4 | 5 | ![vaxis-launcher](./screenshot.png) 6 | 7 | ## Usage 8 | 9 | First, you must have `pop-launcher` installed. 10 | 11 | Second, use your favorite terminal to run `vaxis-launcher`. Personally, I have a 12 | keybind to launch a terminal running this command. I use a rule within Sway to 13 | launch a floating terminal running `vaxis-launcher`. Maybe you should too? 14 | 15 | ## Configuration 16 | 17 | Configuration is done by modifying a couple lines in the source files and 18 | rebuilding the project. 19 | 20 | `launch_cmd` - this is the command to launch an application. For sway, this 21 | should be `swaymsg exec` 22 | 23 | `terminal_cmd` - for Desktop Entries which require a terminal, this is the 24 | terminal cmd to use. This will be appended to `launch_cmd`. For example, to 25 | launch a command with foot you would set this to `foot -e` 26 | 27 | ## Installation 28 | 29 | `vaxis-launcher` can be installed with zig. Currently, it uses 30 | `0.14.0-dev.2456+a68119f8f`. Installation should be something like `zig build 31 | -Doptimize=ReleaseSafe --prefix $HOME/.local` 32 | 33 | ## Contributing 34 | 35 | Contributions are welcome. 36 | 37 | ## Roadmap 38 | 39 | - Icons via kitty graphics protocol 40 | - Tab completion 41 | - Real configuration 42 | -------------------------------------------------------------------------------- /build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn build(b: *std.Build) void { 4 | const target = b.standardTargetOptions(.{}); 5 | const optimize = b.standardOptimizeOption(.{}); 6 | 7 | const exe = b.addExecutable(.{ 8 | .name = "vaxis-launcher", 9 | .root_source_file = b.path("src/main.zig"), 10 | .target = target, 11 | .optimize = optimize, 12 | }); 13 | 14 | const vaxis_dep = b.dependency("vaxis", .{ 15 | .target = target, 16 | .optimize = optimize, 17 | }); 18 | exe.root_module.addImport("vaxis", vaxis_dep.module("vaxis")); 19 | 20 | b.installArtifact(exe); 21 | 22 | const run_cmd = b.addRunArtifact(exe); 23 | 24 | run_cmd.step.dependOn(b.getInstallStep()); 25 | 26 | if (b.args) |args| { 27 | run_cmd.addArgs(args); 28 | } 29 | 30 | const run_step = b.step("run", "Run the app"); 31 | run_step.dependOn(&run_cmd.step); 32 | 33 | const exe_unit_tests = b.addTest(.{ 34 | .root_source_file = b.path("src/main.zig"), 35 | .target = target, 36 | .optimize = optimize, 37 | }); 38 | 39 | const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); 40 | 41 | const test_step = b.step("test", "Run unit tests"); 42 | test_step.dependOn(&run_exe_unit_tests.step); 43 | } 44 | -------------------------------------------------------------------------------- /build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = "vaxis-launcher", 3 | .version = "0.0.0", 4 | .dependencies = .{ 5 | .vaxis = .{ 6 | .url = "git+https://github.com/rockorager/libvaxis?ref=zig-0.14.0#34f3290ac1ffa6bcc0a968141f116c2830187b46", 7 | .hash = "122086621dccc4755a77592840b8e87166ed1958461a73171f4371684f6662b6578b", 8 | }, 9 | }, 10 | .paths = .{ 11 | "build.zig", 12 | "build.zig.zon", 13 | "src", 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockorager/vaxis-launcher/83be9cbb10df1e69529705e55f9233308336b361/screenshot.png -------------------------------------------------------------------------------- /src/main.zig: -------------------------------------------------------------------------------- 1 | /// Change this to your launch command. Example: 2 | /// swaymsg exec 3 | const launch_cmd: []const []const u8 = &.{ "swaymsg", "exec" }; 4 | 5 | /// Change this to your launchable terminal command. Some examples 6 | /// xdg-terminal-exec 7 | /// ghostty -e 8 | /// foot -e 9 | const terminal_cmd: []const []const u8 = &.{"xdg-terminal-exec"}; 10 | 11 | const std = @import("std"); 12 | const vaxis = @import("vaxis"); 13 | 14 | const json = std.json; 15 | const log = std.log; 16 | const mem = std.mem; 17 | const vxfw = vaxis.vxfw; 18 | 19 | pub const std_options: std.Options = .{ 20 | .log_level = .err, 21 | }; 22 | 23 | const request = struct { 24 | const activate = 25 | \\{{"Activate": {d}}} 26 | \\ 27 | ; 28 | 29 | const activate_context = 30 | \\{{"ActivateContext": {{ "id": {d}, "context": {d} }} }} 31 | \\ 32 | ; 33 | 34 | const complete = 35 | \\{{"Complete": {d}}} 36 | \\ 37 | ; 38 | 39 | const context = 40 | \\{{"Context": {d}}} 41 | \\ 42 | ; 43 | 44 | const exit = 45 | \\"Exit" 46 | \\ 47 | ; 48 | 49 | const interrupt = 50 | \\"Interrupt" 51 | \\ 52 | ; 53 | 54 | const quit = 55 | \\{{"Quit": {d}}} 56 | \\ 57 | ; 58 | 59 | const search = 60 | \\{{"Search": "{s}"}} 61 | \\ 62 | ; 63 | }; 64 | 65 | const SearchResult = struct { 66 | id: u32, 67 | name: []const u8, 68 | description: []const u8, 69 | icon: ?IconSource = null, 70 | category_icon: ?IconSource = null, 71 | window: ?[2]u32 = null, 72 | }; 73 | 74 | const IconSource = union(enum) { 75 | Name: []const u8, 76 | Mime: []const u8, 77 | }; 78 | 79 | const ResponseType = enum { 80 | close, 81 | context, 82 | desktop_entry, 83 | update, 84 | fill, 85 | }; 86 | 87 | const Response = union(ResponseType) { 88 | close, 89 | context, // TODO: 90 | desktop_entry: []const u8, 91 | update: json.Parsed([]const SearchResult), 92 | fill: []const u8, 93 | 94 | fn fromString(str: []const u8) ?ResponseType { 95 | if (mem.eql(u8, "Close", str)) 96 | return .close; 97 | if (mem.eql(u8, "Context", str)) 98 | return .context; 99 | if (mem.eql(u8, "DesktopEntry", str)) 100 | return .desktop_entry; 101 | if (mem.eql(u8, "Update", str)) 102 | return .update; 103 | if (mem.eql(u8, "Fill", str)) 104 | return .fill; 105 | return null; 106 | } 107 | }; 108 | 109 | const Model = struct { 110 | gpa: std.mem.Allocator, 111 | 112 | list: std.ArrayList(vxfw.RichText), 113 | results: ?json.Parsed([]const SearchResult) = null, 114 | 115 | list_view: vxfw.ListView, 116 | text_field: vxfw.TextField, 117 | unicode_data: *const vaxis.Unicode, 118 | 119 | cmd: std.process.Child, 120 | 121 | read_thread: ?std.Thread = null, 122 | 123 | responses: vaxis.Queue(Response, 16) = .{}, 124 | 125 | fn deinit(self: *Model) void { 126 | if (self.cmd.stdin) |cmd| { 127 | cmd.writeAll(request.exit) catch {}; 128 | } 129 | if (self.read_thread) |thread| { 130 | thread.join(); 131 | } 132 | if (self.results) |items| 133 | items.deinit(); 134 | self.text_field.deinit(); 135 | self.list.deinit(); 136 | } 137 | 138 | pub fn widget(self: *Model) vxfw.Widget { 139 | return .{ 140 | .userdata = self, 141 | .eventHandler = Model.typeErasedEventHandler, 142 | .drawFn = Model.typeErasedDrawFn, 143 | }; 144 | } 145 | 146 | fn typeErasedEventHandler(ptr: *anyopaque, ctx: *vxfw.EventContext, event: vxfw.Event) anyerror!void { 147 | const self: *Model = @ptrCast(@alignCast(ptr)); 148 | switch (event) { 149 | .init => { 150 | // Initialize the filtered list 151 | self.cmd.stdin_behavior = .Pipe; 152 | self.cmd.stdout_behavior = .Pipe; 153 | self.cmd.stderr_behavior = .Pipe; 154 | self.cmd.spawn() catch |err| { 155 | switch (err) { 156 | error.FileNotFound => @panic("file not found"), 157 | else => return err, 158 | } 159 | }; 160 | self.read_thread = try std.Thread.spawn(.{}, Model.readThread, .{self}); 161 | try ctx.requestFocus(self.text_field.widget()); 162 | try ctx.tick(16, self.widget()); 163 | }, 164 | .tick => { 165 | while (self.responses.tryPop()) |response| { 166 | switch (response) { 167 | .close => { 168 | ctx.quit = true; 169 | return; 170 | }, 171 | .context => {}, 172 | .desktop_entry => |entry| { 173 | defer self.gpa.free(entry); 174 | var arena = std.heap.ArenaAllocator.init(self.gpa); 175 | defer arena.deinit(); 176 | const de = try DesktopEntry.loadFromPathLeaky(arena.allocator(), entry); 177 | const main_group = de.desktopEntry(); 178 | var exec = std.ArrayList(u8).init(arena.allocator()); 179 | const exec_line = main_group.exec() orelse { 180 | // Exit?? 181 | @panic("TODO: no exec"); 182 | }; 183 | var iter = std.mem.tokenizeScalar(u8, exec_line, ' '); 184 | const codes: []const []const u8 = &.{ 185 | "%f", // single file 186 | "%F", // list of files 187 | "%u", // single url 188 | "%U", // list of urls 189 | "%d", // deprecated 190 | "%D", // deprecated 191 | "%n", // deprecated 192 | "%N", // deprecated 193 | "%i", // icon key 194 | "%c", // translated name of application 195 | "%k", // location of desktop file as uri 196 | "%v", // deprecated 197 | "%m", // deprecated 198 | }; 199 | outer: while (iter.next()) |item| { 200 | for (codes) |code| { 201 | if (mem.eql(u8, code, item)) 202 | continue :outer; 203 | } 204 | if (exec.items.len > 0) { 205 | try exec.append(' '); 206 | } 207 | try exec.appendSlice(item); 208 | } 209 | 210 | var argv = std.ArrayList([]const u8).init(self.gpa); 211 | defer argv.deinit(); 212 | 213 | // Build argv 214 | try argv.appendSlice(launch_cmd); 215 | if (main_group.terminal()) 216 | try argv.appendSlice(terminal_cmd); 217 | try argv.append(exec.items); 218 | 219 | var launch = std.process.Child.init(argv.items, self.gpa); 220 | const ret = try launch.spawnAndWait(); 221 | 222 | switch (ret) { 223 | .Exited => |code| { 224 | if (code != 0) { 225 | log.err("failed to launch: {s}", .{exec.items}); 226 | @panic("failure to launch"); 227 | } 228 | }, 229 | else => { 230 | log.err("failed to launch: {s}", .{exec.items}); 231 | @panic("failure to launch"); 232 | }, 233 | } 234 | ctx.quit = true; 235 | }, 236 | .update => |update| { 237 | try self.handleUpdate(update); 238 | ctx.redraw = true; 239 | }, 240 | .fill => |fill| { 241 | ctx.redraw = true; 242 | defer self.gpa.free(fill); 243 | self.text_field.clearAndFree(); 244 | try self.text_field.insertSliceAtCursor(fill); 245 | try Model.onChange(self, ctx, fill); 246 | }, 247 | } 248 | } 249 | try ctx.tick(16, self.widget()); 250 | }, 251 | .key_press => |key| { 252 | if (key.matches('c', .{ .ctrl = true }) or 253 | key.matches(vaxis.Key.escape, .{})) 254 | { 255 | ctx.quit = true; 256 | return; 257 | } 258 | return self.list_view.handleEvent(ctx, event); 259 | }, 260 | .focus_in => { 261 | return ctx.requestFocus(self.text_field.widget()); 262 | }, 263 | else => {}, 264 | } 265 | } 266 | 267 | fn typeErasedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) std.mem.Allocator.Error!vxfw.Surface { 268 | const self: *Model = @ptrCast(@alignCast(ptr)); 269 | const max = ctx.max.size(); 270 | 271 | var list_view: vxfw.SubSurface = .{ 272 | .origin = .{ .row = 2, .col = 0 }, 273 | .surface = try self.list_view.draw(ctx.withConstraints( 274 | ctx.min, 275 | .{ .width = max.width, .height = max.height - 3 }, 276 | )), 277 | }; 278 | list_view.surface.focusable = false; 279 | 280 | const text_field: vxfw.SubSurface = .{ 281 | .origin = .{ .row = 0, .col = 2 }, 282 | .surface = try self.text_field.draw(ctx.withConstraints( 283 | ctx.min, 284 | .{ .width = max.width, .height = 1 }, 285 | )), 286 | }; 287 | 288 | const prompt: vxfw.Text = .{ .text = "", .style = .{ .fg = .{ .index = 4 } } }; 289 | 290 | const prompt_surface: vxfw.SubSurface = .{ 291 | .origin = .{ .row = 0, .col = 0 }, 292 | .surface = try prompt.draw(ctx.withConstraints(ctx.min, .{ .width = 2, .height = 1 })), 293 | }; 294 | 295 | const children = try ctx.arena.alloc(vxfw.SubSurface, 3); 296 | children[0] = list_view; 297 | children[1] = text_field; 298 | children[2] = prompt_surface; 299 | 300 | return .{ 301 | .size = max, 302 | .widget = self.widget(), 303 | .focusable = true, 304 | .buffer = &.{}, 305 | .children = children, 306 | }; 307 | } 308 | 309 | fn widgetBuilder(ptr: *const anyopaque, idx: usize, _: usize) ?vxfw.Widget { 310 | const self: *const Model = @ptrCast(@alignCast(ptr)); 311 | if (idx >= self.list.items.len) return null; 312 | 313 | return self.list.items[idx].widget(); 314 | } 315 | 316 | fn onChange(maybe_ptr: ?*anyopaque, _: *vxfw.EventContext, str: []const u8) anyerror!void { 317 | const ptr = maybe_ptr orelse return; 318 | const self: *Model = @ptrCast(@alignCast(ptr)); 319 | const search_request = try std.fmt.allocPrint(self.gpa, request.search, .{str}); 320 | defer self.gpa.free(search_request); 321 | const cmd = self.cmd.stdin orelse unreachable; 322 | try cmd.writeAll(search_request); 323 | 324 | self.list_view.scroll.top = 0; 325 | self.list_view.scroll.offset = 0; 326 | self.list_view.cursor = 0; 327 | } 328 | 329 | fn onSubmit(maybe_ptr: ?*anyopaque, _: *vxfw.EventContext, _: []const u8) anyerror!void { 330 | const ptr = maybe_ptr orelse unreachable; 331 | const self: *Model = @ptrCast(@alignCast(ptr)); 332 | const cmd = self.cmd.stdin orelse unreachable; 333 | 334 | const activate = try std.fmt.allocPrint( 335 | self.gpa, 336 | request.activate, 337 | .{self.list_view.cursor}, 338 | ); 339 | defer self.gpa.free(activate); 340 | try cmd.writeAll(activate); 341 | } 342 | 343 | fn handleUpdate(self: *Model, update: json.Parsed([]const SearchResult)) anyerror!void { 344 | if (self.results) |items| 345 | items.deinit(); 346 | self.results = update; 347 | self.list.clearAndFree(); 348 | const arena = update.arena.allocator(); 349 | const items = update.value; 350 | for (items) |item| { 351 | if (item.icon) |icon| { 352 | switch (icon) { 353 | .Name => |name| log.debug("icon name={s}", .{name}), 354 | .Mime => |mime| log.debug("icon mime={s}", .{mime}), 355 | } 356 | } 357 | const spans = try arena.alloc(vxfw.RichText.TextSpan, 3); 358 | spans[0] = .{ 359 | .text = item.name, 360 | .style = .{ 361 | .fg = .{ .index = 4 }, 362 | .bold = true, 363 | }, 364 | }; 365 | spans[1] = .{ .text = " " }; 366 | 367 | var description = item.description; 368 | if (std.mem.startsWith(u8, description, "System")) 369 | description = description[6..]; 370 | if (std.mem.startsWith(u8, description, "User")) 371 | description = description[4..]; 372 | if (std.mem.startsWith(u8, description, " - ")) 373 | description = description[3..]; 374 | 375 | spans[2] = .{ 376 | .text = description, 377 | .style = .{ .italic = true }, 378 | }; 379 | try self.list.append(.{ .text = spans }); 380 | } 381 | } 382 | 383 | fn readThread(self: *Model) !void { 384 | const reader = self.cmd.stdout.?.reader(); 385 | var buf = std.ArrayList(u8).init(self.gpa); 386 | defer buf.deinit(); 387 | while (true) { 388 | buf.clearRetainingCapacity(); 389 | reader.readUntilDelimiterArrayList(&buf, '\n', 10_000_000) catch |err| { 390 | switch (err) { 391 | error.EndOfStream => {}, 392 | else => log.err("read: {}", .{err}), 393 | } 394 | return; 395 | }; 396 | const parsed = try json.parseFromSlice(std.json.Value, self.gpa, buf.items, .{}); 397 | defer parsed.deinit(); 398 | const value = parsed.value; 399 | switch (value) { 400 | .string => |str| { 401 | if (mem.eql(u8, "Close", str)) { 402 | self.responses.push(.close); 403 | } else { 404 | stringifyLog(self.gpa, "unknown response: {s}", value); 405 | } 406 | }, 407 | .object => |obj| { 408 | const keys = obj.keys(); 409 | if (keys.len != 1) { 410 | stringifyLog(self.gpa, "invalid response: {s}", value); 411 | return; 412 | } 413 | const kind = Response.fromString(keys[0]) orelse { 414 | stringifyLog(self.gpa, "unexpected response: {s}", value); 415 | return; 416 | }; 417 | const inner = obj.get(keys[0]) orelse unreachable; 418 | switch (kind) { 419 | .close => return, 420 | .context => { 421 | log.warn("context", .{}); 422 | }, 423 | .desktop_entry => { 424 | if (inner != .object) { 425 | stringifyLog(self.gpa, "unexpected response: {s}", value); 426 | return; 427 | } 428 | const object = inner.object; 429 | const path = object.get("path") orelse { 430 | stringifyLog(self.gpa, "unexpected response: {s}", value); 431 | return; 432 | }; 433 | if (path != .string) { 434 | stringifyLog(self.gpa, "unexpected response: {s}", value); 435 | return; 436 | } 437 | const path_str = try self.gpa.dupe(u8, path.string); 438 | self.responses.push(.{ .desktop_entry = path_str }); 439 | }, 440 | .update => { 441 | const items = try json.parseFromValue([]const SearchResult, self.gpa, inner, .{}); 442 | self.responses.push(.{ .update = items }); 443 | }, 444 | .fill => { 445 | if (inner == .string) { 446 | const fill_str = try self.gpa.dupe(u8, inner.string); 447 | self.responses.push(.{ .fill = fill_str }); 448 | } else { 449 | stringifyLog(self.gpa, "unexpected response: {s}", value); 450 | return; 451 | } 452 | }, 453 | } 454 | }, 455 | else => unreachable, 456 | } 457 | } 458 | } 459 | }; 460 | 461 | fn stringifyLog(gpa: mem.Allocator, comptime format: []const u8, value: json.Value) void { 462 | const stringified = json.stringifyAlloc(gpa, value, .{}) catch return; 463 | defer gpa.free(stringified); 464 | log.err(format, .{stringified}); 465 | } 466 | 467 | const DesktopEntry = struct { 468 | groups: []const Group, 469 | 470 | const Group = struct { 471 | name: []const u8, 472 | entries: []const Entry, 473 | 474 | pub fn exec(self: Group) ?[]const u8 { 475 | for (self.entries) |entry| { 476 | if (!mem.eql(u8, "Exec", entry.key)) 477 | continue; 478 | return entry.value; 479 | } 480 | return null; 481 | } 482 | 483 | pub fn terminal(self: Group) bool { 484 | for (self.entries) |entry| { 485 | if (!mem.eql(u8, "Terminal", entry.key)) 486 | continue; 487 | if (std.ascii.eqlIgnoreCase("true", entry.value)) { 488 | return true; 489 | } 490 | return false; 491 | } 492 | return false; 493 | } 494 | }; 495 | 496 | const Entry = struct { 497 | key: []const u8, 498 | value: []const u8, 499 | }; 500 | 501 | pub fn desktopEntry(self: DesktopEntry) Group { 502 | for (self.groups) |group| { 503 | if (std.mem.eql(u8, "Desktop Entry", group.name)) { 504 | return group; 505 | } 506 | } 507 | unreachable; 508 | } 509 | 510 | pub fn loadFromPathLeaky(arena: std.mem.Allocator, abs: []const u8) !DesktopEntry { 511 | const file = try std.fs.openFileAbsolute(abs, .{}); 512 | defer file.close(); 513 | 514 | var groups = std.ArrayList(Group).init(arena); 515 | var group_name: []const u8 = ""; 516 | var entries = std.ArrayList(Entry).init(arena); 517 | 518 | const bytes = try file.readToEndAlloc(arena, 100_000_000); 519 | var iter = std.mem.splitScalar(u8, bytes, '\n'); 520 | 521 | while (iter.next()) |line| { 522 | // Ignore empty and comments 523 | if (line.len == 0 or 524 | std.mem.startsWith(u8, line, "#")) 525 | { 526 | log.debug("skipping line: {s}", .{line}); 527 | continue; 528 | } 529 | 530 | if (std.mem.startsWith(u8, line, "[")) { 531 | // New group 532 | if (group_name.len > 0 and entries.items.len > 0) { 533 | // Add the group 534 | const group: Group = .{ 535 | .name = group_name, 536 | .entries = try entries.toOwnedSlice(), 537 | }; 538 | log.debug("finishing group: {s}, n_entries={d}", .{ group_name, group.entries.len }); 539 | try groups.append(group); 540 | } 541 | const end = std.mem.lastIndexOfScalar(u8, line, ']') orelse unreachable; 542 | group_name = line[1..end]; 543 | log.debug("new group: {s}", .{group_name}); 544 | continue; 545 | } 546 | 547 | const idx = std.mem.indexOfScalar(u8, line, '=') orelse unreachable; 548 | const key = std.mem.trim(u8, line[0..idx], " "); 549 | const value = std.mem.trim(u8, line[idx + 1 ..], " "); 550 | log.debug("entry: key={s}, value={s}", .{ key, value }); 551 | try entries.append(.{ .key = key, .value = value }); 552 | } 553 | if (group_name.len > 0 and entries.items.len > 0) { 554 | // Add the group 555 | const group: Group = .{ 556 | .name = group_name, 557 | .entries = try entries.toOwnedSlice(), 558 | }; 559 | log.debug("finishing group: {s}, n_entries={d}", .{ group_name, group.entries.len }); 560 | try groups.append(group); 561 | } 562 | return .{ .groups = try groups.toOwnedSlice() }; 563 | } 564 | }; 565 | 566 | pub fn main() !void { 567 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 568 | defer _ = gpa.deinit(); 569 | 570 | const allocator = gpa.allocator(); 571 | 572 | var app = try vxfw.App.init(allocator); 573 | defer app.deinit(); 574 | 575 | const model = try allocator.create(Model); 576 | defer allocator.destroy(model); 577 | model.* = .{ 578 | .list = std.ArrayList(vxfw.RichText).init(allocator), 579 | .list_view = .{ 580 | .children = .{ 581 | .builder = .{ 582 | .userdata = model, 583 | .buildFn = Model.widgetBuilder, 584 | }, 585 | }, 586 | }, 587 | .text_field = .{ 588 | .buf = vxfw.TextField.Buffer.init(allocator), 589 | .unicode = &app.vx.unicode, 590 | .userdata = model, 591 | .onChange = Model.onChange, 592 | .onSubmit = Model.onSubmit, 593 | }, 594 | .gpa = allocator, 595 | .cmd = std.process.Child.init(&.{"pop-launcher"}, allocator), 596 | .unicode_data = &app.vx.unicode, 597 | }; 598 | defer model.deinit(); 599 | 600 | try app.run(model.widget(), .{}); 601 | } 602 | --------------------------------------------------------------------------------