add new data type, Stage

This commit is contained in:
falsycat 2025-05-05 11:44:49 +09:00
parent 23aab8414b
commit 45d5bc4d31
4 changed files with 62 additions and 9 deletions

48
src/hncore/Stage.zig Normal file
View File

@ -0,0 +1,48 @@
const std = @import("std");
const Task = @import("./Task.zig");
///
const Self = @This();
///
const TaskList = std.ArrayList(*Task);
///
alloc: std.mem.Allocator,
///
name: [:0]const u8,
///
tasks: TaskList,
///
pub fn init(alloc: std.mem.Allocator, name: []const u8) !Self {
return Self {
.alloc = alloc,
.name = try alloc.dupeZ(u8, name),
.tasks = TaskList.init(alloc),
};
}
///
pub fn deinit(self: *Self) void {
self.tasks.deinit();
self.alloc.free(self.name);
}
///
pub fn rename(self: *Self, name: []const u8) !void {
self.alloc.free(self.name);
self.name = try self.alloc.dupeZ(u8, name);
}
test {
var stage = try init(std.testing.allocator, "helloworld");
defer stage.deinit();
try std.testing.expectEqualStrings("helloworld", stage.name);
try stage.rename("goodbye");
try std.testing.expectEqualStrings("goodbye", stage.name);
}

View File

@ -17,9 +17,6 @@ details: [:0]const u8,
/// ///
done: bool, done: bool,
///
archived: bool,
/// ///
pub fn init(alloc: std.mem.Allocator, id: usize) !Self { pub fn init(alloc: std.mem.Allocator, id: usize) !Self {
return Self { return Self {
@ -28,7 +25,6 @@ pub fn init(alloc: std.mem.Allocator, id: usize) !Self {
.summary = try alloc.dupeZ(u8, ""), .summary = try alloc.dupeZ(u8, ""),
.details = try alloc.dupeZ(u8, ""), .details = try alloc.dupeZ(u8, ""),
.done = true, .done = true,
.archived = true,
}; };
} }
/// ///

View File

@ -2,11 +2,19 @@ const std = @import("std");
const Task = @import("./Task.zig"); const Task = @import("./Task.zig");
///
const Self = @This(); const Self = @This();
///
const Map = std.AutoHashMap(usize, *Task); const Map = std.AutoHashMap(usize, *Task);
///
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
///
map: Map, map: Map,
///
nextId: usize, nextId: usize,
/// ///

View File

@ -1,6 +1,7 @@
pub const command = @import("./command/root.zig"); pub const command = @import("./command/root.zig");
pub const CommandHistory = @import("./CommandHistory.zig"); pub const CommandHistory = @import("./CommandHistory.zig");
pub const Stage = @import("./Stage.zig");
pub const Task = @import("./Task.zig"); pub const Task = @import("./Task.zig");
pub const TaskStore = @import("./TaskStore.zig"); pub const TaskStore = @import("./TaskStore.zig");
pub const Workspace = @import("./Workspace.zig"); pub const Workspace = @import("./Workspace.zig");