mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-04-12 10:48:39 +03:00
c: remove the config load string API
It was unused and doesn't match our diagnostic API.
This commit is contained in:
@ -607,7 +607,6 @@ ghostty_info_s ghostty_info(void);
|
|||||||
ghostty_config_t ghostty_config_new();
|
ghostty_config_t ghostty_config_new();
|
||||||
void ghostty_config_free(ghostty_config_t);
|
void ghostty_config_free(ghostty_config_t);
|
||||||
void ghostty_config_load_cli_args(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_default_files(ghostty_config_t);
|
||||||
void ghostty_config_load_recursive_files(ghostty_config_t);
|
void ghostty_config_load_recursive_files(ghostty_config_t);
|
||||||
void ghostty_config_finalize(ghostty_config_t);
|
void ghostty_config_finalize(ghostty_config_t);
|
||||||
|
@ -4,7 +4,7 @@ pub const args = @import("cli/args.zig");
|
|||||||
pub const Action = @import("cli/action.zig").Action;
|
pub const Action = @import("cli/action.zig").Action;
|
||||||
pub const DiagnosticList = diags.DiagnosticList;
|
pub const DiagnosticList = diags.DiagnosticList;
|
||||||
pub const Diagnostic = diags.Diagnostic;
|
pub const Diagnostic = diags.Diagnostic;
|
||||||
pub const Location = diags.Diagnostic.Location;
|
pub const Location = diags.Location;
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@import("std").testing.refAllDecls(@This());
|
@import("std").testing.refAllDecls(@This());
|
||||||
|
@ -129,7 +129,7 @@ pub fn parse(
|
|||||||
try dst._diagnostics.append(arena_alloc, .{
|
try dst._diagnostics.append(arena_alloc, .{
|
||||||
.key = try arena_alloc.dupeZ(u8, key),
|
.key = try arena_alloc.dupeZ(u8, key),
|
||||||
.message = message,
|
.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);
|
try testing.expect(data._diagnostics.items().len == 1);
|
||||||
{
|
{
|
||||||
const diag = data._diagnostics.items()[0];
|
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("what", diag.key);
|
||||||
try testing.expectEqualStrings("unknown field", diag.message);
|
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.
|
/// 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 };
|
return .{ .cli = self.index };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -975,7 +975,7 @@ pub fn LineIterator(comptime ReaderType: type) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a location for a diagnostic message.
|
/// 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 we have no filepath then we have no location.
|
||||||
if (self.filepath.len == 0) return null;
|
if (self.filepath.len == 0) return null;
|
||||||
|
|
||||||
|
@ -15,31 +15,6 @@ pub const Diagnostic = struct {
|
|||||||
key: [:0]const u8 = "",
|
key: [:0]const u8 = "",
|
||||||
message: [:0]const u8,
|
message: [:0]const u8,
|
||||||
|
|
||||||
/// The possible locations for a diagnostic message. This is used
|
|
||||||
/// to provide context for the message.
|
|
||||||
pub const Location = union(enum) {
|
|
||||||
none,
|
|
||||||
cli: usize,
|
|
||||||
file: struct {
|
|
||||||
path: []const u8,
|
|
||||||
line: usize,
|
|
||||||
},
|
|
||||||
|
|
||||||
pub fn fromIter(iter: anytype) Location {
|
|
||||||
const Iter = t: {
|
|
||||||
const T = @TypeOf(iter);
|
|
||||||
break :t switch (@typeInfo(T)) {
|
|
||||||
.Pointer => |v| v.child,
|
|
||||||
.Struct => T,
|
|
||||||
else => return .none,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!@hasDecl(Iter, "location")) return .none;
|
|
||||||
return iter.location() orelse .none;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Write the full user-friendly diagnostic message to the writer.
|
/// Write the full user-friendly diagnostic message to the writer.
|
||||||
pub fn write(self: *const Diagnostic, writer: anytype) !void {
|
pub fn write(self: *const Diagnostic, writer: anytype) !void {
|
||||||
switch (self.location) {
|
switch (self.location) {
|
||||||
@ -61,6 +36,31 @@ pub const Diagnostic = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The possible locations for a diagnostic message. This is used
|
||||||
|
/// to provide context for the message.
|
||||||
|
pub const Location = union(enum) {
|
||||||
|
none,
|
||||||
|
cli: usize,
|
||||||
|
file: struct {
|
||||||
|
path: []const u8,
|
||||||
|
line: usize,
|
||||||
|
},
|
||||||
|
|
||||||
|
pub fn fromIter(iter: anytype) Location {
|
||||||
|
const Iter = t: {
|
||||||
|
const T = @TypeOf(iter);
|
||||||
|
break :t switch (@typeInfo(T)) {
|
||||||
|
.Pointer => |v| v.child,
|
||||||
|
.Struct => T,
|
||||||
|
else => return .none,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!@hasDecl(Iter, "location")) return .none;
|
||||||
|
return iter.location() orelse .none;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// A list of diagnostics. The "_diagnostics" field must be this type
|
/// A list of diagnostics. The "_diagnostics" field must be this type
|
||||||
/// for diagnostics to be supported. If this field is an incorrect type
|
/// for diagnostics to be supported. If this field is an incorrect type
|
||||||
/// a compile-time error will be raised.
|
/// a compile-time error will be raised.
|
||||||
|
@ -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
|
/// Load the configuration from the default file locations. This
|
||||||
/// is usually done first. The default file locations are locations
|
/// is usually done first. The default file locations are locations
|
||||||
/// such as the home directory.
|
/// such as the home directory.
|
||||||
|
@ -2731,7 +2731,7 @@ pub fn parseManuallyHook(
|
|||||||
|
|
||||||
if (command.items.len == 0) {
|
if (command.items.len == 0) {
|
||||||
try self._diagnostics.append(alloc, .{
|
try self._diagnostics.append(alloc, .{
|
||||||
.location = cli.Diagnostic.Location.fromIter(iter),
|
.location = cli.Location.fromIter(iter),
|
||||||
.message = try std.fmt.allocPrintZ(
|
.message = try std.fmt.allocPrintZ(
|
||||||
alloc,
|
alloc,
|
||||||
"missing command after {s}",
|
"missing command after {s}",
|
||||||
|
Reference in New Issue
Block a user