From 7b651627d53568a13fb284700765a1fbdadae2fb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 27 May 2023 15:52:56 -0700 Subject: [PATCH] core: surface confirm close logic updated to handle semantic prompts --- src/Surface.zig | 20 ++++++++++---------- src/terminal/Terminal.zig | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 481847c20..2701919c4 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -529,18 +529,18 @@ pub fn deinit(self: *Surface) void { /// close process, which should ultimately deinitialize this surface. pub fn close(self: *Surface) void { const process_alive = process_alive: { - // Inform close() if it should hold open the surface or not. If the child - // exited, we don't want to - var process_alive = !self.child_exited; + // If the child has exited then our process is certainly not alive. + // We check this first to avoid the locking overhead below. + if (self.child_exited) break :process_alive false; - // However, if we are configured to not hold open surfaces explicitly, - // just tell close to not hold them open by saying there are no alive - // processes - if (!self.config.confirm_close_surface) { - process_alive = false; - } + // If we are configured to not hold open surfaces explicitly, just + // always say there is nothing alive. + if (!self.config.confirm_close_surface) break :process_alive false; - break :process_alive process_alive; + // We have to talk to the terminal. + self.renderer_state.mutex.lock(); + defer self.renderer_state.mutex.unlock(); + break :process_alive !self.io.terminal.cursorIsAtPrompt(); }; self.rt_surface.close(process_alive); diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index b29012563..56430991a 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1401,6 +1401,7 @@ pub fn setScrollingRegion(self: *Terminal, top: usize, bottom: usize) void { /// (OSC 133) only allow setting this for wherever the current active cursor /// is located. pub fn markSemanticPrompt(self: *Terminal, p: SemanticPrompt) void { + log.warn("semantic_prompt: {}", .{p}); const row = self.screen.getRow(.{ .active = self.screen.cursor.y }); row.setSemanticPrompt(switch (p) { .prompt => .prompt,