change name of config entry and variables, add lock for safety during config update

This commit is contained in:
Jeffrey C. Ollie
2024-01-09 10:07:32 -06:00
parent 342b5e9d06
commit 3c2dfd4a84
3 changed files with 27 additions and 15 deletions

View File

@ -10,8 +10,8 @@ operator.
## Implementation Details ## Implementation Details
The answerback can be configured in the config file using the `enquiry-string` The answerback can be configured in the config file using the `enquiry-response`
configuration setting or on the command line using the `--enquiry-string` configuration setting or on the command line using the `--enquiry-response`
parameter. The default is to send an empty string (`""`). parameter. The default is to send an empty string (`""`).
## References ## References

View File

@ -898,7 +898,7 @@ term: []const u8 = "xterm-ghostty",
/// String to send when we receive ENQ (0x05) from the command that we are /// String to send when we receive ENQ (0x05) from the command that we are
/// running. Defaults to "" if not set. /// running. Defaults to "" if not set.
@"enquiry-string": ?[]const u8 = null, @"enquiry-response": ?[]const u8 = null,
/// This is set by the CLI parser for deinit. /// This is set by the CLI parser for deinit.
_arena: ?ArenaAllocator = null, _arena: ?ArenaAllocator = null,

View File

@ -51,7 +51,7 @@ abnormal_runtime_threshold_ms: u32,
/// Equiry string - the string to send back when we receive a ENQ (0x05) /// Equiry string - the string to send back when we receive a ENQ (0x05)
/// from the process. /// from the process.
enquiry_string: ?[]const u8 = null, enquiry_response: ?[]const u8 = null,
/// The terminal emulator internal state. This is the abstract "terminal" /// The terminal emulator internal state. This is the abstract "terminal"
/// that manages input, grid updating, etc. and is renderer-agnostic. It /// that manages input, grid updating, etc. and is renderer-agnostic. It
@ -116,7 +116,7 @@ pub const DerivedConfig = struct {
term: []const u8, term: []const u8,
grapheme_width_method: configpkg.Config.GraphemeWidthMethod, grapheme_width_method: configpkg.Config.GraphemeWidthMethod,
abnormal_runtime_threshold_ms: u32, abnormal_runtime_threshold_ms: u32,
enquiry_string: ?[]const u8, enquiry_response: ?[]const u8,
pub fn init( pub fn init(
alloc_gpa: Allocator, alloc_gpa: Allocator,
@ -136,7 +136,7 @@ pub const DerivedConfig = struct {
.term = config.term, .term = config.term,
.grapheme_width_method = config.@"grapheme-width-method", .grapheme_width_method = config.@"grapheme-width-method",
.abnormal_runtime_threshold_ms = config.@"abnormal-command-exit-runtime", .abnormal_runtime_threshold_ms = config.@"abnormal-command-exit-runtime",
.enquiry_string = config.@"enquiry-string", .enquiry_response = config.@"enquiry-response",
}; };
} }
@ -216,7 +216,7 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec {
.osc_color_report_format = config.osc_color_report_format, .osc_color_report_format = config.osc_color_report_format,
.data = null, .data = null,
.abnormal_runtime_threshold_ms = opts.config.abnormal_runtime_threshold_ms, .abnormal_runtime_threshold_ms = opts.config.abnormal_runtime_threshold_ms,
.enquiry_string = if (opts.config.enquiry_string) |s| try alloc.dupe(u8, s) else null, .enquiry_response = if (opts.config.enquiry_response) |s| try alloc.dupe(u8, s) else null,
}; };
} }
@ -226,7 +226,7 @@ pub fn deinit(self: *Exec) void {
// Clean up our other members // Clean up our other members
self.terminal.deinit(self.alloc); self.terminal.deinit(self.alloc);
if (self.enquiry_string) |s| self.alloc.free(s); if (self.enquiry_response) |s| self.alloc.free(s);
} }
pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData { pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData {
@ -306,7 +306,8 @@ pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData {
.foreground_color = self.foreground_color, .foreground_color = self.foreground_color,
.background_color = self.background_color, .background_color = self.background_color,
.osc_color_report_format = self.osc_color_report_format, .osc_color_report_format = self.osc_color_report_format,
.enquiry_string = if (self.enquiry_string) |s| try self.alloc.dupe(u8, s) else null, .enquiry_response = if (self.enquiry_response) |s| try self.alloc.dupe(u8, s) else null,
.enquiry_response_lock = .{},
}, },
.parser = .{ .parser = .{
@ -441,8 +442,12 @@ pub fn changeConfig(self: *Exec, config: *DerivedConfig) !void {
config.cursor_style, config.cursor_style,
config.cursor_blink, config.cursor_blink,
); );
if (data.terminal_stream.handler.enquiry_string) |s| data.terminal_stream.handler.alloc.free(s); {
data.terminal_stream.handler.enquiry_string = if (config.enquiry_string) |s| try data.terminal_stream.handler.alloc.dupe(u8, s) else null; data.terminal_stream.handler.enquiry_response_lock.lock();
defer data.terminal_stream.handler.enquiry_response_lock.unlock();
if (data.terminal_stream.handler.enquiry_response) |s| data.terminal_stream.handler.alloc.free(s);
data.terminal_stream.handler.enquiry_response = if (config.enquiry_response) |s| try data.terminal_stream.handler.alloc.dupe(u8, s) else null;
}
} }
// Set the image size limits // Set the image size limits
@ -1707,12 +1712,13 @@ const StreamHandler = struct {
osc_color_report_format: configpkg.Config.OSCColorReportFormat, osc_color_report_format: configpkg.Config.OSCColorReportFormat,
enquiry_string: ?[]const u8 = null, enquiry_response: ?[]const u8,
enquiry_response_lock: std.Thread.RwLock,
pub fn deinit(self: *StreamHandler) void { pub fn deinit(self: *StreamHandler) void {
self.apc.deinit(); self.apc.deinit();
self.dcs.deinit(); self.dcs.deinit();
if (self.enquiry_string) |s| self.alloc.free(s); if (self.enquiry_response) |s| self.alloc.free(s);
} }
inline fn queueRender(self: *StreamHandler) !void { inline fn queueRender(self: *StreamHandler) !void {
@ -2405,8 +2411,14 @@ const StreamHandler = struct {
} }
pub fn enquiry(self: *StreamHandler) !void { pub fn enquiry(self: *StreamHandler) !void {
log.debug("sending equiry string '{any}''", .{self.enquiry_string orelse ""}); self.enquiry_response_lock.lockShared();
self.messageWriter(.{ .write_stable = self.enquiry_string orelse "" }); defer self.enquiry_response_lock.unlock();
log.debug("sending enquiry response={any}", .{self.enquiry_response orelse ""});
if (self.enquiry_response) |r| {
self.messageWriter(try termio.Message.writeReq(self.alloc, r));
} else {
self.messageWriter(.{ .write_stable = "" });
}
} }
pub fn scrollDown(self: *StreamHandler, count: usize) !void { pub fn scrollDown(self: *StreamHandler, count: usize) !void {