terminal/kitty-gfx: images store transmit time

This commit is contained in:
Mitchell Hashimoto
2023-08-23 11:17:58 -07:00
parent 73976824a1
commit c0b58802ba
2 changed files with 9 additions and 0 deletions

View File

@ -297,6 +297,7 @@ const EncodeableError = Image.Error || Allocator.Error;
fn encodeError(r: *Response, err: EncodeableError) void {
switch (err) {
error.OutOfMemory => r.message = "ENOMEM: out of memory",
error.InternalError => r.message = "EINVAL: internal error",
error.InvalidData => r.message = "EINVAL: invalid data",
error.DecompressionFailed => r.message = "EINVAL: decompression failed",
error.FilePathTooLong => r.message = "EINVAL: file path too long",

View File

@ -244,6 +244,12 @@ pub const LoadingImage = struct {
return error.InvalidData;
}
// Set our time
self.image.transmit_time = std.time.Instant.now() catch |err| {
log.warn("failed to get time: {}", .{err});
return error.InternalError;
};
// Everything looks good, copy the image data over.
var result = self.image;
result.data = try self.data.toOwnedSlice(alloc);
@ -358,8 +364,10 @@ pub const Image = struct {
format: command.Transmission.Format = .rgb,
compression: command.Transmission.Compression = .none,
data: []const u8 = "",
transmit_time: std.time.Instant = undefined,
pub const Error = error{
InternalError,
InvalidData,
DecompressionFailed,
DimensionsRequired,