update to zig 0.14.0 and change how newlines are handled

This commit is contained in:
moss 2025-03-10 23:04:59 -05:00
parent 12e96454ff
commit e8ea3f00ee
4 changed files with 21 additions and 18 deletions

View File

@ -26,7 +26,7 @@ the following are currently supported:
- [zig-clap](https://github.com/Hejsil/zig-clap) for arg parsing - [zig-clap](https://github.com/Hejsil/zig-clap) for arg parsing
## building ## building
1. install [zig 0.13.0](https://ziglang.org/download/#release-0.13.0) 1. install [zig 0.14.0](https://ziglang.org/download/#release-0.14.0)
2. clone repo 2. clone repo
3. run `zig build` 3. run `zig build`
@ -40,4 +40,4 @@ release optimize modes are:
- safe - safe
- small - small
the mdcat binary will be in `zig-out/bin/mdcat` the mdcat binary will be in `zig-out/bin/mdcat`

View File

@ -28,8 +28,8 @@ pub fn build(b: *std.Build) void {
const clap = b.dependency("clap", .{}); const clap = b.dependency("clap", .{});
exe.root_module.addImport("clap", clap.module("clap")); exe.root_module.addImport("clap", clap.module("clap"));
const ansiterm = b.dependency("ansi-term", .{}); const ansiterm = b.dependency("ansi_term", .{});
exe.root_module.addImport("ansi-term", ansiterm.module("ansi-term")); exe.root_module.addImport("ansi-term", ansiterm.module("ansi_term"));
// This declares intent for the executable to be installed into the // This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default // standard location when the user invokes the "install" step (the default

View File

@ -6,7 +6,7 @@
// //
// It is redundant to include "zig" in this name because it is already // It is redundant to include "zig" in this name because it is already
// within the Zig package namespace. // within the Zig package namespace.
.name = "mdcat", .name = .mdcat,
// This is a [Semantic Version](https://semver.org/). // This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication. // In a future version of Zig it will be used for package deduplication.
@ -24,12 +24,12 @@
// internet connectivity. // internet connectivity.
.dependencies = .{ .dependencies = .{
.clap = .{ .clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.9.1.tar.gz", .url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.10.0.tar.gz",
.hash = "122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b", .hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0",
}, },
.@"ansi-term" = .{ .ansi_term = .{
.url = "https://github.com/ziglibs/ansi-term/archive/refs/heads/master.zip", .url = "git+https://github.com/ziglibs/ansi_term.git#c36f75d2b49c5bed2a5bb4d71e92f6f4591b1887",
.hash = "12203a64b02d46e6c2e268b7da60cb11b2fa83dc580cad77cf330d1438e2280de46f", .hash = "ansi_term-0.1.0-_baAy-hjAABPPaH9jO03ipMXYOWQBzOJhaj2vsDpc0MK",
}, },
}, },
.paths = .{ .paths = .{
@ -40,4 +40,6 @@
//"LICENSE", //"LICENSE",
//"README.md", //"README.md",
}, },
.fingerprint = 0x72dbbe0f3b46658e,
.minimum_zig_version = "0.14.0",
} }

View File

@ -35,10 +35,10 @@ pub fn main() !void {
if (res.args.version != 0) return std.debug.print(version_string, .{}); if (res.args.version != 0) return std.debug.print(version_string, .{});
var reader: std.io.AnyReader = undefined; var reader: std.io.AnyReader = undefined;
if (res.positionals.len < 1 or std.mem.eql(u8, res.positionals[0], "-")) { if (res.positionals.len < 1 or std.mem.eql(u8, res.positionals[0].?, "-")) {
reader = std.io.getStdIn().reader().any(); reader = std.io.getStdIn().reader().any();
} else { } else {
const filename = res.positionals[0]; const filename = res.positionals[0].?;
const cwd = std.fs.cwd(); const cwd = std.fs.cwd();
reader = (cwd.openFile(filename, .{}) catch errorexit(13, "failed to open file D:\n")).reader().any(); reader = (cwd.openFile(filename, .{}) catch errorexit(13, "failed to open file D:\n")).reader().any();
} }
@ -57,7 +57,7 @@ pub fn main() !void {
gpa.allocator().free(data); gpa.allocator().free(data);
try stdout.writeByte('\n'); //try stdout.writeByte('\n');
try bw.flush(); try bw.flush();
} }
@ -146,7 +146,7 @@ fn enter_block(blocktype: md4c.MD_BLOCKTYPE, detail: ?*anyopaque, userdata: ?*an
state.update_style(temp_style); state.update_style(temp_style);
} }
if (blocktype == md4c.MD_BLOCK_UL or blocktype == md4c.MD_BLOCK_OL) { if (blocktype == md4c.MD_BLOCK_UL or blocktype == md4c.MD_BLOCK_OL) {
just_write(state.writer, "\n"); //just_write(state.writer, "\n");
} }
return 0; // TODO what does the return value represent ???? return 0; // TODO what does the return value represent ????
} }
@ -158,6 +158,7 @@ fn leave_block(blocktype: md4c.MD_BLOCKTYPE, detail: ?*anyopaque, userdata: ?*an
just_write(state.writer, "\n\n"); just_write(state.writer, "\n\n");
} }
if (blocktype == md4c.MD_BLOCK_P or blocktype == md4c.MD_BLOCK_LI) { if (blocktype == md4c.MD_BLOCK_P or blocktype == md4c.MD_BLOCK_LI) {
//if (blocktype == md4c.MD_BLOCK_P) {
just_write(state.writer, "\n"); just_write(state.writer, "\n");
} }
if (blocktype == md4c.MD_BLOCK_HR) { if (blocktype == md4c.MD_BLOCK_HR) {
@ -171,7 +172,7 @@ fn leave_block(blocktype: md4c.MD_BLOCKTYPE, detail: ?*anyopaque, userdata: ?*an
var winsize: std.c.winsize = undefined; var winsize: std.c.winsize = undefined;
if (std.c.ioctl(term_fd, std.c.T.IOCGWINSZ, &winsize) != -1) { if (std.c.ioctl(term_fd, std.c.T.IOCGWINSZ, &winsize) != -1) {
for (0..winsize.ws_col) |_| { for (0..winsize.col) |_| {
just_write(state.writer, "-"); just_write(state.writer, "-");
} }
just_write(state.writer, "\n"); just_write(state.writer, "\n");
@ -184,7 +185,7 @@ fn leave_block(blocktype: md4c.MD_BLOCKTYPE, detail: ?*anyopaque, userdata: ?*an
state.update_style(temp_style); state.update_style(temp_style);
} }
if (blocktype == md4c.MD_BLOCK_UL or blocktype == md4c.MD_BLOCK_OL) { if (blocktype == md4c.MD_BLOCK_UL or blocktype == md4c.MD_BLOCK_OL) {
just_write(state.writer, "\n"); //just_write(state.writer, "\n");
} }
_ = detail; _ = detail;
return 0; // TODO what does the return value represent ???? return 0; // TODO what does the return value represent ????
@ -267,7 +268,7 @@ fn on_text(texttype: md4c.MD_TEXTTYPE, text: [*c]const md4c.MD_CHAR, size: md4c.
if (texttype == md4c.MD_TEXT_NULLCHAR) { if (texttype == md4c.MD_TEXT_NULLCHAR) {
just_write(state.writer, "<EFBFBD>"); just_write(state.writer, "<EFBFBD>");
} }
if (texttype == md4c.MD_TEXT_BR) { if (texttype == md4c.MD_TEXT_BR or texttype == md4c.MD_TEXT_SOFTBR) {
just_write(state.writer, "\n"); just_write(state.writer, "\n");
} }
if (texttype == md4c.MD_TEXT_CODE) { if (texttype == md4c.MD_TEXT_CODE) {
@ -285,7 +286,7 @@ fn on_text(texttype: md4c.MD_TEXTTYPE, text: [*c]const md4c.MD_CHAR, size: md4c.
const parser: md4c.MD_PARSER = .{ const parser: md4c.MD_PARSER = .{
.abi_version = @intCast(0), .abi_version = @intCast(0),
.flags = md4c.MD_FLAG_UNDERLINE | md4c.MD_FLAG_STRIKETHROUGH | md4c.MD_FLAG_COLLAPSEWHITESPACE | md4c.MD_FLAG_TASKLISTS | md4c.MD_FLAG_UNDERLINE, .flags = md4c.MD_FLAG_UNDERLINE | md4c.MD_FLAG_STRIKETHROUGH | md4c.MD_FLAG_TASKLISTS | md4c.MD_FLAG_UNDERLINE,
.enter_block = &enter_block, .enter_block = &enter_block,
.leave_block = &leave_block, .leave_block = &leave_block,