feat: add byte offset support to vim style '+' cli arguments

This adds support for using `+b{offset}` on the command line.
This commit is contained in:
CJ van den Berg 2025-09-17 22:46:35 +02:00
parent 219b8cd00a
commit 7228a604b0
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -245,10 +245,23 @@ pub fn main() anyerror!void {
defer links.deinit();
var prev: ?*file_link.Dest = null;
var line_next: ?usize = null;
var offset_next: ?usize = null;
for (positional_args.items) |arg| {
if (arg.len == 0) continue;
if (!args.literal and arg[0] == '+') {
if (arg.len > 2 and arg[1] == 'b') {
const offset = try std.fmt.parseInt(usize, arg[2..], 10);
if (prev) |p| switch (p.*) {
.file => |*file| {
file.offset = offset;
continue;
},
else => {},
};
offset_next = offset;
line_next = null;
} else {
const line = try std.fmt.parseInt(usize, arg[1..], 10);
if (prev) |p| switch (p.*) {
.file => |*file| {
@ -258,6 +271,8 @@ pub fn main() anyerror!void {
else => {},
};
line_next = line;
offset_next = null;
}
continue;
}
@ -274,6 +289,15 @@ pub fn main() anyerror!void {
else => {},
}
}
if (offset_next) |offset| {
switch (curr.*) {
.file => |*file| {
file.offset = offset;
offset_next = null;
},
else => {},
}
}
}
var have_project = false;