From ecd27791e4a5d2ebd812e98ab198a6d4588cfc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Tue, 12 May 2026 15:10:06 +0200 Subject: [PATCH] terminal: skip isocline setup in script mode Prevents unwanted terminal probes (ESC[6n) when not in REPL mode by wrapping Isocline initialization in a conditional. --- src/agent/Terminal.zig | 43 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/agent/Terminal.zig b/src/agent/Terminal.zig index d732310f..79e41e2f 100644 --- a/src/agent/Terminal.zig +++ b/src/agent/Terminal.zig @@ -66,25 +66,30 @@ pub fn attachCompleter(self: *Self, schemas: []const SlashCommand.SchemaInfo) vo } pub fn init(allocator: std.mem.Allocator, history_path: ?[:0]const u8, verbosity: Verbosity, is_repl: bool) Self { - _ = c.ic_enable_multiline(true); - _ = c.ic_enable_hint(true); - _ = c.ic_enable_inline_help(true); - // Show ghost completions instantly; isocline's default is 400 ms. - _ = c.ic_set_hint_delay(0); - _ = c.ic_enable_brace_insertion(true); - // `ps-*` namespace avoids colliding with isocline's built-in `ic-*` styles. - c.ic_style_def(style_cmd, "ansi-cyan bold"); - c.ic_style_def(style_slash, "ansi-magenta bold"); - c.ic_style_def(style_string, "ansi-green"); - c.ic_style_def(style_var, "ansi-yellow bold"); - c.ic_style_def(style_url, "ansi-blue underline"); - c.ic_style_def(style_key, "ansi-cyan"); - c.ic_style_def(style_num, "ansi-yellow"); - c.ic_style_def(style_err, "ansi-red"); - c.ic_set_default_highlighter(&highlighterCallback, null); - _ = c.ic_enable_highlight(true); - if (history_path) |path| { - c.ic_set_history(path.ptr, -1); // -1 → 200-entry default cap + // Isocline probes the terminal on init (writes ESC[6n cursor-report on + // stdout), so skip the whole setup in script-only mode — `ic_readline` is + // never reached there anyway. + if (is_repl) { + _ = c.ic_enable_multiline(true); + _ = c.ic_enable_hint(true); + _ = c.ic_enable_inline_help(true); + // Show ghost completions instantly; isocline's default is 400 ms. + _ = c.ic_set_hint_delay(0); + _ = c.ic_enable_brace_insertion(true); + // `ps-*` namespace avoids colliding with isocline's built-in `ic-*` styles. + c.ic_style_def(style_cmd, "ansi-cyan bold"); + c.ic_style_def(style_slash, "ansi-magenta bold"); + c.ic_style_def(style_string, "ansi-green"); + c.ic_style_def(style_var, "ansi-yellow bold"); + c.ic_style_def(style_url, "ansi-blue underline"); + c.ic_style_def(style_key, "ansi-cyan"); + c.ic_style_def(style_num, "ansi-yellow"); + c.ic_style_def(style_err, "ansi-red"); + c.ic_set_default_highlighter(&highlighterCallback, null); + _ = c.ic_enable_highlight(true); + if (history_path) |path| { + c.ic_set_history(path.ptr, -1); // -1 → 200-entry default cap + } } const stderr_is_tty = std.posix.isatty(std.posix.STDERR_FILENO); return .{