90 lines
2.3 KiB
Zig
90 lines
2.3 KiB
Zig
pub var gargs: []const [:0]const u8 = undefined;
|
|
|
|
pub const Opts = struct {
|
|
targetFile: ?[]const u8 = null,
|
|
|
|
pub fn parse() @This() {
|
|
const ParseState = enum {
|
|
exe,
|
|
targetFile,
|
|
end,
|
|
};
|
|
|
|
var opts: Opts = .{};
|
|
|
|
var state: ParseState = .exe;
|
|
for (gargs) |arg| {
|
|
switch (state) {
|
|
.exe => state = .targetFile,
|
|
.targetFile => {
|
|
opts.targetFile = arg;
|
|
state = .end;
|
|
},
|
|
.end => {},
|
|
}
|
|
}
|
|
|
|
return opts;
|
|
}
|
|
};
|
|
|
|
var stdoutb: [4096]u8 = undefined;
|
|
var stdoutw: std.Io.File.Writer = undefined;
|
|
var stdout: *std.Io.Writer = undefined;
|
|
|
|
fn print(comptime fmt: []const u8, args: anytype) void {
|
|
stdout.print(fmt, args) catch {};
|
|
stdout.flush() catch {};
|
|
}
|
|
|
|
fn println(comptime fmt: []const u8, args: anytype) void {
|
|
stdout.print(fmt ++ "\n", args) catch {};
|
|
stdout.flush() catch {};
|
|
}
|
|
|
|
fn initStdout(io: std.Io) void {
|
|
stdoutw = std.Io.File.stdout().writer(io, &stdoutb);
|
|
stdout = &stdoutw.interface;
|
|
}
|
|
|
|
pub fn usage() void {}
|
|
|
|
pub fn main(init: std.process.Init) !void {
|
|
const io = init.io;
|
|
|
|
gargs = try init.minimal.args.toSlice(init.arena.allocator());
|
|
|
|
const opts = Opts.parse();
|
|
if (opts.targetFile == null) {
|
|
usage();
|
|
return error.MissingTargetFile;
|
|
}
|
|
|
|
initStdout(io);
|
|
|
|
const targetfile = opts.targetFile.?;
|
|
print("reading file: '{s}' \n", .{targetfile});
|
|
const logDirPath = std.fs.path.dirname(targetfile) orelse ".";
|
|
print("dir name: '{s}' \n", .{logDirPath});
|
|
|
|
const logDir = try std.Io.Dir.cwd().openDir(io, logDirPath, .{});
|
|
defer logDir.close(io);
|
|
|
|
const basepath = std.fs.path.basename(targetfile);
|
|
var logs: slugger.LoadedLogs = undefined;
|
|
|
|
try logs.init(io, init.arena.allocator(), logDir, basepath);
|
|
defer logs.deinit();
|
|
|
|
var readBuffer: [1024]u8 = undefined;
|
|
const frame = try logs.readNextFrame(init.arena.allocator());
|
|
|
|
for (frame) |l| {
|
|
const rendered = try l.renderBufferOptions(logs.mem(), &readBuffer, .{ .colormode = .ascii_codes });
|
|
print("{s}", .{rendered});
|
|
}
|
|
}
|
|
const std = @import("std");
|
|
const core = @import("core");
|
|
const slugger = core.slugger;
|