Merge pull request #141 from mitchellh/f-confirm-close-surface

Allow configuring confirm close surface
This commit is contained in:
Mitchell Hashimoto
2023-04-06 09:05:22 -07:00
committed by GitHub
2 changed files with 22 additions and 1 deletions

View File

@ -140,6 +140,7 @@ const DerivedConfig = struct {
clipboard_read: bool, clipboard_read: bool,
clipboard_write: bool, clipboard_write: bool,
clipboard_trim_trailing_spaces: bool, clipboard_trim_trailing_spaces: bool,
confirm_close_surface: bool,
mouse_interval: u64, mouse_interval: u64,
pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig { pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig {
@ -153,6 +154,7 @@ const DerivedConfig = struct {
.clipboard_read = config.@"clipboard-read", .clipboard_read = config.@"clipboard-read",
.clipboard_write = config.@"clipboard-write", .clipboard_write = config.@"clipboard-write",
.clipboard_trim_trailing_spaces = config.@"clipboard-trim-trailing-spaces", .clipboard_trim_trailing_spaces = config.@"clipboard-trim-trailing-spaces",
.confirm_close_surface = config.@"confirm-close-surface",
.mouse_interval = config.@"click-repeat-interval" * 1_000_000, // 500ms .mouse_interval = config.@"click-repeat-interval" * 1_000_000, // 500ms
// Assignments happen sequentially so we have to do this last // Assignments happen sequentially so we have to do this last
@ -526,7 +528,22 @@ pub fn deinit(self: *Surface) void {
/// Close this surface. This will trigger the runtime to start the /// Close this surface. This will trigger the runtime to start the
/// close process, which should ultimately deinitialize this surface. /// close process, which should ultimately deinitialize this surface.
pub fn close(self: *Surface) void { pub fn close(self: *Surface) void {
self.rt_surface.close(!self.child_exited); 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;
// 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;
}
break :process_alive process_alive;
};
self.rt_surface.close(process_alive);
} }
/// Called from the app thread to handle mailbox messages to our specific /// Called from the app thread to handle mailbox messages to our specific

View File

@ -164,6 +164,10 @@ pub const Config = struct {
/// Additional configuration files to read. /// Additional configuration files to read.
@"config-file": RepeatableString = .{}, @"config-file": RepeatableString = .{},
// Confirms that a surface should be closed before closing it. This defaults
// to true. If set to false, surfaces will close without any confirmation.
@"confirm-close-surface": bool = true,
/// This is set by the CLI parser for deinit. /// This is set by the CLI parser for deinit.
_arena: ?ArenaAllocator = null, _arena: ?ArenaAllocator = null,