wasm: export terminal core API

This commit is contained in:
Mitchell Hashimoto
2022-12-05 21:27:20 -08:00
parent 95b89149aa
commit 10f708ee65
4 changed files with 9 additions and 11 deletions

View File

@ -6,6 +6,7 @@ const builtin = @import("builtin");
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");
// 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

View File

@ -28,6 +28,11 @@ pub const EraseLine = csi.EraseLine;
pub const TabClear = csi.TabClear;
pub const Attribute = sgr.Attribute;
/// If we're targeting wasm then we export some wasm APIs.
pub usingnamespace if (builtin.target.isWasm()) struct {
pub usingnamespace @import("wasm.zig");
} else struct {};
test {
@import("std").testing.refAllDecls(@This());
}

View File

@ -1,4 +0,0 @@
// This is the main file for the WASM module. The WASM module just
// imports the C API.
pub usingnamespace @import("c_api.zig");

View File

@ -8,12 +8,8 @@ const std = @import("std");
const builtin = @import("builtin");
const Allocator = std.mem.Allocator;
const Terminal = @import("main.zig").Terminal;
// The allocator that we want to use.
const alloc = if (builtin.link_libc)
std.heap.c_allocator
else
std.heap.page_allocator;
const wasm = @import("../os/wasm.zig");
const alloc = wasm.alloc;
export fn terminal_new(cols: usize, rows: usize) ?*Terminal {
const term = Terminal.init(alloc, cols, rows) catch return null;
@ -31,6 +27,6 @@ export fn terminal_free(ptr: ?*Terminal) void {
export fn terminal_print(ptr: ?*Terminal, char: u32) void {
if (ptr) |t| {
t.print(@intCast(u21, char)) catch return null;
t.print(@intCast(u21, char)) catch return;
}
}