feat: remove single trailing new line in shell_execute_insert

This commit is contained in:
CJ van den Berg 2025-01-15 11:26:17 +01:00
parent 1c5dc9064d
commit 9d6b760f03
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -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 });