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:
parent
219b8cd00a
commit
7228a604b0
1 changed files with 33 additions and 9 deletions
42
src/main.zig
42
src/main.zig
|
@ -245,19 +245,34 @@ 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] == '+') {
|
||||
const line = try std.fmt.parseInt(usize, arg[1..], 10);
|
||||
if (prev) |p| switch (p.*) {
|
||||
.file => |*file| {
|
||||
file.line = line;
|
||||
continue;
|
||||
},
|
||||
else => {},
|
||||
};
|
||||
line_next = line;
|
||||
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| {
|
||||
file.line = line;
|
||||
continue;
|
||||
},
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue