WIP: exec element with initial implementation

Problem is that the main application actually does not create a pty and
instead uses the current one (for better compatability for ssh based
hosting).

The current problem is the fact that the child process should not
take over (and never give back too) the input / output handling of the
current pts. Such that both applications can receive inputs accordingly
(in best case actually controlled by the main application).
This commit is contained in:
2025-04-01 21:56:10 +02:00
parent bce134f052
commit efb11d5c0c
3 changed files with 267 additions and 13 deletions

View File

@@ -87,6 +87,19 @@ pub fn main() !void {
}, quit_text.element());
try container.append(try App.Container.init(allocator, .{}, scrollable.element()));
var environment = try std.process.getEnvMap(allocator);
defer environment.deinit();
var editor: App.Exec = .init(
allocator,
&.{
"tty",
},
&environment,
&app.queue,
);
defer editor.deinit();
try container.append(try App.Container.init(allocator, .{
.border = .{
.color = .light_blue,
@@ -95,7 +108,7 @@ pub fn main() !void {
.size = .{
.dim = .{ .x = 100 },
},
}, .{}));
}, editor.element()));
try container.append(try App.Container.init(allocator, .{
.rectangle = .{ .fill = .blue },
.size = .{
@@ -107,6 +120,11 @@ pub fn main() !void {
try app.start();
defer app.stop() catch |err| log.err("Failed to stop application: {any}", .{err});
var process_in: std.ArrayListUnmanaged(u8) = .empty;
defer process_in.deinit(allocator);
var process_out: std.ArrayListUnmanaged(u8) = .empty;
defer process_out.deinit(allocator);
// event loop
while (true) {
const event = app.nextEvent();
@@ -117,18 +135,18 @@ pub fn main() !void {
.key => |key| {
if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit();
if (key.eql(.{ .cp = 'n', .mod = .{ .ctrl = true } })) {
try app.interrupt();
defer app.start() catch @panic("could not start app event loop");
var child = std.process.Child.init(&.{"hx"}, allocator);
_ = child.spawnAndWait() catch |err| app.postEvent(.{
.err = .{
.err = err,
.msg = "Spawning $EDITOR failed",
},
});
continue;
}
// if (key.eql(.{ .cp = 'n', .mod = .{ .ctrl = true } })) {
// try app.interrupt();
// defer renderer.clear() catch {};
// defer app.start() catch @panic("could not start app event loop");
// var child = std.process.Child.init(&.{"hx"}, allocator);
// _ = child.spawnAndWait() catch |err| app.postEvent(.{
// .err = .{
// .err = err,
// .msg = "Spawning $EDITOR failed",
// },
// });
// }
},
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),