Prove multi-file terminal coding loop
This commit is contained in:
+23
-4
@@ -474,6 +474,10 @@ pub const Client = struct {
|
||||
return self.saved_bytes orelse Error.NothingSaved;
|
||||
}
|
||||
|
||||
pub fn currentPath(self: *const Client) ?[]const u8 {
|
||||
return self.current_path;
|
||||
}
|
||||
|
||||
pub fn snapshotBytesAlloc(self: *const Client, allocator: std.mem.Allocator) ![]u8 {
|
||||
const snap = try self.session.snapshot();
|
||||
return allocator.dupe(u8, snap.bytes);
|
||||
@@ -487,6 +491,10 @@ pub const Client = struct {
|
||||
return self.discard_on_quit;
|
||||
}
|
||||
|
||||
pub fn openFilePicker(self: *Client) !void {
|
||||
try self.openFilePickerPanel();
|
||||
}
|
||||
|
||||
pub fn clearQuit(self: *Client) void {
|
||||
self.quit = false;
|
||||
self.discard_on_quit = false;
|
||||
@@ -669,11 +677,18 @@ pub const Client = struct {
|
||||
const path = repo_mod.gitPathFromStatusRow(selected) catch return Error.ProtocolRejected;
|
||||
const content = repo_mod.readRepoFileAlloc(self.allocator, io, cwd, path) catch return Error.ProtocolRejected;
|
||||
defer self.allocator.free(content);
|
||||
try self.session.openFixture(content);
|
||||
try self.openRepoContentAtPath(path, content, 0);
|
||||
try self.session.closePanel();
|
||||
self.message = null;
|
||||
}
|
||||
|
||||
fn openRepoContentAtPath(self: *Client, path: []const u8, content: []const u8, cursor: usize) !void {
|
||||
if (self.current_path) |old| self.allocator.free(old);
|
||||
self.current_path = try self.allocator.dupe(u8, path);
|
||||
try self.session.openFixtureAt(content, cursor);
|
||||
self.message = null;
|
||||
}
|
||||
|
||||
fn openJobRun(self: *Client, cwd_and_command: []const u8) !void {
|
||||
const io = self.io orelse return Error.ProtocolRejected;
|
||||
const split = splitCwdAndCommand(cwd_and_command) orelse return Error.ProtocolRejected;
|
||||
@@ -2239,9 +2254,13 @@ pub const Client = struct {
|
||||
self.message = "quit:discard";
|
||||
},
|
||||
.open => |path| {
|
||||
const line = try std.fmt.allocPrint(self.allocator, "open {s}", .{path});
|
||||
defer self.allocator.free(line);
|
||||
try self.applyProtocol(line);
|
||||
if (self.repo.content(path)) |content| {
|
||||
try self.openRepoContentAtPath(path, content, 0);
|
||||
} else |_| {
|
||||
const line = try std.fmt.allocPrint(self.allocator, "open {s}", .{path});
|
||||
defer self.allocator.free(line);
|
||||
try self.applyProtocol(line);
|
||||
}
|
||||
},
|
||||
.symbol => |symbol| try self.applyProtocol(symbol_mod.protocolCommand(symbol)),
|
||||
.file_picker => try self.openFilePickerPanel(),
|
||||
|
||||
Reference in New Issue
Block a user