c: remove the config load string API

It was unused and doesn't match our diagnostic API.
This commit is contained in:
Mitchell Hashimoto
2024-10-17 08:02:28 -07:00
parent a12b33662c
commit 70c175e2a6
6 changed files with 31 additions and 50 deletions

View File

@ -607,7 +607,6 @@ ghostty_info_s ghostty_info(void);
ghostty_config_t ghostty_config_new();
void ghostty_config_free(ghostty_config_t);
void ghostty_config_load_cli_args(ghostty_config_t);
void ghostty_config_load_string(ghostty_config_t, const char*, uintptr_t);
void ghostty_config_load_default_files(ghostty_config_t);
void ghostty_config_load_recursive_files(ghostty_config_t);
void ghostty_config_finalize(ghostty_config_t);

View File

@ -4,7 +4,7 @@ pub const args = @import("cli/args.zig");
pub const Action = @import("cli/action.zig").Action;
pub const DiagnosticList = diags.DiagnosticList;
pub const Diagnostic = diags.Diagnostic;
pub const Location = diags.Diagnostic.Location;
pub const Location = diags.Location;
test {
@import("std").testing.refAllDecls(@This());

View File

@ -129,7 +129,7 @@ pub fn parse(
try dst._diagnostics.append(arena_alloc, .{
.key = try arena_alloc.dupeZ(u8, key),
.message = message,
.location = Diagnostic.Location.fromIter(iter),
.location = diags.Location.fromIter(iter),
});
};
}
@ -475,7 +475,7 @@ test "parse: diagnostic tracking" {
try testing.expect(data._diagnostics.items().len == 1);
{
const diag = data._diagnostics.items()[0];
try testing.expectEqual(Diagnostic.Location.none, diag.location);
try testing.expectEqual(diags.Location.none, diag.location);
try testing.expectEqualStrings("what", diag.key);
try testing.expectEqualStrings("unknown field", diag.message);
}
@ -878,7 +878,7 @@ pub fn ArgsIterator(comptime Iterator: type) type {
}
/// Returns a location for a diagnostic message.
pub fn location(self: *const Self) ?Diagnostic.Location {
pub fn location(self: *const Self) ?diags.Location {
return .{ .cli = self.index };
}
};
@ -975,7 +975,7 @@ pub fn LineIterator(comptime ReaderType: type) type {
}
/// Returns a location for a diagnostic message.
pub fn location(self: *const Self) ?Diagnostic.Location {
pub fn location(self: *const Self) ?diags.Location {
// If we have no filepath then we have no location.
if (self.filepath.len == 0) return null;

View File

@ -15,6 +15,27 @@ pub const Diagnostic = struct {
key: [:0]const u8 = "",
message: [:0]const u8,
/// Write the full user-friendly diagnostic message to the writer.
pub fn write(self: *const Diagnostic, writer: anytype) !void {
switch (self.location) {
.none => {},
.cli => |index| try writer.print("cli:{}:", .{index}),
.file => |file| try writer.print(
"{s}:{}:",
.{ file.path, file.line },
),
}
if (self.key.len > 0) {
try writer.print("{s}: ", .{self.key});
} else if (self.location != .none) {
try writer.print(" ", .{});
}
try writer.print("{s}", .{self.message});
}
};
/// The possible locations for a diagnostic message. This is used
/// to provide context for the message.
pub const Location = union(enum) {
@ -40,27 +61,6 @@ pub const Diagnostic = struct {
}
};
/// Write the full user-friendly diagnostic message to the writer.
pub fn write(self: *const Diagnostic, writer: anytype) !void {
switch (self.location) {
.none => {},
.cli => |index| try writer.print("cli:{}:", .{index}),
.file => |file| try writer.print(
"{s}:{}:",
.{ file.path, file.line },
),
}
if (self.key.len > 0) {
try writer.print("{s}: ", .{self.key});
} else if (self.location != .none) {
try writer.print(" ", .{});
}
try writer.print("{s}", .{self.message});
}
};
/// A list of diagnostics. The "_diagnostics" field must be this type
/// for diagnostics to be supported. If this field is an incorrect type
/// a compile-time error will be raised.

View File

@ -39,24 +39,6 @@ export fn ghostty_config_load_cli_args(self: *Config) void {
};
}
/// Load the configuration from a string in the same format as
/// the file-based syntax for the desktop version of the terminal.
export fn ghostty_config_load_string(
self: *Config,
str: [*]const u8,
len: usize,
) void {
config_load_string_(self, str[0..len]) catch |err| {
log.err("error loading config err={}", .{err});
};
}
fn config_load_string_(self: *Config, str: []const u8) !void {
var fbs = std.io.fixedBufferStream(str);
var iter = cli.args.lineIterator(fbs.reader());
try cli.args.parse(Config, global.alloc, self, &iter);
}
/// Load the configuration from the default file locations. This
/// is usually done first. The default file locations are locations
/// such as the home directory.

View File

@ -2731,7 +2731,7 @@ pub fn parseManuallyHook(
if (command.items.len == 0) {
try self._diagnostics.append(alloc, .{
.location = cli.Diagnostic.Location.fromIter(iter),
.location = cli.Location.fromIter(iter),
.message = try std.fmt.allocPrintZ(
alloc,
"missing command after {s}",