Commit 7cdb333
Eric Bower
·
2026-03-23 11:51:56 -0400 EDT
parent 4dff5d4
chore: wrap lines where applicable to 100
5 files changed,
+152,
-36
+10,
-2
| ... | ... | @@ -74,7 +74,12 @@ pub fn send(fd: i32, tag: Tag, data: []const u8) !void { | |
| 74 | 74 | } | |
| 75 | 75 | } | |
| 76 | 76 | ||
| 77 | - | pub fn appendMessage(alloc: std.mem.Allocator, list: *std.ArrayList(u8), tag: Tag, data: []const u8) !void { | |
| 77 | + | pub fn appendMessage( | |
| 78 | + | alloc: std.mem.Allocator, | |
| 79 | + | list: *std.ArrayList(u8), | |
| 80 | + | tag: Tag, | |
| 81 | + | data: []const u8, | |
| 82 | + | ) !void { | |
| 78 | 83 | const header = Header{ | |
| 79 | 84 | .tag = tag, | |
| 80 | 85 | .len = @intCast(data.len), |
| ... | ... | @@ -178,7 +183,10 @@ const SessionProbeResult = struct { | |
| 178 | 183 | info: Info, | |
| 179 | 184 | }; | |
| 180 | 185 | ||
| 181 | - | pub fn probeSession(alloc: std.mem.Allocator, socket_path: []const u8) SessionProbeError!SessionProbeResult { | |
| 186 | + | pub fn probeSession( | |
| 187 | + | alloc: std.mem.Allocator, | |
| 188 | + | socket_path: []const u8, | |
| 189 | + | ) SessionProbeError!SessionProbeResult { | |
| 182 | 190 | const timeout_ms = 1000; | |
| 183 | 191 | const fd = socket.sessionConnect(socket_path) catch |err| switch (err) { | |
| 184 | 192 | error.ConnectionRefused => return error.ConnectionRefused, |
+15,
-3
| ... | ... | @@ -13,7 +13,10 @@ pub const LogSystem = struct { | |
| 13 | 13 | self.path = try alloc.dupe(u8, path); | |
| 14 | 14 | ||
| 15 | 15 | const file = std.fs.openFileAbsolute(path, .{ .mode = .read_write }) catch |err| switch (err) { | |
| 16 | - | error.FileNotFound => try std.fs.createFileAbsolute(path, .{ .read = true, .mode = 0o640 }), | |
| 16 | + | error.FileNotFound => try std.fs.createFileAbsolute( | |
| 17 | + | path, | |
| 18 | + | .{ .read = true, .mode = 0o640 }, | |
| 19 | + | ), | |
| 17 | 20 | else => return err, | |
| 18 | 21 | }; | |
| 19 | 22 |
| ... | ... | @@ -28,7 +31,13 @@ pub const LogSystem = struct { | |
| 28 | 31 | if (self.path.len > 0) self.alloc.free(self.path); | |
| 29 | 32 | } | |
| 30 | 33 | ||
| 31 | - | pub fn log(self: *LogSystem, comptime level: std.log.Level, comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype) void { | |
| 34 | + | pub fn log( | |
| 35 | + | self: *LogSystem, | |
| 36 | + | comptime level: std.log.Level, | |
| 37 | + | comptime scope: @Type(.enum_literal), | |
| 38 | + | comptime format: []const u8, | |
| 39 | + | args: anytype, | |
| 40 | + | ) void { | |
| 32 | 41 | self.mutex.lock(); | |
| 33 | 42 | defer self.mutex.unlock(); | |
| 34 | 43 |
| ... | ... | @@ -82,7 +91,10 @@ pub const LogSystem = struct { | |
| 82 | 91 | else => return err, | |
| 83 | 92 | }; | |
| 84 | 93 | ||
| 85 | - | self.file = try std.fs.createFileAbsolute(self.path, .{ .truncate = true, .read = true, .mode = 0o640 }); | |
| 94 | + | self.file = try std.fs.createFileAbsolute( | |
| 95 | + | self.path, | |
| 96 | + | .{ .truncate = true, .read = true, .mode = 0o640 }, | |
| 97 | + | ); | |
| 86 | 98 | self.current_size = 0; | |
| 87 | 99 | } | |
| 88 | 100 | }; |
+100,
-25
| ... | ... | @@ -355,7 +355,12 @@ const Daemon = struct { | |
| 355 | 355 | ||
| 356 | 356 | const shell = util.detectShell(); | |
| 357 | 357 | // Use "-shellname" as argv[0] to signal login shell (traditional method) | |
| 358 | - | const login_shell = try std.fmt.allocPrintSentinel(alloc, "-{s}", .{std.fs.path.basename(shell)}, 0); | |
| 358 | + | const login_shell = try std.fmt.allocPrintSentinel( | |
| 359 | + | alloc, | |
| 360 | + | "-{s}", | |
| 361 | + | .{std.fs.path.basename(shell)}, | |
| 362 | + | 0, | |
| 363 | + | ); | |
| 359 | 364 | const argv = [_:null]?[*:0]const u8{ login_shell, null }; | |
| 360 | 365 | const err = std.posix.execveZ(shell, &argv, std.c.environ); | |
| 361 | 366 | std.log.err("execve failed: err={s}", .{@errorName(err)}); |
| ... | ... | @@ -412,7 +417,10 @@ const Daemon = struct { | |
| 412 | 417 | if (ipc.probeSession(self.alloc, self.socket_path)) |result| { | |
| 413 | 418 | posix.close(result.fd); | |
| 414 | 419 | if (self.command != null) { | |
| 415 | - | std.log.warn("session already exists, ignoring command session={s}", .{self.session_name}); | |
| 420 | + | std.log.warn( | |
| 421 | + | "session already exists, ignoring command session={s}", | |
| 422 | + | .{self.session_name}, | |
| 423 | + | ); | |
| 416 | 424 | } | |
| 417 | 425 | } else |err| switch (err) { | |
| 418 | 426 | // Daemon is definitively gone: safe to replace. |
| ... | ... | @@ -424,7 +432,10 @@ const Daemon = struct { | |
| 424 | 432 | // The probe is only to decide create-vs-attach; the session | |
| 425 | 433 | // exists, so proceed to attach rather than fail or orphan. | |
| 426 | 434 | else => { | |
| 427 | - | std.log.warn("probe slow ({s}), proceeding to attach session={s}", .{ @errorName(err), self.session_name }); | |
| 435 | + | std.log.warn( | |
| 436 | + | "probe slow ({s}), proceeding to attach session={s}", | |
| 437 | + | .{ @errorName(err), self.session_name }, | |
| 438 | + | ); | |
| 428 | 439 | }, | |
| 429 | 440 | } | |
| 430 | 441 | } |
| ... | ... | @@ -440,9 +451,16 @@ const Daemon = struct { | |
| 440 | 451 | _ = try posix.setsid(); | |
| 441 | 452 | ||
| 442 | 453 | log_system.deinit(); | |
| 443 | - | const session_log_name = try std.fmt.allocPrint(self.alloc, "{s}.log", .{self.session_name}); | |
| 454 | + | const session_log_name = try std.fmt.allocPrint( | |
| 455 | + | self.alloc, | |
| 456 | + | "{s}.log", | |
| 457 | + | .{self.session_name}, | |
| 458 | + | ); | |
| 444 | 459 | defer self.alloc.free(session_log_name); | |
| 445 | - | const session_log_path = try std.fs.path.join(self.alloc, &.{ self.cfg.log_dir, session_log_name }); | |
| 460 | + | const session_log_path = try std.fs.path.join( | |
| 461 | + | self.alloc, | |
| 462 | + | &.{ self.cfg.log_dir, session_log_name }, | |
| 463 | + | ); | |
| 446 | 464 | defer self.alloc.free(session_log_path); | |
| 447 | 465 | try log_system.init(self.alloc, session_log_path); | |
| 448 | 466 |
| ... | ... | @@ -490,9 +508,15 @@ const Daemon = struct { | |
| 490 | 508 | while (remaining.len > 0) { | |
| 491 | 509 | const n = posix.write(pty_fd, remaining) catch |err| { | |
| 492 | 510 | if (err == error.WouldBlock) { | |
| 493 | - | std.log.warn("pty write dropped {d}/{d} bytes (buffer full)", .{ remaining.len, data.len }); | |
| 511 | + | std.log.warn( | |
| 512 | + | "pty write dropped {d}/{d} bytes (buffer full)", | |
| 513 | + | .{ remaining.len, data.len }, | |
| 514 | + | ); | |
| 494 | 515 | } else { | |
| 495 | - | std.log.warn("pty write failed, {d} bytes lost: {s}", .{ remaining.len, @errorName(err) }); | |
| 516 | + | std.log.warn( | |
| 517 | + | "pty write failed, {d} bytes lost: {s}", | |
| 518 | + | .{ remaining.len, @errorName(err) }, | |
| 519 | + | ); | |
| 496 | 520 | } | |
| 497 | 521 | return; | |
| 498 | 522 | }; |
| ... | ... | @@ -526,12 +550,18 @@ const Daemon = struct { | |
| 526 | 550 | // interfering with shell initialization (DA1 queries, etc.) | |
| 527 | 551 | if (self.has_pty_output and self.has_had_client) { | |
| 528 | 552 | const cursor = &term.screens.active.cursor; | |
| 529 | - | std.log.debug("cursor before serialize: x={d} y={d} pending_wrap={}", .{ cursor.x, cursor.y, cursor.pending_wrap }); | |
| 553 | + | std.log.debug( | |
| 554 | + | "cursor before serialize: x={d} y={d} pending_wrap={}", | |
| 555 | + | .{ cursor.x, cursor.y, cursor.pending_wrap }, | |
| 556 | + | ); | |
| 530 | 557 | if (util.serializeTerminalState(self.alloc, term)) |term_output| { | |
| 531 | 558 | std.log.debug("serialize terminal state", .{}); | |
| 532 | 559 | defer self.alloc.free(term_output); | |
| 533 | 560 | ipc.appendMessage(self.alloc, &client.write_buf, .Output, term_output) catch |err| { | |
| 534 | - | std.log.warn("failed to buffer terminal state for client err={s}", .{@errorName(err)}); | |
| 561 | + | std.log.warn( | |
| 562 | + | "failed to buffer terminal state for client err={s}", | |
| 563 | + | .{@errorName(err)}, | |
| 564 | + | ); | |
| 535 | 565 | }; | |
| 536 | 566 | client.has_pending_output = true; | |
| 537 | 567 | } |
| ... | ... | @@ -552,7 +582,12 @@ const Daemon = struct { | |
| 552 | 582 | std.log.debug("init resize rows={d} cols={d}", .{ resize.rows, resize.cols }); | |
| 553 | 583 | } | |
| 554 | 584 | ||
| 555 | - | pub fn handleResize(self: *Daemon, pty_fd: i32, term: *ghostty_vt.Terminal, payload: []const u8) !void { | |
| 585 | + | pub fn handleResize( | |
| 586 | + | self: *Daemon, | |
| 587 | + | pty_fd: i32, | |
| 588 | + | term: *ghostty_vt.Terminal, | |
| 589 | + | payload: []const u8, | |
| 590 | + | ) !void { | |
| 556 | 591 | if (payload.len != @sizeOf(ipc.Resize)) return; | |
| 557 | 592 | ||
| 558 | 593 | const resize = std.mem.bytesToValue(ipc.Resize, payload); |
| ... | ... | @@ -584,7 +619,8 @@ const Daemon = struct { | |
| 584 | 619 | pub fn handleKill(self: *Daemon) void { | |
| 585 | 620 | std.log.info("kill received session={s}", .{self.session_name}); | |
| 586 | 621 | self.shutdown(); | |
| 587 | - | // gracefully shutdown shell processes, shells tend to ignore SIGTERM so we send SIGHUP instead | |
| 622 | + | // gracefully shutdown shell processes, shells tend to ignore SIGTERM so we send SIGHUP | |
| 623 | + | // instead | |
| 588 | 624 | // https://www.gnu.org/software/bash/manual/html_node/Signals.html | |
| 589 | 625 | // negative pid means kill process and children | |
| 590 | 626 | std.log.info("sending SIGHUP session={s} pid={d}", .{ self.session_name, self.pid }); |
| ... | ... | @@ -653,7 +689,12 @@ const Daemon = struct { | |
| 653 | 689 | client.has_pending_output = true; | |
| 654 | 690 | } | |
| 655 | 691 | ||
| 656 | - | pub fn handleHistory(self: *Daemon, client: *Client, term: *ghostty_vt.Terminal, payload: []const u8) !void { | |
| 692 | + | pub fn handleHistory( | |
| 693 | + | self: *Daemon, | |
| 694 | + | client: *Client, | |
| 695 | + | term: *ghostty_vt.Terminal, | |
| 696 | + | payload: []const u8, | |
| 697 | + | ) !void { | |
| 657 | 698 | const format: util.HistoryFormat = if (payload.len > 0) | |
| 658 | 699 | std.meta.intToEnum(util.HistoryFormat, payload[0]) catch .plain | |
| 659 | 700 | else |
| ... | ... | @@ -784,7 +825,10 @@ fn wait(cfg: *Cfg, session_names: std.ArrayList([]const u8)) !void { | |
| 784 | 825 | // is no longer deleted, so this session would otherwise | |
| 785 | 826 | // persist as task_ended_at==0 forever → infinite "still | |
| 786 | 827 | // waiting". Count it as done+failed so wait terminates. | |
| 787 | - | try stderr.print("task unreachable: {s} ({s})\n", .{ session.name, session.error_name orelse "unknown" }); | |
| 828 | + | try stderr.print( | |
| 829 | + | "task unreachable: {s} ({s})\n", | |
| 830 | + | .{ session.name, session.error_name orelse "unknown" }, | |
| 831 | + | ); | |
| 788 | 832 | try stderr.flush(); | |
| 789 | 833 | agg_exit_code = 1; | |
| 790 | 834 | done += 1; |
| ... | ... | @@ -810,7 +854,10 @@ fn wait(cfg: *Cfg, session_names: std.ArrayList([]const u8)) !void { | |
| 810 | 854 | // crashed and the remaining N-1 happen to be done, total==done | |
| 811 | 855 | // would be a false success. | |
| 812 | 856 | if (total < max_seen) { | |
| 813 | - | try stderr.print("error: {d} session(s) disappeared before completing\n", .{max_seen - total}); | |
| 857 | + | try stderr.print( | |
| 858 | + | "error: {d} session(s) disappeared before completing\n", | |
| 859 | + | .{max_seen - total}, | |
| 860 | + | ); | |
| 814 | 861 | try stderr.flush(); | |
| 815 | 862 | std.process.exit(1); | |
| 816 | 863 | return; |
| ... | ... | @@ -943,7 +990,10 @@ fn kill(cfg: *Cfg, session_name: []const u8) !void { | |
| 943 | 990 | socket.cleanupStaleSocket(dir, session_name); | |
| 944 | 991 | w.interface.print("cleaned up stale session {s}\n", .{session_name}) catch {}; | |
| 945 | 992 | } else { | |
| 946 | - | w.interface.print("session {s} is unresponsive ({s}) -- daemon may be busy, try again or kill the process directly\n", .{ session_name, @errorName(err) }) catch {}; | |
| 993 | + | w.interface.print( | |
| 994 | + | "session {s} is unresponsive ({s}) -- daemon may be busy, try again or kill the process directly\n", | |
| 995 | + | .{ session_name, @errorName(err) }, | |
| 996 | + | ) catch {}; | |
| 947 | 997 | } | |
| 948 | 998 | w.interface.flush() catch {}; | |
| 949 | 999 | return; |
| ... | ... | @@ -1193,7 +1243,9 @@ fn run(daemon: *Daemon, command_args: [][]const u8) !void { | |
| 1193 | 1243 | else => return err, | |
| 1194 | 1244 | }; | |
| 1195 | 1245 | ||
| 1196 | - | var poll_fds = [_]posix.pollfd{.{ .fd = probe_result.fd, .events = posix.POLL.IN, .revents = 0 }}; | |
| 1246 | + | var poll_fds = [_]posix.pollfd{ | |
| 1247 | + | .{ .fd = probe_result.fd, .events = posix.POLL.IN, .revents = 0 }, | |
| 1248 | + | }; | |
| 1197 | 1249 | const poll_result = posix.poll(&poll_fds, 5000) catch return error.PollFailed; | |
| 1198 | 1250 | if (poll_result == 0) { | |
| 1199 | 1251 | std.log.err("timeout waiting for ack", .{}); |
| ... | ... | @@ -1297,7 +1349,8 @@ fn clientLoop(client_sock_fd: i32) !void { | |
| 1297 | 1349 | }; | |
| 1298 | 1350 | ||
| 1299 | 1351 | // Handle stdin -> socket (Input) | |
| 1300 | - | if (poll_fds.items[0].revents & (posix.POLL.IN | posix.POLL.HUP | posix.POLL.ERR | posix.POLL.NVAL) != 0) { | |
| 1352 | + | const inp_flags = (posix.POLL.IN | posix.POLL.HUP | posix.POLL.ERR | posix.POLL.NVAL); | |
| 1353 | + | if (poll_fds.items[0].revents & inp_flags != 0) { | |
| 1301 | 1354 | var buf: [4096]u8 = undefined; | |
| 1302 | 1355 | const n_opt: ?usize = posix.read(stdin_fd, &buf) catch |err| blk: { | |
| 1303 | 1356 | if (err == error.WouldBlock) break :blk null; |
| ... | ... | @@ -1397,7 +1450,10 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1397 | 1450 | ||
| 1398 | 1451 | daemon_loop: while (daemon.running) { | |
| 1399 | 1452 | if (sigterm_received.swap(false, .acq_rel)) { | |
| 1400 | - | std.log.info("SIGTERM received, shutting down gracefully session={s}", .{daemon.session_name}); | |
| 1453 | + | std.log.info( | |
| 1454 | + | "SIGTERM received, shutting down gracefully session={s}", | |
| 1455 | + | .{daemon.session_name}, | |
| 1456 | + | ); | |
| 1401 | 1457 | break :daemon_loop; | |
| 1402 | 1458 | } | |
| 1403 | 1459 |
| ... | ... | @@ -1436,7 +1492,12 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1436 | 1492 | std.log.err("server socket error revents={d}", .{poll_fds.items[0].revents}); | |
| 1437 | 1493 | break :daemon_loop; | |
| 1438 | 1494 | } else if (poll_fds.items[0].revents & posix.POLL.IN != 0) { | |
| 1439 | - | const client_fd = try posix.accept(server_sock_fd, null, null, posix.SOCK.NONBLOCK | posix.SOCK.CLOEXEC); | |
| 1495 | + | const client_fd = try posix.accept( | |
| 1496 | + | server_sock_fd, | |
| 1497 | + | null, | |
| 1498 | + | null, | |
| 1499 | + | posix.SOCK.NONBLOCK | posix.SOCK.CLOEXEC, | |
| 1500 | + | ); | |
| 1440 | 1501 | const client = try daemon.alloc.create(Client); | |
| 1441 | 1502 | client.* = Client{ | |
| 1442 | 1503 | .alloc = daemon.alloc, |
| ... | ... | @@ -1446,10 +1507,14 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1446 | 1507 | }; | |
| 1447 | 1508 | client.write_buf = try std.ArrayList(u8).initCapacity(client.alloc, 4096); | |
| 1448 | 1509 | try daemon.clients.append(daemon.alloc, client); | |
| 1449 | - | std.log.info("client connected fd={d} total={d}", .{ client_fd, daemon.clients.items.len }); | |
| 1510 | + | std.log.info( | |
| 1511 | + | "client connected fd={d} total={d}", | |
| 1512 | + | .{ client_fd, daemon.clients.items.len }, | |
| 1513 | + | ); | |
| 1450 | 1514 | } | |
| 1451 | 1515 | ||
| 1452 | - | if (poll_fds.items[1].revents & (posix.POLL.IN | posix.POLL.HUP | posix.POLL.ERR | posix.POLL.NVAL) != 0) { | |
| 1516 | + | const inp_flags = posix.POLL.IN | posix.POLL.HUP | posix.POLL.ERR | posix.POLL.NVAL; | |
| 1517 | + | if (poll_fds.items[1].revents & inp_flags != 0) { | |
| 1453 | 1518 | // Read from PTY | |
| 1454 | 1519 | var buf: [4096]u8 = undefined; | |
| 1455 | 1520 | const n_opt: ?usize = posix.read(pty_fd, &buf) catch |err| blk: { |
| ... | ... | @@ -1490,7 +1555,10 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1490 | 1555 | // Broadcast data to all clients | |
| 1491 | 1556 | for (daemon.clients.items) |client| { | |
| 1492 | 1557 | ipc.appendMessage(daemon.alloc, &client.write_buf, .Output, buf[0..n]) catch |err| { | |
| 1493 | - | std.log.warn("failed to buffer output for client err={s}", .{@errorName(err)}); | |
| 1558 | + | std.log.warn( | |
| 1559 | + | "failed to buffer output for client err={s}", | |
| 1560 | + | .{@errorName(err)}, | |
| 1561 | + | ); | |
| 1494 | 1562 | continue; | |
| 1495 | 1563 | }; | |
| 1496 | 1564 | client.has_pending_output = true; |
| ... | ... | @@ -1505,7 +1573,8 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1505 | 1573 | // So number of clients in poll_fds is poll_fds.items.len - 2 | |
| 1506 | 1574 | const num_polled_clients = poll_fds.items.len - 2; | |
| 1507 | 1575 | if (i > num_polled_clients) { | |
| 1508 | - | // If we have more clients than polled (i.e. we just accepted one), start from the polled ones | |
| 1576 | + | // If we have more clients than polled (i.e. we just accepted one), start from the | |
| 1577 | + | // polled ones | |
| 1509 | 1578 | i = num_polled_clients; | |
| 1510 | 1579 | } | |
| 1511 | 1580 |
| ... | ... | @@ -1517,7 +1586,10 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1517 | 1586 | if (revents & posix.POLL.IN != 0) { | |
| 1518 | 1587 | const n = client.read_buf.read(client.socket_fd) catch |err| { | |
| 1519 | 1588 | if (err == error.WouldBlock) continue; | |
| 1520 | - | std.log.debug("client read err={s} fd={d}", .{ @errorName(err), client.socket_fd }); | |
| 1589 | + | std.log.debug( | |
| 1590 | + | "client read err={s} fd={d}", | |
| 1591 | + | .{ @errorName(err), client.socket_fd }, | |
| 1592 | + | ); | |
| 1521 | 1593 | const last = daemon.closeClient(client, i, false); | |
| 1522 | 1594 | if (last) break :daemon_loop; | |
| 1523 | 1595 | continue; |
| ... | ... | @@ -1550,7 +1622,10 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void { | |
| 1550 | 1622 | .History => try daemon.handleHistory(client, &term, msg.payload), | |
| 1551 | 1623 | .Run => try daemon.handleRun(client, pty_fd, msg.payload), | |
| 1552 | 1624 | .Output, .Ack => {}, | |
| 1553 | - | _ => std.log.warn("ignoring unknown IPC tag={d}", .{@intFromEnum(msg.header.tag)}), | |
| 1625 | + | _ => std.log.warn( | |
| 1626 | + | "ignoring unknown IPC tag={d}", | |
| 1627 | + | .{@intFromEnum(msg.header.tag)}, | |
| 1628 | + | ), | |
| 1554 | 1629 | } | |
| 1555 | 1630 | } | |
| 1556 | 1631 | } |
+10,
-2
| ... | ... | @@ -58,7 +58,11 @@ pub fn createSocket(fname: []const u8) !i32 { | |
| 58 | 58 | // AF.UNIX: Unix domain socket for local IPC with client processes | |
| 59 | 59 | // SOCK.STREAM: Reliable, bidirectional communication | |
| 60 | 60 | // SOCK.NONBLOCK: Set socket to non-blocking | |
| 61 | - | const fd = try posix.socket(posix.AF.UNIX, posix.SOCK.STREAM | posix.SOCK.NONBLOCK | posix.SOCK.CLOEXEC, 0); | |
| 61 | + | const fd = try posix.socket( | |
| 62 | + | posix.AF.UNIX, | |
| 63 | + | posix.SOCK.STREAM | posix.SOCK.NONBLOCK | posix.SOCK.CLOEXEC, | |
| 64 | + | 0, | |
| 65 | + | ); | |
| 62 | 66 | errdefer posix.close(fd); | |
| 63 | 67 | ||
| 64 | 68 | var unix_addr = try std.net.Address.initUnix(fname); |
| ... | ... | @@ -74,7 +78,11 @@ pub const max_socket_path_len: usize = @typeInfo( | |
| 74 | 78 | @TypeOf(@as(posix.sockaddr.un, undefined).path), | |
| 75 | 79 | ).array.len - 1; | |
| 76 | 80 | ||
| 77 | - | pub fn getSocketPath(alloc: std.mem.Allocator, socket_dir: []const u8, session_name: []const u8) error{ NameTooLong, OutOfMemory }![]const u8 { | |
| 81 | + | pub fn getSocketPath( | |
| 82 | + | alloc: std.mem.Allocator, | |
| 83 | + | socket_dir: []const u8, | |
| 84 | + | session_name: []const u8, | |
| 85 | + | ) error{ NameTooLong, OutOfMemory }![]const u8 { | |
| 78 | 86 | const dir = socket_dir; | |
| 79 | 87 | const path_len = dir.len + 1 + session_name.len; | |
| 80 | 88 | if (path_len > max_socket_path_len) return error.NameTooLong; |
+17,
-4
| ... | ... | @@ -27,7 +27,10 @@ pub const SessionEntry = struct { | |
| 27 | 27 | } | |
| 28 | 28 | }; | |
| 29 | 29 | ||
| 30 | - | pub fn get_session_entries(alloc: std.mem.Allocator, socket_dir: []const u8) !std.ArrayList(SessionEntry) { | |
| 30 | + | pub fn get_session_entries( | |
| 31 | + | alloc: std.mem.Allocator, | |
| 32 | + | socket_dir: []const u8, | |
| 33 | + | ) !std.ArrayList(SessionEntry) { | |
| 31 | 34 | var dir = try std.fs.openDirAbsolute(socket_dir, .{ .iterate = true }); | |
| 32 | 35 | defer dir.close(); | |
| 33 | 36 | var iter = dir.iterate(); |
| ... | ... | @@ -102,7 +105,8 @@ pub fn shellNeedsQuoting(arg: []const u8) bool { | |
| 102 | 105 | if (arg.len == 0) return true; | |
| 103 | 106 | for (arg) |ch| { | |
| 104 | 107 | switch (ch) { | |
| 105 | - | ' ', '\t', '"', '\'', '\\', '$', '`', '!', '(', ')', '{', '}', '[', ']', '|', '&', ';', '<', '>', '?', '*', '~', '#', '\n' => return true, | |
| 108 | + | ' ', '\t', '"', '\'', '\\', '$', '`', '!', '(', ')', '{', '}', '[', ']' => return true, | |
| 109 | + | '|', '&', ';', '<', '>', '?', '*', '~', '#', '\n' => return true, | |
| 106 | 110 | else => {}, | |
| 107 | 111 | } | |
| 108 | 112 | } |
| ... | ... | @@ -333,7 +337,11 @@ pub const HistoryFormat = enum(u8) { | |
| 333 | 337 | html = 2, | |
| 334 | 338 | }; | |
| 335 | 339 | ||
| 336 | - | pub fn serializeTerminal(alloc: std.mem.Allocator, term: *ghostty_vt.Terminal, format: HistoryFormat) ?[]const u8 { | |
| 340 | + | pub fn serializeTerminal( | |
| 341 | + | alloc: std.mem.Allocator, | |
| 342 | + | term: *ghostty_vt.Terminal, | |
| 343 | + | format: HistoryFormat, | |
| 344 | + | ) ?[]const u8 { | |
| 337 | 345 | var builder: std.Io.Writer.Allocating = .init(alloc); | |
| 338 | 346 | defer builder.deinit(); | |
| 339 | 347 |
| ... | ... | @@ -378,7 +386,12 @@ pub fn detectShell() [:0]const u8 { | |
| 378 | 386 | ||
| 379 | 387 | /// Formats a session entry for list output (only the name when `short` is | |
| 380 | 388 | /// true), adding a prefix to indicate the current session, if there is one. | |
| 381 | - | pub fn writeSessionLine(writer: *std.Io.Writer, session: SessionEntry, short: bool, current_session: ?[]const u8) !void { | |
| 389 | + | pub fn writeSessionLine( | |
| 390 | + | writer: *std.Io.Writer, | |
| 391 | + | session: SessionEntry, | |
| 392 | + | short: bool, | |
| 393 | + | current_session: ?[]const u8, | |
| 394 | + | ) !void { | |
| 382 | 395 | const current_arrow = "→"; | |
| 383 | 396 | const prefix = if (current_session) |current| | |
| 384 | 397 | if (std.mem.eql(u8, current, session.name)) current_arrow ++ " " else " " |