From 9d6b760f03739def6479a65d2ac6d222689640a1 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 15 Jan 2025 11:26:17 +0100 Subject: [PATCH] feat: remove single trailing new line in shell_execute_insert --- src/tui/mainview.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 3076ada..e253008 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -628,7 +628,20 @@ const cmds = struct { const cmd = ctx.args; const handlers = struct { fn out(parent: tp.pid_ref, _: []const u8, output: []const u8) void { - parent.send(.{ "cmd", "insert_chars", .{output} }) catch {}; + var pos: usize = 0; + var nl_count: usize = 0; + while (std.mem.indexOfScalarPos(u8, output, pos, '\n')) |next| { + pos = next + 1; + nl_count += 1; + } + const output_ = if (nl_count == 1 and output[output.len - 1] == '\n') + if (output.len > 2 and output[output.len - 2] == '\r') + output[0 .. output.len - 2] + else + output[0 .. output.len - 1] + else + output; + parent.send(.{ "cmd", "insert_chars", .{output_} }) catch {}; } }; try shell.execute(self.allocator, cmd, .{ .out = handlers.out });