config: make abnormal runtime threshold a u32

This commit is contained in:
Mitchell Hashimoto
2023-12-30 21:45:16 -08:00
parent 4ef8d099a7
commit aef93a5420
2 changed files with 37 additions and 30 deletions

View File

@ -387,10 +387,14 @@ palette: Palette = .{},
/// flag. For example: `ghostty -e fish --with --custom --args`. /// flag. For example: `ghostty -e fish --with --custom --args`.
command: ?[]const u8 = null, command: ?[]const u8 = null,
/// The number of milliseconds below which we consider a process /// The number of milliseconds of runtime below which we consider a process
/// exit to be abnormal. This is used to show an error message /// exit to be abnormal. This is used to show an error message when the
/// when the process exits too quickly. /// process exits too quickly.
@"abnormal-runtime-threshold-ms": u64 = 250, ///
/// On Linux, this must be paired with a non-zero exit code. On macOS,
/// we allow any exit code because of the way shell processes are launched
/// via the login command.
@"abnormal-command-exit-runtime": u32 = 250,
/// Match a regular expression against the terminal text and associate /// Match a regular expression against the terminal text and associate
/// clicking it with an action. This can be used to match URLs, file paths, /// clicking it with an action. This can be used to match URLs, file paths,

View File

@ -41,7 +41,7 @@ const disable_kitty_keyboard_protocol = apprt.runtime == apprt.glfw;
/// The number of milliseconds below which we consider a process /// The number of milliseconds below which we consider a process
/// exit to be abnormal. This is used to show an error message /// exit to be abnormal. This is used to show an error message
/// when the process exits too quickly. /// when the process exits too quickly.
abnormal_runtime_threshold_ms: u64, abnormal_runtime_threshold_ms: u32,
/// Allocator /// Allocator
alloc: Allocator, alloc: Allocator,
@ -111,7 +111,7 @@ pub const DerivedConfig = struct {
osc_color_report_format: configpkg.Config.OSCColorReportFormat, osc_color_report_format: configpkg.Config.OSCColorReportFormat,
term: []const u8, term: []const u8,
grapheme_width_method: configpkg.Config.GraphemeWidthMethod, grapheme_width_method: configpkg.Config.GraphemeWidthMethod,
abnormal_runtime_threshold_ms: u64, abnormal_runtime_threshold_ms: u32,
pub fn init( pub fn init(
alloc_gpa: Allocator, alloc_gpa: Allocator,
@ -130,7 +130,7 @@ pub const DerivedConfig = struct {
.osc_color_report_format = config.@"osc-color-report-format", .osc_color_report_format = config.@"osc-color-report-format",
.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-runtime-threshold-ms", .abnormal_runtime_threshold_ms = config.@"abnormal-command-exit-runtime",
}; };
} }
@ -551,18 +551,13 @@ pub fn jumpToPrompt(self: *Exec, delta: isize) !void {
/// Called when the child process exited abnormally but before /// Called when the child process exited abnormally but before
/// the surface is notified. /// the surface is notified.
pub fn childExitedAbnormally(self: *Exec, exit_code: u32, runtime_ms: u64) !void { pub fn childExitedAbnormally(self: *Exec, exit_code: u32, runtime_ms: u64) !void {
// Build up our command for the error message var arena = ArenaAllocator.init(self.alloc);
const command = try std.mem.join( defer arena.deinit();
self.alloc, const alloc = arena.allocator();
" ",
self.subprocess.args,
);
defer self.alloc.free(command);
const runtime_str = try std.fmt.allocPrint(self.alloc, "{d} ms", .{runtime_ms}); // Build up our command for the error message
defer self.alloc.free(runtime_str); const command = try std.mem.join(alloc, " ", self.subprocess.args);
const exit_code_str = try std.fmt.allocPrint(self.alloc, "{d}", .{exit_code}); const runtime_str = try std.fmt.allocPrint(alloc, "{d} ms", .{runtime_ms});
defer self.alloc.free(exit_code_str);
// Modify the terminal to show our error message. This // Modify the terminal to show our error message. This
// requires grabbing the renderer state lock. // requires grabbing the renderer state lock.
@ -580,8 +575,7 @@ pub fn childExitedAbnormally(self: *Exec, exit_code: u32, runtime_ms: u64) !void
// a little bit and write a horizontal rule before writing // a little bit and write a horizontal rule before writing
// our message. This lets the use see the error message the // our message. This lets the use see the error message the
// command may have output. // command may have output.
const viewport_str = try t.plainString(self.alloc); const viewport_str = try t.plainString(alloc);
defer self.alloc.free(viewport_str);
if (viewport_str.len > 0) { if (viewport_str.len > 0) {
try t.linefeed(); try t.linefeed();
for (0..t.cols) |_| try t.print(0x2501); for (0..t.cols) |_| try t.print(0x2501);
@ -593,14 +587,16 @@ pub fn childExitedAbnormally(self: *Exec, exit_code: u32, runtime_ms: u64) !void
// Output our error message // Output our error message
try t.setAttribute(.{ .@"8_fg" = .bright_red }); try t.setAttribute(.{ .@"8_fg" = .bright_red });
try t.setAttribute(.{ .bold = {} }); try t.setAttribute(.{ .bold = {} });
try t.printString("Ghostty failed to launch the requested command:"); try t.printString("Ghostty failed to launch the requested command.");
try t.setAttribute(.{ .unset = {} }); try t.setAttribute(.{ .unset = {} });
t.carriageReturn(); t.carriageReturn();
try t.linefeed(); try t.linefeed();
try t.linefeed(); try t.linefeed();
try t.setAttribute(.{ .bold = {} }); try t.printString("Command: ");
try t.printString(command); try t.printString(command);
try t.setAttribute(.{ .unset = {} }); try t.setAttribute(.{ .unset = {} });
t.carriageReturn(); t.carriageReturn();
try t.linefeed(); try t.linefeed();
try t.linefeed(); try t.linefeed();
@ -608,12 +604,19 @@ pub fn childExitedAbnormally(self: *Exec, exit_code: u32, runtime_ms: u64) !void
try t.setAttribute(.{ .@"8_fg" = .bright_red }); try t.setAttribute(.{ .@"8_fg" = .bright_red });
try t.printString(runtime_str); try t.printString(runtime_str);
try t.setAttribute(.{ .unset = {} }); try t.setAttribute(.{ .unset = {} });
// We don't print this on macOS because the exit code is always 0
// due to the way we launch the process.
if (comptime !builtin.target.isDarwin()) {
const exit_code_str = try std.fmt.allocPrint(alloc, "{d}", .{exit_code});
t.carriageReturn(); t.carriageReturn();
try t.linefeed(); try t.linefeed();
try t.printString("Exit code: "); try t.printString("Exit Code: ");
try t.setAttribute(.{ .@"8_fg" = .bright_red }); try t.setAttribute(.{ .@"8_fg" = .bright_red });
try t.printString(exit_code_str); try t.printString(exit_code_str);
try t.setAttribute(.{ .unset = {} }); try t.setAttribute(.{ .unset = {} });
}
t.carriageReturn(); t.carriageReturn();
try t.linefeed(); try t.linefeed();
try t.linefeed(); try t.linefeed();
@ -771,7 +774,7 @@ const EventData = struct {
/// The number of milliseconds below which we consider a process /// The number of milliseconds below which we consider a process
/// exit to be abnormal. This is used to show an error message /// exit to be abnormal. This is used to show an error message
/// when the process exits too quickly. /// when the process exits too quickly.
abnormal_runtime_threshold_ms: u64, abnormal_runtime_threshold_ms: u32,
pub fn deinit(self: *EventData, alloc: Allocator) void { pub fn deinit(self: *EventData, alloc: Allocator) void {
// Clear our write pools. We know we aren't ever going to do // Clear our write pools. We know we aren't ever going to do