mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-23 20:26:09 +03:00
config: API for wasm
This commit is contained in:
@ -527,6 +527,59 @@ pub const Keybinds = struct {
|
||||
}
|
||||
};
|
||||
|
||||
// Wasm API.
|
||||
pub const Wasm = struct {
|
||||
const wasm = @import("os/wasm.zig");
|
||||
const alloc = wasm.alloc;
|
||||
const cli_args = @import("cli_args.zig");
|
||||
|
||||
/// Create a new configuration filled with the initial default values.
|
||||
export fn config_new() ?*Config {
|
||||
const result = alloc.create(Config) catch |err| {
|
||||
log.err("error allocating config err={}", .{err});
|
||||
return null;
|
||||
};
|
||||
|
||||
result.* = Config.default(alloc) catch |err| {
|
||||
log.err("error creating config err={}", .{err});
|
||||
return null;
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export fn config_free(ptr: ?*Config) void {
|
||||
if (ptr) |v| {
|
||||
v.deinit();
|
||||
alloc.destroy(v);
|
||||
}
|
||||
}
|
||||
|
||||
/// Load the configuration from a string in the same format as
|
||||
/// the file-based syntax for the desktop version of the terminal.
|
||||
export fn 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, alloc, self, &iter);
|
||||
}
|
||||
|
||||
export fn config_finalize(self: *Config) void {
|
||||
self.finalize() catch |err| {
|
||||
log.err("error finalizing config err={}", .{err});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
test {
|
||||
std.testing.refAllDecls(@This());
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ pub usingnamespace @import("os/wasm.zig");
|
||||
pub usingnamespace @import("os/wasm/log.zig");
|
||||
pub usingnamespace @import("font/main.zig");
|
||||
pub usingnamespace @import("terminal/main.zig");
|
||||
pub usingnamespace @import("config.zig").Wasm;
|
||||
|
||||
// Set our log level. We try to get as much logging as possible but in
|
||||
// ReleaseSmall mode where we're optimizing for space, we elevate the
|
||||
|
Reference in New Issue
Block a user