Compare commits

...

3 Commits

Author SHA1 Message Date
9bfeea89d9 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
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.
2026-01-10 18:18:44 +01:00
b950deda6b mod(ci): update location of external setup-zig
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 58s
2026-01-08 23:26:44 +01:00
0b34a432d1 fix(lint): format using zig fmt
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 50s
2026-01-08 23:23:05 +01:00
4 changed files with 141 additions and 117 deletions

View File

@@ -15,7 +15,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup zig installation
uses: mlugg/setup-zig@v2
uses: https://codeberg.org/mlugg/setup-zig@v2
with:
version: master
- name: Lint check

View File

@@ -14,7 +14,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup zig installation
uses: mlugg/setup-zig@v2
uses: https://codeberg.org/mlugg/setup-zig@v2
with:
version: master
- name: Lint check

View File

@@ -83,7 +83,6 @@ pub fn Tree(App: type) type {
return .{ .x = width };
}
fn handle(ctx: *anyopaque, model: *App.Model, event: App.Event) !void {
const this: *@This() = @ptrCast(@alignCast(ctx));
switch (event) {

View File

@@ -120,6 +120,13 @@ pub fn main() !void {
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
{
var arg_it = try std.process.argsWithAllocator(allocator);
@@ -127,21 +134,39 @@ pub fn main() !void {
// TODO may there be other options?
// usage: tui-diff
// skip own executable name
_ = 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
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);
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);
var element_root: tui_diff.elements.Root(App) = .init(allocator);