aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/ncurses.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/ncurses.zig')
-rw-r--r--src/frontend/ncurses.zig26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/frontend/ncurses.zig b/src/frontend/ncurses.zig
index dfbf276..fd58cf1 100644
--- a/src/frontend/ncurses.zig
+++ b/src/frontend/ncurses.zig
@@ -1,5 +1,5 @@
//! This module provides an implementation of IO using the ncurses library.
-const io_interface = @import("io_interface.zig");
+const IOInterface = @import("io_interface.zig").IOInterface;
const std = @import("std");
const Action = @import("../actions.zig").Action;
const ncurses = @cImport({
@@ -120,7 +120,7 @@ pub const IO = struct {
/// Display a message in the message box.
/// Takes a pre-formatted null-terminated string
/// If the message is too wide for the box, display "Message too long" instead.
- pub fn displayMessage(self: *IO, str: []const u8) error{OutOfMemory}!void {
+ pub fn displayMessage(self: *IO, str: []const u8) anyerror!void {
if (self.msgs == null) return;
for (1..MESSAGE_PANEL_WIDTH - 1) |i| {
@@ -161,7 +161,7 @@ pub const IO = struct {
/// An interface for user input and time processing.
/// Waits for the end of a tick and returns a tick action.
/// If input is given before the end of the tick, return that instead.
- pub fn waitForTick(self: *IO) !Action {
+ pub fn waitForTick(self: *IO) anyerror!Action {
var new = std.time.milliTimestamp();
while (new - self.prev_tick_time <= TICK_MS) {
@@ -236,17 +236,17 @@ pub const IO = struct {
);
}
- pub fn init(allocator: std.mem.Allocator) !IO {
+ pub fn init(allocator: std.mem.Allocator) !IOInterface {
_ = locale.setlocale(locale.LC_ALL, "");
- var io = IO{
- .allocator = allocator,
- .inst = null,
- .msgs = null,
- .stat = null,
- .main = null,
- .prev_tick_time = std.time.milliTimestamp(),
- };
+ const io_ptr = try allocator.alloc(IO, 1);
+ var io = &io_ptr[0];
+ io.allocator = allocator;
+ io.inst = null;
+ io.msgs = null;
+ io.stat = null;
+ io.main = null;
+ io.prev_tick_time = std.time.milliTimestamp();
if (ncurses.initscr() == null) {
return error.CursesInitFail;
@@ -275,7 +275,7 @@ pub const IO = struct {
try io.createPanels();
}
- return io;
+ return IOInterface.init(io);
}
fn deleteWindows(self: *IO) void {