@@ 18,27 18,25 @@ pub const cmd = Command{
pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!void {
if (args) |patterns| {
+ const writer = ColorWriter.new(std.io.getStdOut());
const zettels = try getZettels(allocator);
for (zettels) |zet| {
if (!zet.match(patterns)) continue;
- const writer = ColorWriter.new(std.io.getStdOut());
-
writer.setColor(.Blue).print("{}\n", .{zet.fname});
- writer.setColor(.Yellow).print("{}", .{zet.contents[0..3]});
- const metadata_end = blk: {
- if (mem.indexOfPos(u8, zet.contents, 3, "...")) |i| {
- break :blk i;
- } else if (mem.indexOfPos(u8, zet.contents, 3, "---")) |i| {
- break :blk i;
- } else unreachable;
- };
+ var it = mem.split(zet.contents, "\n");
+
+ // Print front matter fences in yellow
+ writer.setColor(.Yellow).print("{}\n", .{it.next()});
- writer.print("{}", .{zet.contents[3..metadata_end]});
+ while (it.next()) |line| {
+ const fence = mem.eql(u8, line, "---");
+ writer.setColor(if (fence) .Yellow else null).print("{}\n", .{line});
+ if (fence) break;
+ }
- writer.setColor(.Yellow).print("{}", .{zet.contents[metadata_end .. metadata_end + 3]});
- writer.print("{}\n", .{zet.contents[metadata_end + 3 ..]});
+ writer.print("{}\n", .{it.rest()});
}
} else {
return error.MissingRequiredArgument;
@@ 33,7 33,7 @@ pub const ColorWriter = struct {
return .{ .file = file };
}
- pub fn setColor(self: Self, color: Color) Self {
+ pub fn setColor(self: Self, color: ?Color) Self {
return .{ .color = color, .bold = self.bold, .italic = self.italic, .file = self.file };
}