Skip to content

Commit

Permalink
Add ziglyph and normalize input
Browse files Browse the repository at this point in the history
  • Loading branch information
natecraddock committed Jan 31, 2023
1 parent 6a3e7eb commit 3e70696
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/ziglyph"]
path = lib/ziglyph
url = https://github.com/jecolon/ziglyph
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions();

const exe = b.addExecutable("zf", "src/main.zig");
exe.addPackagePath("ziglyph", "lib/ziglyph/src/ziglyph.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
Expand All @@ -28,6 +29,7 @@ pub fn build(b: *std.build.Builder) void {
run_step.dependOn(&run_cmd.step);

var exe_tests = b.addTest("src/main.zig");
exe_tests.addPackagePath("ziglyph", "libs/ziglyph/src/ziglyph.zig");
exe_tests.setBuildMode(mode);

const tests = b.step("test", "Run tests");
Expand Down
1 change: 1 addition & 0 deletions lib/ziglyph
Submodule ziglyph added at 6b628e
12 changes: 10 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const heap = std.heap;
const io = std.io;
const std = @import("std");
const testing = std.testing;
const ziglyph = @import("ziglyph");

const ArrayList = std.ArrayList;
const Normalizer = ziglyph.Normalizer;
const SGRAttribute = ui.SGRAttribute;

const filter = @import("filter.zig");
Expand Down Expand Up @@ -213,9 +215,15 @@ pub fn main() anyerror!void {
std.process.exit(0);
}

var normalizer = try Normalizer.init(allocator);
defer normalizer.deinit();

// read all lines or exit on out of memory
var stdin = io.getStdIn().reader();
const buf = try readAll(allocator, &stdin);
const buf = blk: {
var stdin = io.getStdIn().reader();
const buf = try readAll(allocator, &stdin);
break :blk (try normalizer.nfd(allocator, buf)).slice;
};

const delimiter = '\n';
var candidates = try filter.collectCandidates(allocator, buf, delimiter);
Expand Down

0 comments on commit 3e70696

Please sign in to comment.