~gpanders/wk

5283931674bd30b526f917d7145b0b87f9f01404 — Gregory Anders 2 months ago 4f358b1 master
Update for zig 0.7.0
6 files changed, 22 insertions(+), 24 deletions(-)

M src/cmd.zig
M src/cmd/preview.zig
M src/cmd/sync.zig
M src/cmd/tags.zig
M src/core.zig
M src/tty.zig
M src/cmd.zig => src/cmd.zig +9 -5
@@ 33,7 33,13 @@ pub const Command = struct {
        NoMatches,
        StreamTooLong,
        InvalidFormat,
    } || mem.Allocator.Error || fs.File.OpenError || fs.File.StatError || fs.File.ReadError || fs.File.WriteError || ChildProcess.SpawnError;
    } ||
        (mem.Allocator.Error ||
        fs.File.OpenError ||
        fs.File.StatError ||
        fs.File.ReadError ||
        fs.File.WriteError ||
        ChildProcess.SpawnError);

    fn parse(str: []const u8) !Self {
        inline for (commands) |cmd| {


@@ 56,11 62,9 @@ pub fn printUsage(cmd: ?Command) void {
    } else {
        stdout.print("Available commands:\n", .{}) catch return;
        inline for (commands) |command| {
            // TODO (zig 0.7.0) Replace with format string specifier
            // stdout.print("{: 8}{: <16}{}\n", ...)
            stdout.print("        {}{}{}\n", .{
            stdout.print("{: <4}{: <16}{}\n", .{
                "",
                command.name,
                " " ** (16 - command.name.len),
                command.desc,
            }) catch return;
        }

M src/cmd/preview.zig => src/cmd/preview.zig +1 -1
@@ 40,7 40,7 @@ pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!v
        // Next, try OS specific launchers
        if (builtin.os.tag == .linux) {
            if (try openBrowser(allocator, "xdg-open", html_file)) continue;
        } else if (builtin.os.tag == .macosx) {
        } else if (builtin.os.tag == .macos) {
            if (try openBrowser(allocator, "open", html_file)) continue;
        }


M src/cmd/sync.zig => src/cmd/sync.zig +1 -5
@@ 25,11 25,7 @@ pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!v

    var add_args = try std.ArrayList([]const u8).initCapacity(allocator, pages.len + 2);

    // TODO: zig 0.7.0
    // add_args.appendSliceAssumeCapacity(&[_][]const u8{ "git", "add" });
    inline for ([_][]const u8{ "git", "add" }) |s| {
        add_args.appendAssumeCapacity(s);
    }
    add_args.appendSliceAssumeCapacity(&[_][]const u8{ "git", "add" });

    for (pages) |page| add_args.appendAssumeCapacity(page.fname);


M src/cmd/tags.zig => src/cmd/tags.zig +2 -2
@@ 34,8 34,8 @@ pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!v

        for (pages) |page| try tags.appendSlice(page.tags);

        std.sort.sort([]const u8, tags.items, struct {
            fn lessThan(lhs: []const u8, rhs: []const u8) bool {
        std.sort.sort([]const u8, tags.items, {}, struct {
            fn lessThan(context: void, lhs: []const u8, rhs: []const u8) bool {
                return mem.lessThan(u8, lhs, rhs);
            }
        }.lessThan);

M src/core.zig => src/core.zig +8 -10
@@ 107,9 107,7 @@ pub fn openPages(allocator: *mem.Allocator, pages: []const []const u8) !void {
    var argv = try std.ArrayList([]const u8).initCapacity(allocator, pages.len + 1);
    argv.appendAssumeCapacity(os.getenv("EDITOR") orelse "vi");

    // TODO zig 0.7.0
    // argv.appendSliceAssumeCapacity(pages)
    for (pages) |page| argv.appendAssumeCapacity(page);
    argv.appendSliceAssumeCapacity(pages);

    var proc = try std.ChildProcess.init(argv.items, allocator);
    defer proc.deinit();


@@ 145,8 143,8 @@ pub fn getPages(allocator: *mem.Allocator) ![]Page {
        try pages.append(page);
    }

    std.sort.sort(Page, pages.items, struct {
        fn lessThan(lhs: Page, rhs: Page) bool {
    std.sort.sort(Page, pages.items, {}, struct {
        fn lessThan(context: void, lhs: Page, rhs: Page) bool {
            return mem.lessThan(u8, lhs.id, rhs.id);
        }
    }.lessThan);


@@ 167,14 165,14 @@ pub fn updateBacklinks(allocator: *mem.Allocator, pages: []const Page) !void {
            }
        }

        if (backlinks.size == 0) continue;
        if (backlinks.count() == 0) continue;

        const start_index = if (mem.indexOf(u8, page.contents, bl_header)) |s|
            s - 1
        else
            page.contents.len;

        var bl_list = try std.ArrayList([]const u8).initCapacity(allocator, backlinks.size);
        var bl_list = try std.ArrayList([]const u8).initCapacity(allocator, backlinks.count());
        var it = backlinks.iterator();
        while (it.next()) |kv| {
            comptime var template = "- [[{}]] {}";


@@ 235,7 233,7 @@ fn fromFile(allocator: *mem.Allocator, page: fs.Dir.Entry) !Page {
        if (mem.startsWith(u8, line, "title: ")) {
            comptime var k = "title: ".len - 1;
            for (line[k..]) |char, i| {
                if (!fmt.isWhiteSpace(char)) {
                if (!ascii.isSpace(char)) {
                    title = line[k + i ..];
                    continue :outer;
                }


@@ 249,10 247,10 @@ fn fromFile(allocator: *mem.Allocator, page: fs.Dir.Entry) !Page {
        if (mem.startsWith(u8, line, "tags: ")) {
            comptime var k = "tags: ".len - 1;
            for (line[k..]) |char, i| {
                if (!fmt.isWhiteSpace(char)) {
                if (!ascii.isSpace(char)) {
                    var it = mem.split(line[k + i ..], ",");
                    while (it.next()) |tag| {
                        const new_tag = fmt.trim(tag);
                        const new_tag = mem.trim(u8, tag, &ascii.spaces);
                        try tags.append(new_tag);
                    }


M src/tty.zig => src/tty.zig +1 -1
@@ 37,7 37,7 @@ pub const ColorWriter = struct {
        return .{ .color = color, .bold = self.bold, .italic = self.italic, .file = self.file };
    }

    pub fn print(self: Self, comptime format: []const u8, args: var) void {
    pub fn print(self: Self, comptime format: []const u8, args: anytype) void {
        if (self.color) |_| {
            self.file.outStream().print("\x1b[38;5;{}m", .{@enumToInt(self.color.?)}) catch return;
        }