From a3cfd26125bbb5fdb2872c1b3d511ccbf6f3fc4c Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 23 Aug 2021 02:31:06 -0700 Subject: emoji Former-commit-id: 812c1222bd62826a9bd829219970332d4b22bcd7 --- src/http.zig | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/http.zig b/src/http.zig index 4e08af858..316bbb802 100644 --- a/src/http.zig +++ b/src/http.zig @@ -1736,6 +1736,7 @@ pub const Server = struct { events: []watcher.WatchEvent, watchlist: watcher.Watchlist, comptime is_javascript_enabled: bool, + comptime is_emoji_enabled: bool, ) void { var fbs = std.io.fixedBufferStream(&filechange_buf); var writer = ByteApiWriter.init(&fbs); @@ -1750,11 +1751,12 @@ pub const Server = struct { const kinds = slice.items(.kind); const hashes = slice.items(.hash); const parent_hashes = slice.items(.parent_hash); - const fds = slice.items(.fd); var header = fbs.getWritten(); defer ctx.watcher.flushEvictions(); defer Output.flush(); + // It's important that this function does not do any memory allocations + // If this blocks, it can cause cascading bad things to happen for (events) |event| { const file_path = file_paths[event.index]; const update_count = counts[event.index] + 1; @@ -1801,7 +1803,12 @@ pub const Server = struct { RequestContext.WebsocketHandler.broadcast(written_buf) catch |err| { Output.prettyln("Error writing change notification: {s}", .{@errorName(err)}); }; - Output.prettyln("Detected edit: {s}", .{ctx.bundler.fs.relativeTo(file_path)}); + + if (comptime is_emoji_enabled) { + Output.prettyln("📜 File change: {s}", .{ctx.bundler.fs.relativeTo(file_path)}); + } else { + Output.prettyln(" File change: {s}", .{ctx.bundler.fs.relativeTo(file_path)}); + } } }, .directory => { @@ -1809,11 +1816,14 @@ pub const Server = struct { rfs.bustEntriesCache(file_path); ctx.bundler.resolver.dir_cache.remove(file_path); - if (event.op.delete or event.op.rename) { + if (event.op.delete or event.op.rename) ctx.watcher.removeAtIndex(event.index, hashes[event.index], parent_hashes, .directory); - } - Output.prettyln("Folder change: {s}", .{ctx.bundler.fs.relativeTo(file_path)}); + if (comptime is_emoji_enabled) { + Output.prettyln("📁 Dir change: {s}", .{ctx.bundler.fs.relativeTo(file_path)}); + } else { + Output.prettyln(" Dir change: {s}", .{ctx.bundler.fs.relativeTo(file_path)}); + } }, } } -- cgit v1.2.3