mod: read file from argument for diff contents
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m26s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m26s
For example you can run the following bash command: ```bash tui-diff <(git diff) ``` With this command you create a temporary file containing contents of the `git diff` command and is provided to `tui-diff` to open and render.
This commit is contained in:
37
src/main.zig
37
src/main.zig
@@ -120,6 +120,13 @@ pub fn main() !void {
|
|||||||
else => area.allocator(),
|
else => area.allocator(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var threaded_io: std.Io.Threaded = .init(allocator, .{});
|
||||||
|
errdefer threaded_io.deinit();
|
||||||
|
const io = threaded_io.io();
|
||||||
|
|
||||||
|
var diff_input: [:0]u8 = undefined;
|
||||||
|
defer allocator.free(diff_input);
|
||||||
|
|
||||||
// argument handling
|
// argument handling
|
||||||
{
|
{
|
||||||
var arg_it = try std.process.argsWithAllocator(allocator);
|
var arg_it = try std.process.argsWithAllocator(allocator);
|
||||||
@@ -127,21 +134,39 @@ pub fn main() !void {
|
|||||||
|
|
||||||
// TODO may there be other options?
|
// TODO may there be other options?
|
||||||
// usage: tui-diff
|
// usage: tui-diff
|
||||||
|
|
||||||
// skip own executable name
|
// skip own executable name
|
||||||
_ = arg_it.skip();
|
_ = arg_it.skip();
|
||||||
|
|
||||||
|
// only handle the first argument otherwise ignore!
|
||||||
|
if (arg_it.next()) |file| {
|
||||||
|
var buffer: [4096]u8 = undefined;
|
||||||
|
var stream = std.Io.File.readerStreaming(
|
||||||
|
try std.Io.Dir.openFileAbsolute(
|
||||||
|
io,
|
||||||
|
file,
|
||||||
|
.{ .mode = .read_only },
|
||||||
|
),
|
||||||
|
io,
|
||||||
|
&buffer,
|
||||||
|
);
|
||||||
|
const reader = &stream.interface;
|
||||||
|
diff_input = try reader.allocRemainingAlignedSentinel(
|
||||||
|
allocator,
|
||||||
|
.unlimited,
|
||||||
|
.of(u8),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// TODO detect VCS in the current working directory (and traversing upwards if none found at point?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// tui creation
|
// tui creation
|
||||||
errdefer |err| log.err("Application Error: {any}", .{err});
|
errdefer |err| log.err("Application Error: {any}", .{err});
|
||||||
|
|
||||||
var threaded_io: std.Io.Threaded = .init(allocator, .{});
|
|
||||||
errdefer threaded_io.deinit();
|
|
||||||
const io = threaded_io.io();
|
|
||||||
|
|
||||||
var renderer = zterm.Renderer.Buffered.init(allocator);
|
var renderer = zterm.Renderer.Buffered.init(allocator);
|
||||||
defer renderer.deinit();
|
defer renderer.deinit();
|
||||||
|
|
||||||
var app: App = .init(io, try .init(allocator, diff));
|
var app: App = .init(io, try .init(allocator, diff_input));
|
||||||
defer app.model.deinit(allocator);
|
defer app.model.deinit(allocator);
|
||||||
|
|
||||||
var element_root: tui_diff.elements.Root(App) = .init(allocator);
|
var element_root: tui_diff.elements.Root(App) = .init(allocator);
|
||||||
|
|||||||
Reference in New Issue
Block a user