Address review comments

This commit is contained in:
yunusey
2025-01-02 16:40:51 -05:00
parent ad5b90a2ea
commit 71f678c576
2 changed files with 20 additions and 14 deletions

View File

@ -4186,18 +4186,25 @@ pub const SinglePath = struct {
const Self = @This();
/// The actual value that is updated as we parse.
value: []const u8 = "",
value: ?[]const u8 = null,
/// Parse a single path.
pub fn parseCLI(self: *Self, alloc: Allocator, input: ?[]const u8) !void {
const value = input orelse return error.ValueRequired;
// If the value is empty, we set the value to null
if (value.len == 0) {
self.value = null;
return;
}
const copy = try alloc.dupe(u8, value);
self.value = copy;
}
/// Deep copy of the struct. Required by Config.
pub fn clone(self: Self, alloc: Allocator) Allocator.Error!Self {
const copy_path = try alloc.dupe(u8, self.value);
const value = self.value orelse return .{};
const copy_path = try alloc.dupe(u8, value);
return .{
.value = copy_path,
};
@ -4205,7 +4212,8 @@ pub const SinglePath = struct {
/// Used by Formatter
pub fn formatEntry(self: Self, formatter: anytype) !void {
try formatter.formatEntry([]const u8, self.value);
const value = self.value orelse return;
try formatter.formatEntry([]const u8, value);
}
pub fn expand(
@ -4218,10 +4226,9 @@ pub const SinglePath = struct {
var dir = try std.fs.cwd().openDir(base, .{});
defer dir.close();
const path = self.value;
// If it is already absolute we can ignore it.
if (path.len == 0 or std.fs.path.isAbsolute(path)) return;
const path = self.value orelse return;
if (std.fs.path.isAbsolute(path)) return;
// If it isn't absolute, we need to make it absolute relative
// to the base.
@ -4245,7 +4252,7 @@ pub const SinglePath = struct {
});
// Blank this path so that we don't attempt to resolve it again
self.value = "";
self.value = null;
return;
};

View File

@ -828,7 +828,7 @@ pub fn updateFrame(
}
if (self.current_background_image == null and
self.background_image.value.len > 0)
self.background_image.value != null)
{
if (single_threaded_draw) self.draw_mutex.lock();
defer if (single_threaded_draw) self.draw_mutex.unlock();
@ -1208,8 +1208,7 @@ fn prepKittyImage(
/// Prepares the current background image for upload
pub fn prepBackgroundImage(self: *OpenGL) !void {
// If the user doesn't have a background image, do nothing...
if (self.background_image.value.len == 0) return;
const path = self.background_image.value;
const path = self.background_image.value orelse return;
// Read the file content
const file_content = try self.readImageContent(path);
@ -1234,8 +1233,9 @@ pub fn prepBackgroundImage(self: *OpenGL) !void {
/// Reads the content of the given image path and returns it
pub fn readImageContent(self: *OpenGL, path: []const u8) ![]u8 {
assert(std.fs.path.isAbsolute(path));
// Open the file
var file = std.fs.cwd().openFile(path, .{}) catch |err| {
var file = std.fs.openFileAbsolute(path, .{}) catch |err| {
log.warn("failed to open file: {}", .{err});
return error.InvalidData;
};
@ -1258,13 +1258,12 @@ pub fn readImageContent(self: *OpenGL, path: []const u8) ![]u8 {
// Read the file
var managed = std.ArrayList(u8).init(self.alloc);
errdefer managed.deinit();
const size: usize = max_image_size;
reader.readAllArrayList(&managed, size) catch |err| {
reader.readAllArrayList(&managed, max_image_size) catch |err| {
log.warn("failed to read file: {}", .{err});
return error.InvalidData;
};
return managed.items;
return managed.toOwnedSlice();
}
/// rebuildCells rebuilds all the GPU cells from our CPU state. This is a