From e7e47006fe3aa038f6e94fea6910f1dd6e5f7e5e Mon Sep 17 00:00:00 2001 From: Lee Penkman Date: Sun, 1 Mar 2026 20:29:38 +1300 Subject: [PATCH 1/2] fix: update build.zig for new std.ArrayList API Replace .writer() pattern with direct *std.ArrayList and .print() method calls to support newer zig versions. Co-Authored-By: Claude Opus 4.6 --- build.zig | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/build.zig b/build.zig index 8d3c126e..4e73eb4b 100644 --- a/build.zig +++ b/build.zig @@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void { var version: std.ArrayList(u8) = .empty; defer version.deinit(b.allocator); - gen_version(b, version.writer(b.allocator)) catch |e| { + gen_version(b, &version) catch |e| { if (b.release_mode != .off) std.debug.panic("gen_version failed: {any}", .{e}); version.clearAndFree(b.allocator); @@ -274,7 +274,7 @@ pub fn build_exe( var version_info: std.ArrayList(u8) = .empty; defer version_info.deinit(b.allocator); - gen_version_info(b, target, version_info.writer(b.allocator), optimize) catch |e| { + gen_version_info(b, target, &version_info, optimize) catch |e| { if (b.release_mode != .off) std.debug.panic("gen_version failed: {any}", .{e}); version_info.clearAndFree(b.allocator); @@ -815,7 +815,7 @@ pub fn build_exe( fn gen_version_info( b: *std.Build, target: std.Build.ResolvedTarget, - writer: anytype, + out: *std.ArrayList(u8), optimize: std.builtin.OptimizeMode, ) !void { var code: u8 = 0; @@ -835,7 +835,7 @@ fn gen_version_info( const tracking_remote_ = if (tracking_remote_name.len > 0) blk: { var remote_config_path: std.ArrayList(u8) = .empty; defer remote_config_path.deinit(b.allocator); - try remote_config_path.writer(b.allocator).print("remote.{s}.url", .{tracking_remote_name}); + try remote_config_path.print(b.allocator, "remote.{s}.url", .{tracking_remote_name}); break :blk b.runAllowFail(&[_][]const u8{ "git", "config", remote_config_path.items }, &code, .Ignore) catch "(remote not found)"; } else ""; const remote_ = b.runAllowFail(&[_][]const u8{ "git", "config", "remote.origin.url" }, &code, .Ignore) catch "(origin not found)"; @@ -854,7 +854,7 @@ fn gen_version_info( const diff = std.mem.trimRight(u8, diff_, "\r\n "); const target_triple = try target.result.zigTriple(b.allocator); - try writer.print("Flow Control: a programmer's text editor\n\nversion: {s}{s}\ncommitted: {s}\ntarget: {s}\n", .{ + try out.print(b.allocator, "Flow Control: a programmer's text editor\n\nversion: {s}{s}\ncommitted: {s}\ntarget: {s}\n", .{ version, if (diff.len > 0) "-dirty" else "", date, @@ -862,21 +862,21 @@ fn gen_version_info( }); if (branch.len > 0) if (tracking_branch.len > 0) - try writer.print("branch: {s} tracking {s} at {s}\n", .{ branch, tracking_branch, tracking_remote }) + try out.print(b.allocator, "branch: {s} tracking {s} at {s}\n", .{ branch, tracking_branch, tracking_remote }) else - try writer.print("branch: {s} at {s}\n", .{ branch, remote }); + try out.print(b.allocator, "branch: {s} at {s}\n", .{ branch, remote }); - try writer.print("built-with: zig {s} ({t})\n", .{ builtin.zig_version_string, builtin.zig_backend }); - try writer.print("build-mode: {t}\n", .{optimize}); + try out.print(b.allocator, "built-with: zig {s} ({t})\n", .{ builtin.zig_version_string, builtin.zig_backend }); + try out.print(b.allocator, "build-mode: {t}\n", .{optimize}); if (log.len > 0) - try writer.print("\nbranched off {s} @ {s} with the following diverging commits:\n{s}\n", .{ tracking_branch, describe_base_commit, log }); + try out.print(b.allocator, "\nbranched off {s} @ {s} with the following diverging commits:\n{s}\n", .{ tracking_branch, describe_base_commit, log }); if (diff.len > 0) - try writer.print("\nwith the following uncommited changes:\n\n{s}\n", .{diff}); + try out.print(b.allocator, "\nwith the following uncommited changes:\n\n{s}\n", .{diff}); } -fn gen_version(b: *std.Build, writer: anytype) !void { +fn gen_version(b: *std.Build, out: *std.ArrayList(u8)) !void { var code: u8 = 0; const describe = try b.runAllowFail(&[_][]const u8{ "git", "describe", "--always", "--tags" }, &code, .Ignore); @@ -884,5 +884,5 @@ fn gen_version(b: *std.Build, writer: anytype) !void { const diff = std.mem.trimRight(u8, diff_, "\r\n "); const version = std.mem.trimRight(u8, describe, "\r\n "); - try writer.print("{s}{s}", .{ version, if (diff.len > 0) "-dirty" else "" }); + try out.print(b.allocator, "{s}{s}", .{ version, if (diff.len > 0) "-dirty" else "" }); } From ad9964de4f14ddf0175bc2eeaef12af3f59a210c Mon Sep 17 00:00:00 2001 From: Lee Penkman Date: Thu, 5 Mar 2026 21:26:33 +1300 Subject: [PATCH 2/2] fix: port codebase to Zig 0.16 API changes Migrate from removed/renamed APIs: std.io -> std.Io, ArrayList.writer() -> ArrayList.print(), fixedBufferStream -> Io.Writer.fixed, File.readToEndAlloc -> reader().interface.allocRemaining, std.fmt.Formatter -> inline struct, MemoryAccessor removal, and generic Writer/BufferedWriter type removal. Co-Authored-By: Claude Opus 4.6 --- build.zig.zon | 4 ++++ src/Project.zig | 34 +++++++++++++-------------- src/buffer/unicode.zig | 5 ++-- src/list_languages.zig | 6 ++--- src/log.zig | 4 ++-- src/lsp_config.zig | 8 +++++-- src/main.zig | 18 ++++++++++---- src/renderer/vaxis/renderer.zig | 2 +- src/renderer/vaxis/std/debug.zig | 26 +++++++------------- src/ripgrep.zig | 10 -------- src/shell.zig | 10 -------- src/text_manip.zig | 33 ++++++++++++-------------- src/tui/editor.zig | 26 ++++++++++---------- src/tui/home.zig | 32 ++++++++++++------------- src/tui/logview.zig | 2 +- src/tui/mainview.zig | 11 ++++----- src/tui/mode/mini/file_browser.zig | 3 +-- src/tui/mode/overlay/task_palette.zig | 4 ++-- src/tui/status/branch.zig | 19 +++++++-------- src/tui/status/clock.zig | 7 +++--- src/tui/status/diagstate.zig | 13 +++++----- src/tui/status/keybindstate.zig | 11 ++++----- src/tui/status/linenumstate.zig | 32 ++++++++++++------------- src/tui/status/selectionstate.zig | 21 ++++++++--------- src/win32/d3d11.zig | 4 +++- src/win32/gui.zig | 8 +++---- 26 files changed, 163 insertions(+), 190 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index bd7db6ae..b0444172 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -42,6 +42,10 @@ .hash = "zigwin32-25.0.28-preview-AAAAAICM5AMResOGQnQ85mfe60TTOQeMtt7GRATUOKoP", .lazy = true, }, + .uucode = .{ + .url = "git+https://github.com/jacobsandlund/uucode?ref=zig-0.16#faab8894d753207878283d523add01817e23b805", + .hash = "uucode-0.2.0-ZZjBPl1XVACasBRHQowdN6_UB_jkKpOMgKSkGNEB1vSk", + }, .diffz = .{ .url = "git+https://github.com/ziglibs/diffz.git#fbdf690b87db6b1142bbce6d4906f90b09ce60bb", .hash = "diffz-0.0.1-G2tlIezMAQBwGNGDs7Hn_N25dWSjEzgR_FAx9GFAvCuZ", diff --git a/src/Project.zig b/src/Project.zig index 817ada81..c84f0232 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -2349,7 +2349,7 @@ fn send_lsp_init_request(self: *Self, from: tp.pid_ref, lsp: *const LSP, project const version = if (root.version.len > 0 and root.version[0] == 'v') root.version[1..] else root.version; const initializationOptions: struct { - pub fn cborEncode(ctx: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void { + pub fn cborEncode(ctx: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { if (ctx.language_server_options.len == 0) { try cbor.writeValue(writer, null); return; @@ -2727,24 +2727,22 @@ fn send_lsp_triggerCharacters(to: tp.pid_ref, project_path: []const u8, language }; } -fn fmt_lsp_name_func(bytes: []const u8) std.fmt.Formatter([]const u8, format_lsp_name_func) { - return .{ .data = bytes }; -} - -fn format_lsp_name_func( - bytes: []const u8, - writer: *std.Io.Writer, -) std.Io.Writer.Error!void { - var iter: []const u8 = bytes; - var len = cbor.decodeArrayHeader(&iter) catch return; - var first: bool = true; - while (len > 0) : (len -= 1) { - var value: []const u8 = undefined; - if (!(cbor.matchValue(&iter, cbor.extract(&value)) catch return)) - return; - if (first) first = false else try writer.writeAll(" "); - try writer.writeAll(value); +fn fmt_lsp_name_func(bytes: []const u8) struct { + data: []const u8, + pub fn format(self: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { + var iter: []const u8 = self.data; + var len = cbor.decodeArrayHeader(&iter) catch return; + var first: bool = true; + while (len > 0) : (len -= 1) { + var value: []const u8 = undefined; + if (!(cbor.matchValue(&iter, cbor.extract(&value)) catch return)) + return; + if (first) first = false else try writer.writeAll(" "); + try writer.writeAll(value); + } } +} { + return .{ .data = bytes }; } const eol = '\n'; diff --git a/src/buffer/unicode.zig b/src/buffer/unicode.zig index eca8f5e8..e84fdfc5 100644 --- a/src/buffer/unicode.zig +++ b/src/buffer/unicode.zig @@ -99,9 +99,8 @@ pub fn utf8_sanitize(allocator: std.mem.Allocator, input: []const u8) error{ UnexpectedSecondSurrogateHalf, }![]u8 { var output: std.ArrayListUnmanaged(u8) = .{}; - const writer = output.writer(allocator); var buf: [4]u8 = undefined; - for (input) |byte| try writer.writeAll(try raw_byte_to_utf8(byte, &buf)); + for (input) |byte| try output.appendSlice(allocator, try raw_byte_to_utf8(byte, &buf)); return output.toOwnedSlice(allocator); } @@ -117,7 +116,7 @@ fn utf8_write_transform_T(comptime View: anytype, comptime field: uucode.FieldEn var it = view.iterator(); while (it.nextCodepoint()) |cp| { const cp_ = switch (field) { - .simple_uppercase_mapping, .simple_lowercase_mapping => uucode.get(field, cp) orelse cp, + .simple_uppercase_mapping, .simple_lowercase_mapping => uucode.get(field, cp), .case_folding_simple => uucode.get(field, cp), else => @compileError(@tagName(field) ++ " is not a unicode transformation"), }; diff --git a/src/list_languages.zig b/src/list_languages.zig index 8296e87f..322db004 100644 --- a/src/list_languages.zig +++ b/src/list_languages.zig @@ -13,7 +13,7 @@ const checkmark_width = if (builtin.os.tag != .windows) 2 else 3; const success_mark = if (builtin.os.tag != .windows) "✓ " else "[y]"; const fail_mark = if (builtin.os.tag != .windows) "✘ " else "[n]"; -pub fn list(allocator: std.mem.Allocator, writer: *std.io.Writer, tty_config: std.io.tty.Config) !void { +pub fn list(allocator: std.mem.Allocator, writer: *std.Io.Writer, tty_config: std.Io.tty.Config) !void { var max_language_len: usize = 0; var max_langserver_len: usize = 0; var max_formatter_len: usize = 0; @@ -69,7 +69,7 @@ fn args_string_length(args_: ?[]const []const u8) usize { return len; } -fn write_checkmark(writer: anytype, success: bool, tty_config: std.io.tty.Config) !void { +fn write_checkmark(writer: anytype, success: bool, tty_config: std.Io.tty.Config) !void { try tty_config.setColor(writer, if (success) .green else .red); if (success) try writer.writeAll(success_mark) else try writer.writeAll(fail_mark); } @@ -79,7 +79,7 @@ fn write_segmented( args_: ?[]const []const u8, sep: []const u8, pad: ?usize, - tty_config: std.io.tty.Config, + tty_config: std.Io.tty.Config, ) !void { const args = args_ orelse return; var len: usize = 0; diff --git a/src/log.zig b/src/log.zig index 0be31e33..e345caed 100644 --- a/src/log.zig +++ b/src/log.zig @@ -176,12 +176,12 @@ pub const Logger = struct { // } else { var failed = false; - msg_fmt.writer(std.heap.c_allocator).print("{f}", .{msg_}) catch { + msg_fmt.print(std.heap.c_allocator, "{f}", .{msg_}) catch { failed = true; }; if (failed) { msg_fmt.clearRetainingCapacity(); - msg_fmt.writer(std.heap.c_allocator).print("{f}", .{std.ascii.hexEscape(msg_.buf, .lower)}) catch {}; + msg_fmt.print(std.heap.c_allocator, "{f}", .{std.ascii.hexEscape(msg_.buf, .lower)}) catch {}; } msg__ = msg_fmt.items; tp.trace(tp.channel.debug, .{ "log_err_fmt", msg__.len, msg__[0..@min(msg__.len, 128)] }); diff --git a/src/lsp_config.zig b/src/lsp_config.zig index a3219851..4c739d9d 100644 --- a/src/lsp_config.zig +++ b/src/lsp_config.zig @@ -9,7 +9,9 @@ fn get_project(project: []const u8, lsp_name: []const u8) ?[]const u8 { defer allocator.free(file_name); const file: std.fs.File = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null; defer file.close(); - return file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch return null; + var buf: [4096]u8 = undefined; + var r = file.reader(&buf); + return r.interface.allocRemaining(allocator, .unlimited) catch return null; } fn get_global(lsp_name: []const u8) ?[]const u8 { @@ -17,7 +19,9 @@ fn get_global(lsp_name: []const u8) ?[]const u8 { defer allocator.free(file_name); const file: std.fs.File = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null; defer file.close(); - return file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch return null; + var buf: [4096]u8 = undefined; + var r = file.reader(&buf); + return r.interface.allocRemaining(allocator, .unlimited) catch return null; } pub fn get_config_file_path(project: ?[]const u8, lsp_name: []const u8, scope: Scope, mode: Mode) ![]u8 { diff --git a/src/main.zig b/src/main.zig index b191faf5..b0b50f21 100644 --- a/src/main.zig +++ b/src/main.zig @@ -156,7 +156,7 @@ pub fn main() anyerror!void { return std.fs.File.stdout().writeAll(version_info); if (args.list_languages) { - const tty_config = std.io.tty.detectConfig(std.fs.File.stdout()); + const tty_config = std.Io.tty.detectConfig(std.fs.File.stdout()); return list_languages.list(a, stdout, tty_config); } @@ -542,7 +542,9 @@ fn read_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs: *[][] fn read_text_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: *[][]const u8, file_name: []const u8) !void { var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }); defer file.close(); - const content = try file.readToEndAlloc(allocator, 64 * 1024); + var read_buf: [4096]u8 = undefined; + var r = file.reader(&read_buf); + const content = try r.interface.allocRemaining(allocator, .limited(64 * 1024)); defer allocator.free(content); return parse_text_config_file(T, allocator, conf, bufs_, file_name, content); } @@ -581,7 +583,9 @@ pub fn parse_text_config_file(T: type, allocator: std.mem.Allocator, conf: *T, b fn read_json_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: *[][]const u8, file_name: []const u8) !void { var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }); defer file.close(); - const json = try file.readToEndAlloc(allocator, 64 * 1024); + var read_buf: [4096]u8 = undefined; + var r = file.reader(&read_buf); + const json = try r.interface.allocRemaining(allocator, .limited(64 * 1024)); defer allocator.free(json); const cbor_buf: []u8 = try allocator.alloc(u8, json.len); var bufs = std.ArrayListUnmanaged([]const u8).fromOwnedSlice(bufs_.*); @@ -854,7 +858,9 @@ pub fn read_keybind_namespace(allocator: std.mem.Allocator, namespace_name: []co const file_name = get_keybind_namespace_file_name(namespace_name) catch return null; var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null; defer file.close(); - return file.readToEndAlloc(allocator, 64 * 1024) catch null; + var read_buf: [4096]u8 = undefined; + var r = file.reader(&read_buf); + return r.interface.allocRemaining(allocator, .limited(64 * 1024)) catch null; } pub fn write_keybind_namespace(namespace_name: []const u8, content: []const u8) !void { @@ -882,7 +888,9 @@ pub fn read_theme(allocator: std.mem.Allocator, theme_name: []const u8) ?[]const const file_name = get_theme_file_name(theme_name) catch return null; var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null; defer file.close(); - return file.readToEndAlloc(allocator, 64 * 1024) catch null; + var read_buf: [4096]u8 = undefined; + var r = file.reader(&read_buf); + return r.interface.allocRemaining(allocator, .limited(64 * 1024)) catch null; } pub fn write_theme(theme_name: []const u8, content: []const u8) !void { diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index 3ed5f280..0f7e59a0 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -186,7 +186,7 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque unreachable; } -fn handleSegfaultPosixNoAbort(stderr: *std.io.Writer, sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void { +fn handleSegfaultPosixNoAbort(stderr: *std.Io.Writer, sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void { const debug = @import("std/debug.zig"); debug.resetSegfaultHandler(); const addr = switch (builtin.os.tag) { diff --git a/src/renderer/vaxis/std/debug.zig b/src/renderer/vaxis/std/debug.zig index bfe62fea..e8915db2 100644 --- a/src/renderer/vaxis/std/debug.zig +++ b/src/renderer/vaxis/std/debug.zig @@ -2,7 +2,7 @@ const builtin = @import("builtin"); const std = @import("std"); const math = std.math; const mem = std.mem; -const io = std.io; +const io = std.Io; const posix = std.posix; const fs = std.fs; const testing = std.testing; @@ -13,7 +13,6 @@ const native_arch = builtin.cpu.arch; const native_os = builtin.os.tag; const native_endian = native_arch.endian(); -pub const MemoryAccessor = std.debug.MemoryAccessor; pub const FixedBufferReader = std.debug.FixedBufferReader.zig; pub const Dwarf = std.debug.Dwarf; pub const Pdb = std.debug.Pdb; @@ -219,13 +218,13 @@ pub fn dumpHex(bytes: []const u8) void { /// Prints a hexadecimal view of the bytes, unbuffered, returning any error that occurs. pub fn dumpHexFallible(bytes: []const u8) !void { - const stderr = std.io.getStdErr(); - const ttyconf = std.io.tty.detectConfig(stderr); + const stderr = std.fs.File.stderr(); + const ttyconf = std.Io.tty.detectConfig(stderr); const writer = stderr.writer(); try dumpHexInternal(bytes, ttyconf, writer); } -fn dumpHexInternal(bytes: []const u8, ttyconf: std.io.tty.Config, writer: anytype) !void { +fn dumpHexInternal(bytes: []const u8, ttyconf: std.Io.tty.Config, writer: anytype) !void { var chunks = mem.window(u8, bytes, 16, 16); while (chunks.next()) |window| { // 1. Print the address. @@ -736,8 +735,6 @@ pub const StackIterator = struct { first_address: ?usize, // Last known value of the frame pointer register. fp: usize, - ma: MemoryAccessor = MemoryAccessor.init, - // When SelfInfo and a register context is available, this iterator can unwind // stacks with frames that don't use a frame pointer (ie. -fomit-frame-pointer), // using DWARF and MachO unwind info. @@ -788,7 +785,6 @@ pub const StackIterator = struct { } pub fn deinit(it: *StackIterator) void { - it.ma.deinit(); if (have_ucontext and it.unwind_state != null) it.unwind_state.?.dwarf_context.deinit(); } @@ -859,7 +855,6 @@ pub const StackIterator = struct { unwind_state.debug_info.allocator, module.base_address, &unwind_state.dwarf_context, - &it.ma, unwind_info, module.eh_frame, )) |return_address| { @@ -878,7 +873,6 @@ pub const StackIterator = struct { di, module.base_address, &unwind_state.dwarf_context, - &it.ma, null, ); } else return error.MissingDebugInfo; @@ -914,7 +908,7 @@ pub const StackIterator = struct { // Sanity check. if (fp == 0 or !mem.isAligned(fp, @alignOf(usize))) return null; - const new_fp = math.add(usize, it.ma.load(usize, fp) orelse return null, fp_bias) catch + const new_fp = math.add(usize, @as(*usize, @ptrFromInt(fp)).*, fp_bias) catch return null; // Sanity check: the stack grows down thus all the parent frames must be @@ -922,8 +916,7 @@ pub const StackIterator = struct { // A zero frame pointer often signals this is the last frame, that case // is gracefully handled by the next call to next_internal. if (new_fp != 0 and new_fp < it.fp) return null; - const new_pc = it.ma.load(usize, math.add(usize, fp, pc_offset) catch return null) orelse - return null; + const new_pc = @as(*usize, @ptrFromInt(math.add(usize, fp, pc_offset) catch return null)).*; it.fp = new_fp; @@ -1573,10 +1566,10 @@ test "manage resources correctly" { // self-hosted debug info is still too buggy if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest; - const writer = std.io.null_writer; + const writer = std.Io.null_writer; var di = try SelfInfo.open(testing.allocator); defer di.deinit(); - try printSourceAtAddress(&di, writer, showMyTrace(), io.tty.detectConfig(std.io.getStdErr())); + try printSourceAtAddress(&di, writer, showMyTrace(), io.tty.detectConfig(std.fs.File.stderr())); } noinline fn showMyTrace() usize { @@ -1642,7 +1635,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize pub fn dump(t: @This()) void { if (!enabled) return; - const tty_config = io.tty.detectConfig(std.io.getStdErr()); + const tty_config = io.tty.detectConfig(std.fs.File.stderr()); const stderr = io.getStdErr().writer(); const end = @min(t.index, size); const debug_info = getSelfDebugInfo() catch |err| { @@ -1737,7 +1730,6 @@ pub inline fn inValgrind() bool { test { _ = &Dwarf; - _ = &MemoryAccessor; _ = &FixedBufferReader; _ = &Pdb; _ = &SelfInfo; diff --git a/src/ripgrep.zig b/src/ripgrep.zig index b6c93946..62f5dbb7 100644 --- a/src/ripgrep.zig +++ b/src/ripgrep.zig @@ -10,8 +10,6 @@ stdin_behavior: std.process.Child.StdIo, const Self = @This(); const module_name = @typeName(Self); pub const max_chunk_size = tp.subprocess.max_chunk_size; -pub const Writer = std.io.Writer(*Self, Error, write); -pub const BufferedWriter = std.io.BufferedWriter(max_chunk_size, Writer); pub const Error = error{ OutOfMemory, Exit, ThespianSpawnFailed, Closed }; pub const FindF = fn (allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self; @@ -61,14 +59,6 @@ pub fn close(self: *Self) void { self.deinit(); } -pub fn writer(self: *Self) Writer { - return .{ .context = self }; -} - -pub fn bufferedWriter(self: *Self) BufferedWriter { - return .{ .unbuffered_writer = self.writer() }; -} - const Process = struct { allocator: std.mem.Allocator, query: []const u8, diff --git a/src/shell.zig b/src/shell.zig index 7e303908..117b432e 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -9,8 +9,6 @@ stdin_behavior: std.process.Child.StdIo, const Self = @This(); const module_name = @typeName(Self); pub const max_chunk_size = tp.subprocess.max_chunk_size; -pub const Writer = std.io.Writer(*Self, Error, write); -pub const BufferedWriter = std.io.BufferedWriter(max_chunk_size, Writer); pub const Error = error{ InvalidShellArg0, OutOfMemory, @@ -88,14 +86,6 @@ pub fn close(self: *Self) void { self.deinit(); } -pub fn writer(self: *Self) Writer { - return .{ .context = self }; -} - -pub fn bufferedWriter(self: *Self) BufferedWriter { - return .{ .unbuffered_writer = self.writer() }; -} - pub fn log_handler(context: usize, parent: tp.pid_ref, arg0: []const u8, output: []const u8) void { _ = context; _ = parent; diff --git a/src/text_manip.zig b/src/text_manip.zig index 54307dbc..2f2c8405 100644 --- a/src/text_manip.zig +++ b/src/text_manip.zig @@ -1,6 +1,4 @@ const std = @import("std"); -const TextWriter = std.ArrayList(u8).Writer; - pub fn find_first_non_ws(text: []const u8) ?usize { for (text, 0..) |c, i| if (c == ' ' or c == '\t') continue else return i; return null; @@ -30,34 +28,33 @@ pub fn find_prefix(prefix: []const u8, text: []const u8) ?usize { return null; } -fn add_prefix_in_line(prefix: []const u8, text: []const u8, writer: TextWriter, pos: usize) !void { +fn add_prefix_in_line(prefix: []const u8, text: []const u8, result: *std.ArrayList(u8), allocator: std.mem.Allocator, pos: usize) !void { if (text.len >= pos and find_first_non_ws(text) != null) { - _ = try writer.write(text[0..pos]); - _ = try writer.write(prefix); - _ = try writer.write(" "); - _ = try writer.write(text[pos..]); + try result.appendSlice(allocator, text[0..pos]); + try result.appendSlice(allocator, prefix); + try result.appendSlice(allocator, " "); + try result.appendSlice(allocator, text[pos..]); } else { - _ = try writer.write(text); + try result.appendSlice(allocator, text); } } -fn remove_prefix_in_line(prefix: []const u8, text: []const u8, writer: TextWriter) !void { +fn remove_prefix_in_line(prefix: []const u8, text: []const u8, result: *std.ArrayList(u8), allocator: std.mem.Allocator) !void { if (find_prefix(prefix, text)) |pos| { - _ = try writer.write(text[0..pos]); + try result.appendSlice(allocator, text[0..pos]); if (text.len > pos + prefix.len) { - _ = try if (text[pos + prefix.len] == ' ') - writer.write(text[pos + 1 + prefix.len ..]) + if (text[pos + prefix.len] == ' ') + try result.appendSlice(allocator, text[pos + 1 + prefix.len ..]) else - writer.write(text[pos + prefix.len ..]); + try result.appendSlice(allocator, text[pos + prefix.len ..]); } } else { - _ = try writer.write(text); + try result.appendSlice(allocator, text); } } pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: std.mem.Allocator) ![]const u8 { var result = try std.ArrayList(u8).initCapacity(allocator, prefix.len + text.len); - const writer = result.writer(allocator); var pos: usize = 0; var prefix_pos: usize = std.math.maxInt(usize); var have_prefix = true; @@ -80,11 +77,11 @@ pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: st pos = 0; while (std.mem.indexOfScalarPos(u8, text, pos, '\n')) |next| { if (have_prefix) { - try remove_prefix_in_line(prefix, text[pos..next], writer); + try remove_prefix_in_line(prefix, text[pos..next], &result, allocator); } else { - try add_prefix_in_line(prefix, text[pos..next], writer, prefix_pos); + try add_prefix_in_line(prefix, text[pos..next], &result, allocator, prefix_pos); } - _ = try writer.write("\n"); + try result.appendSlice(allocator, "\n"); pos = next + 1; } return result.toOwnedSlice(allocator); diff --git a/src/tui/editor.zig b/src/tui/editor.zig index bdac85ac..a051401d 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -266,7 +266,7 @@ pub const TriggerSymbol = struct { char: u8, command: command.ID, - pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void { + pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { try cbor.writeArrayHeader(writer, 2); try cbor.writeValue(writer, self.char); try cbor.writeValue(writer, command.get_name(self.command)); @@ -5853,9 +5853,10 @@ pub const Editor = struct { var rg = try find_f(self.allocator, query, "A"); defer rg.deinit(); if (write_buffer) { - var rg_buffer = rg.bufferedWriter(); - try root.store(rg_buffer.writer()); - try rg_buffer.flush(); + var output: std.Io.Writer.Allocating = .init(self.allocator); + defer output.deinit(); + try root.store_node(&output.writer, .lf); + try rg.input(output.writer.buffered()); } } @@ -5950,17 +5951,16 @@ pub const Editor = struct { if (fdr.matches.items.len == 0) return; var buf: [max_match_batch * @sizeOf(Match)]u8 = undefined; - var stream = std.io.fixedBufferStream(&buf); - const writer = stream.writer(); - try cbor.writeArrayHeader(writer, 4); - try cbor.writeValue(writer, "A"); - try cbor.writeValue(writer, "batch"); - try cbor.writeValue(writer, fdr.token); - try cbor.writeArrayHeader(writer, fdr.matches.items.len); + var stream = std.Io.Writer.fixed(&buf); + try cbor.writeArrayHeader(&stream, 4); + try cbor.writeValue(&stream, "A"); + try cbor.writeValue(&stream, "batch"); + try cbor.writeValue(&stream, fdr.token); + try cbor.writeArrayHeader(&stream, fdr.matches.items.len); for (fdr.matches.items) |m_| if (m_) |m| { - try cbor.writeArray(writer, .{ m.begin.row, m.begin.col, m.end.row, m.end.col }); + try cbor.writeArray(&stream, .{ m.begin.row, m.begin.col, m.end.row, m.end.col }); }; - try fdr.parent.send_raw(.{ .buf = stream.getWritten() }); + try fdr.parent.send_raw(.{ .buf = stream.buffered() }); fdr.matches.clearRetainingCapacity(); } }; diff --git a/src/tui/home.zig b/src/tui/home.zig index 9cdb16f0..23802bd1 100644 --- a/src/tui/home.zig +++ b/src/tui/home.zig @@ -171,17 +171,16 @@ fn add_menu_command(self: *Self, command_name: []const u8, description: []const const label_len = description.len + hint.len; var buf: [64]u8 = undefined; { - var fis = std.io.fixedBufferStream(&buf); - const writer = fis.writer(); + var fis = std.Io.Writer.fixed(&buf); const leader = if (hint.len > 0) "." else " "; - _ = try writer.write(description); - _ = try writer.write(" "); - _ = try writer.write(leader); - _ = try writer.write(leader); + _ = try fis.writeAll(description); + _ = try fis.writeAll(" "); + _ = try fis.writeAll(leader); + _ = try fis.writeAll(leader); for (0..(self.max_desc_len - label_len - 5)) |_| - _ = try writer.write(leader); - try writer.print(" :{s}", .{hint}); - const label = fis.getWritten(); + _ = try fis.writeAll(leader); + try fis.print(" :{s}", .{hint}); + const label = fis.buffered(); const padding = tui.get_widget_style(widget_type).padding; self.menu_label_max = @max(self.menu_label_max, label.len); self.menu_w = self.menu_label_max + 2 + padding.left + padding.right; @@ -237,16 +236,15 @@ fn menu_on_render(self: *Self, button: *ButtonType, theme: *const Widget.Theme, const label_len = description.len + hint.len; var buf: [64]u8 = undefined; const leader = blk: { - var fis = std.io.fixedBufferStream(&buf); - const writer = fis.writer(); + var fis = std.Io.Writer.fixed(&buf); const leader = if (hint.len > 0) "." else " "; - _ = writer.write(" ") catch return false; - _ = writer.write(leader) catch return false; - _ = writer.write(leader) catch return false; + _ = fis.writeAll(" ") catch return false; + _ = fis.writeAll(leader) catch return false; + _ = fis.writeAll(leader) catch return false; for (0..(self.max_desc_len - label_len - 5)) |_| - _ = writer.write(leader) catch return false; - writer.print(" ", .{}) catch return false; - break :blk fis.getWritten(); + _ = fis.writeAll(leader) catch return false; + fis.print(" ", .{}) catch return false; + break :blk fis.buffered(); }; const style_base = theme.editor; diff --git a/src/tui/logview.zig b/src/tui/logview.zig index 92a756a4..63470907 100644 --- a/src/tui/logview.zig +++ b/src/tui/logview.zig @@ -134,7 +134,7 @@ fn append_error(buffer: *Buffer, src: []const u8, context: []const u8, msg_: []c defer arena.deinit(); var sfa = std.heap.stackFallback(4096, arena.allocator()); var msg = std.array_list.Managed(u8).init(sfa.get()); - try fmt.format(msg.writer(), "error in {s}: {s}", .{ context, msg_ }); + try msg.print("error in {s}: {s}", .{ context, msg_ }); try append(buffer, src, msg.items, .err); } diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 178f7e55..b83ba203 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -770,7 +770,7 @@ const cmds = struct { defer name.deinit(self.allocator); while (!found_unique) { name.clearRetainingCapacity(); - try name.writer(self.allocator).print("Untitled-{d}", .{n}); + try name.print(self.allocator, "Untitled-{d}", .{n}); if (self.buffer_manager.get_buffer_for_file(name.items)) |_| { n += 1; } else { @@ -1408,14 +1408,13 @@ const cmds = struct { fn exit(context: usize, parent: tp.pid_ref, arg0: []const u8, err_msg: []const u8, exit_code: i64) void { const buffer_ref: Buffer.Ref = @enumFromInt(context); var buf: [256]u8 = undefined; - var stream = std.io.fixedBufferStream(&buf); - const writer = stream.writer(); + var stream = std.Io.Writer.fixed(&buf); if (exit_code > 0) { - writer.print("\n'{s}' terminated {s} exitcode: {d}\n", .{ arg0, err_msg, exit_code }) catch {}; + stream.print("\n'{s}' terminated {s} exitcode: {d}\n", .{ arg0, err_msg, exit_code }) catch {}; } else { - writer.print("\n'{s}' exited\n", .{arg0}) catch {}; + stream.print("\n'{s}' exited\n", .{arg0}) catch {}; } - parent.send(.{ "cmd", "shell_execute_stream_output", .{ buffer_ref, stream.getWritten() } }) catch {}; + parent.send(.{ "cmd", "shell_execute_stream_output", .{ buffer_ref, stream.buffered() } }) catch {}; parent.send(.{ "cmd", "shell_execute_stream_output_complete", .{buffer_ref} }) catch {}; } }; diff --git a/src/tui/mode/mini/file_browser.zig b/src/tui/mode/mini/file_browser.zig index e66b4d24..2d1809de 100644 --- a/src/tui/mode/mini/file_browser.zig +++ b/src/tui/mode/mini/file_browser.zig @@ -293,8 +293,7 @@ pub fn Create(options: type) type { else " "; self.rendered_mini_buffer.clearRetainingCapacity(); - const writer = self.rendered_mini_buffer.writer(self.allocator); - writer.print("{s} {s}", .{ icon, self.file_path.items }) catch {}; + self.rendered_mini_buffer.print(self.allocator, "{s} {s}", .{ icon, self.file_path.items }) catch {}; mini_mode.text = self.rendered_mini_buffer.items; mini_mode.cursor = tui.egc_chunk_width(self.file_path.items, 0, 1) + 3; } diff --git a/src/tui/mode/overlay/task_palette.zig b/src/tui/mode/overlay/task_palette.zig index 6dbaa1e7..83756b49 100644 --- a/src/tui/mode/overlay/task_palette.zig +++ b/src/tui/mode/overlay/task_palette.zig @@ -103,9 +103,9 @@ pub fn on_render_menu(palette: *Type, button: *Type.ButtonType, theme: *const Wi const id = command.get_id(command_name) orelse break :blk; if (command.get_icon(id)) |icon| - label_.writer(palette.allocator).print("{s} ", .{icon}) catch {}; + label_.print(palette.allocator, "{s} ", .{icon}) catch {}; if (command.get_description(id)) |desc| - label_.writer(palette.allocator).print("{s}", .{desc}) catch {}; + label_.print(palette.allocator, "{s}", .{desc}) catch {}; _ = button.plane.print("{s} ", .{label_.items}) catch {}; const hints = if (tui.input_mode()) |m| m.keybind_hints else @panic("no keybind hints"); diff --git a/src/tui/status/branch.zig b/src/tui/status/branch.zig index ec8d7f6d..3b6f811a 100644 --- a/src/tui/status/branch.zig +++ b/src/tui/status/branch.zig @@ -113,21 +113,20 @@ fn process_vcs_status(self: *Self, m: tp.message) MessageFilter.Error!bool { fn format(self: *Self, buf: []u8) []const u8 { const branch = self.status.branch orelse return ""; - var fbs = std.io.fixedBufferStream(buf); - const writer = fbs.writer(); - writer.print(" {s}{s}", .{ branch_symbol, branch }) catch {}; + var fbs = std.Io.Writer.fixed(buf); + fbs.print(" {s}{s}", .{ branch_symbol, branch }) catch {}; if (self.status.ahead) |ahead| if (ahead.len > 1 and ahead[1] != '0') - writer.print(" {s}{s}", .{ ahead_symbol, ahead[1..] }) catch {}; + fbs.print(" {s}{s}", .{ ahead_symbol, ahead[1..] }) catch {}; if (self.status.behind) |behind| if (behind.len > 1 and behind[1] != '0') - writer.print(" {s}{s}", .{ behind_symbol, behind[1..] }) catch {}; + fbs.print(" {s}{s}", .{ behind_symbol, behind[1..] }) catch {}; if (self.status.stash) |stash| if (stash.len > 0 and stash[0] != '0') - writer.print(" {s}{s}", .{ stash_symbol, stash }) catch {}; + fbs.print(" {s}{s}", .{ stash_symbol, stash }) catch {}; if (self.status.changed > 0) - writer.print(" {s}{d}", .{ changed_symbol, self.status.changed }) catch {}; + fbs.print(" {s}{d}", .{ changed_symbol, self.status.changed }) catch {}; if (self.status.untracked > 0) - writer.print(" {s}{d}", .{ untracked_symbol, self.status.untracked }) catch {}; - writer.print(" ", .{}) catch {}; - return fbs.getWritten(); + fbs.print(" {s}{d}", .{ untracked_symbol, self.status.untracked }) catch {}; + fbs.print(" ", .{}) catch {}; + return fbs.buffered(); } pub fn layout(self: *Self, btn: *ButtonType) Widget.Layout { diff --git a/src/tui/status/clock.zig b/src/tui/status/clock.zig index a2f99aa8..d04d5fb4 100644 --- a/src/tui/status/clock.zig +++ b/src/tui/status/clock.zig @@ -84,11 +84,10 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool { const dt = now.time(); var buf: [64]u8 = undefined; - var fbs = std.io.fixedBufferStream(&buf); - const writer = fbs.writer(); - std.fmt.format(writer, "{d:0>2}:{d:0>2}", .{ dt.hour, dt.minute }) catch {}; + var writer = std.Io.Writer.fixed(&buf); + writer.print("{d:0>2}:{d:0>2}", .{ dt.hour, dt.minute }) catch {}; - const value_str = fbs.getWritten(); + const value_str = writer.buffered(); for (value_str, 0..) |_, i| _ = self.plane.putstr(fonts.get_digit_ascii(value_str[i .. i + 1], self.style orelse .ascii)) catch {}; return false; } diff --git a/src/tui/status/diagstate.zig b/src/tui/status/diagstate.zig index d5082180..ccc58df8 100644 --- a/src/tui/status/diagstate.zig +++ b/src/tui/status/diagstate.zig @@ -52,13 +52,12 @@ pub fn render(self: *Self, btn: *ButtonType, theme: *const Widget.Theme) bool { } fn format(self: *Self) void { - var fbs = std.io.fixedBufferStream(&self.buf); - const writer = fbs.writer(); - if (self.errors > 0) std.fmt.format(writer, "  {d}", .{self.errors}) catch {}; - if (self.warnings > 0) std.fmt.format(writer, "  {d}", .{self.warnings}) catch {}; - if (self.info > 0) std.fmt.format(writer, "  {d}", .{self.info}) catch {}; - if (self.hints > 0) std.fmt.format(writer, "  {d}", .{self.hints}) catch {}; - self.rendered = @ptrCast(fbs.getWritten()); + var fbs = std.Io.Writer.fixed(&self.buf); + if (self.errors > 0) fbs.print("  {d}", .{self.errors}) catch {}; + if (self.warnings > 0) fbs.print("  {d}", .{self.warnings}) catch {}; + if (self.info > 0) fbs.print("  {d}", .{self.info}) catch {}; + if (self.hints > 0) fbs.print("  {d}", .{self.hints}) catch {}; + self.rendered = @ptrCast(fbs.buffered()); self.buf[self.rendered.len] = 0; } diff --git a/src/tui/status/keybindstate.zig b/src/tui/status/keybindstate.zig index 9b45c757..0d83e33a 100644 --- a/src/tui/status/keybindstate.zig +++ b/src/tui/status/keybindstate.zig @@ -28,13 +28,12 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { pub fn layout(_: *Self) Widget.Layout { var buf: [256]u8 = undefined; - var fbs = std.io.fixedBufferStream(&buf); - const writer = fbs.writer(); - writer.print(" ", .{}) catch {}; + var fbs = std.Io.Writer.fixed(&buf); + fbs.print(" ", .{}) catch {}; if (keybind.current_integer_argument()) |integer_argument| - writer.print("{}", .{integer_argument}) catch {}; - writer.print("{f} ", .{keybind.current_key_event_sequence_fmt()}) catch {}; - const len = fbs.getWritten().len; + fbs.print("{}", .{integer_argument}) catch {}; + fbs.print("{f} ", .{keybind.current_key_event_sequence_fmt()}) catch {}; + const len = fbs.buffered().len; return .{ .static = if (len > 0) len else 0 }; } diff --git a/src/tui/status/linenumstate.zig b/src/tui/status/linenumstate.zig index 4c566cbb..a5be7ff5 100644 --- a/src/tui/status/linenumstate.zig +++ b/src/tui/status/linenumstate.zig @@ -98,8 +98,7 @@ pub fn render(self: *Self, btn: *ButtonType, theme: *const Widget.Theme) bool { } fn format(self: *Self) void { - var fbs = std.io.fixedBufferStream(&self.buf); - const writer = fbs.writer(); + var fbs = std.Io.Writer.fixed(&self.buf); const eol_mode = switch (self.eol_mode) { .lf => "", .crlf => " ␍␊", @@ -108,56 +107,55 @@ fn format(self: *Self) void { .spaces, .auto => "", .tabs => " ⭾ ", }; - writer.print("{s}{s} ", .{ eol_mode, indent_mode }) catch {}; + fbs.print("{s}{s} ", .{ eol_mode, indent_mode }) catch {}; (blk: switch (self.mode orelse .default) { - .default => writer.print("Ln {f}, Col {f} ", .{ + .default => fbs.print("Ln {f}, Col {f} ", .{ digits_fmt(self, self.line + 1), digits_fmt(self, self.column + 1), }), - .compact => writer.print(" {f}:{f} ", .{ + .compact => fbs.print(" {f}:{f} ", .{ digits_fmt(self, self.line + 1), digits_fmt(self, self.column + 1), }), - .total => writer.print(" {f}:{f}/{f} ", .{ + .total => fbs.print(" {f}:{f}/{f} ", .{ digits_fmt(self, self.line + 1), digits_fmt(self, self.column + 1), digits_fmt(self, self.lines), }), .percent => { if (self.line == 0) - writer.print(" Top", .{}) catch {} + fbs.print(" Top", .{}) catch {} else if (self.line >= self.lines -| 1) - writer.print(" Bot", .{}) catch {} + fbs.print(" Bot", .{}) catch {} else { const percent = (self.line * 1000) / (self.lines * 10); - writer.print(" {f}%", .{digits_fmt(self, percent)}) catch {}; + fbs.print(" {f}%", .{digits_fmt(self, percent)}) catch {}; } continue :blk .compact; }, }) catch {}; - self.rendered = @ptrCast(fbs.getWritten()); + self.rendered = @ptrCast(fbs.buffered()); self.buf[self.rendered.len] = 0; } pub fn digits_fmt(self_: *Self, value: usize) struct { self: *Self, value: usize, - pub fn format(ctx: @This(), writer: anytype) std.Io.Writer.Error!void { + pub fn format(ctx: @This(), _: anytype) std.Io.Writer.Error!void { const self = ctx.self; const width = self.padding orelse 0; var buf: [64]u8 = undefined; - var fbs = std.io.fixedBufferStream(&buf); - const writer_ = fbs.writer(); - std.fmt.format(writer_, "{d}", .{ctx.value}) catch return error.WriteFailed; - const value_str = fbs.getWritten(); + var fbs = std.Io.Writer.fixed(&buf); + fbs.print("{d}", .{ctx.value}) catch return error.WriteFailed; + const value_str = fbs.buffered(); const char: []const u8 = switch (self.leader orelse .space) { .space => " ", .zero => "0", }; - for (0..(@max(value_str.len, width) - value_str.len)) |_| try writer.writeAll(fonts.get_digit_ascii(char, self.style orelse .ascii)); - for (value_str, 0..) |_, i| try writer.writeAll(fonts.get_digit_ascii(value_str[i .. i + 1], self.style orelse .ascii)); + for (0..(@max(value_str.len, width) - value_str.len)) |_| try fbs.writeAll(fonts.get_digit_ascii(char, self.style orelse .ascii)); + for (value_str, 0..) |_, i| try fbs.writeAll(fonts.get_digit_ascii(value_str[i .. i + 1], self.style orelse .ascii)); } } { return .{ .self = self_, .value = value }; diff --git a/src/tui/status/selectionstate.zig b/src/tui/status/selectionstate.zig index a8beb49a..5af3d076 100644 --- a/src/tui/status/selectionstate.zig +++ b/src/tui/status/selectionstate.zig @@ -51,31 +51,30 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool { } fn format(self: *Self) void { - var fbs = std.io.fixedBufferStream(&self.buf); - const writer = fbs.writer(); - _ = writer.write(" ") catch {}; + var fbs = std.Io.Writer.fixed(&self.buf); + _ = fbs.writeAll(" ") catch {}; if (self.matches > 1) { - std.fmt.format(writer, "({d} matches)", .{self.matches}) catch {}; + fbs.print("({d} matches)", .{self.matches}) catch {}; if (self.selection) |_| - _ = writer.write(" ") catch {}; + _ = fbs.writeAll(" ") catch {}; } if (self.cursels > 1) { - std.fmt.format(writer, "({d} cursors)", .{self.cursels}) catch {}; + fbs.print("({d} cursors)", .{self.cursels}) catch {}; if (self.selection) |_| - _ = writer.write(" ") catch {}; + _ = fbs.writeAll(" ") catch {}; } if (self.selection) |sel_| { var sel = sel_; sel.normalize(); const lines = sel.end.row - sel.begin.row; if (lines == 0) { - std.fmt.format(writer, "({d} columns selected)", .{sel.end.col - sel.begin.col}) catch {}; + fbs.print("({d} columns selected)", .{sel.end.col - sel.begin.col}) catch {}; } else { - std.fmt.format(writer, "({d} lines selected)", .{if (sel.end.col == 0) lines else lines + 1}) catch {}; + fbs.print("({d} lines selected)", .{if (sel.end.col == 0) lines else lines + 1}) catch {}; } } - _ = writer.write(" ") catch {}; - self.rendered = @ptrCast(fbs.getWritten()); + _ = fbs.writeAll(" ") catch {}; + self.rendered = @ptrCast(fbs.buffered()); self.buf[self.rendered.len] = 0; } diff --git a/src/win32/d3d11.zig b/src/win32/d3d11.zig index 938fd3c1..94bbb783 100644 --- a/src/win32/d3d11.zig +++ b/src/win32/d3d11.zig @@ -534,7 +534,9 @@ const Shaders = struct { .{ file_path, @errorName(e) }, ); defer file.close(); - break :blk file.readToEndAlloc(arena.allocator(), std.math.maxInt(usize)) catch |e| std.debug.panic( + var read_buf: [4096]u8 = undefined; + var r = file.reader(&read_buf); + break :blk r.interface.allocRemaining(arena.allocator(), .unlimited) catch |e| std.debug.panic( "read --shader '{s}' failed with {s}", .{ file_path, @errorName(e) }, ); diff --git a/src/win32/gui.zig b/src/win32/gui.zig index e770d7f4..6469afb6 100644 --- a/src/win32/gui.zig +++ b/src/win32/gui.zig @@ -601,11 +601,11 @@ const CellPos = struct { }; pub fn fmtmsg(buf: []u8, value: anytype) []const u8 { - var fbs = std.io.fixedBufferStream(buf); - cbor.writeValue(fbs.writer(), value) catch |e| switch (e) { - error.NoSpaceLeft => std.debug.panic("buffer of size {} not big enough", .{buf.len}), + var fbs = std.Io.Writer.fixed(buf); + cbor.writeValue(&fbs, value) catch |e| switch (e) { + error.WriteFailed => std.debug.panic("buffer of size {} not big enough", .{buf.len}), }; - return buf[0..fbs.pos]; + return fbs.buffered(); } const MouseFlags = packed struct(u8) {