feat(mobile): Add terminal powered by libghostty (#2056)
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
d686613e34
commit
da6ea88331
84 files changed
+10510
-66
No files matched your search
@@ -440,6 +440,32 @@ it.layer(NodeServices.layer, { excludeTestServices: true })("TerminalManager", (
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("restarts a running session when open is called with a different cwd", () =>
|
||||
Effect.gen(function* () {
|
||||
const { manager, ptyAdapter, logsDir, baseDir } = yield* createManager();
|
||||
const originalCwd = path.join(baseDir, "original");
|
||||
const differentCwd = path.join(baseDir, "different");
|
||||
yield* makeDirectory(originalCwd);
|
||||
yield* makeDirectory(differentCwd);
|
||||
|
||||
yield* manager.open(openInput({ cwd: originalCwd }));
|
||||
const firstProcess = ptyAdapter.processes[0];
|
||||
expect(firstProcess).toBeDefined();
|
||||
if (!firstProcess) return;
|
||||
|
||||
firstProcess.emitData("before reopen\n");
|
||||
yield* waitFor(pathExists(historyLogPath(logsDir)));
|
||||
|
||||
const reopened = yield* manager.open(openInput({ cwd: differentCwd }));
|
||||
|
||||
expect(ptyAdapter.spawnInputs).toHaveLength(2);
|
||||
assert.equal(firstProcess.killed, true);
|
||||
assert.equal(reopened.cwd, differentCwd);
|
||||
assert.equal(reopened.history, "");
|
||||
yield* waitFor(Effect.map(readFileString(historyLogPath(logsDir)), (text) => text === ""));
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("propagates explicit worktree metadata through snapshots and lifecycle events", () =>
|
||||
Effect.gen(function* () {
|
||||
const { manager, getEvents, baseDir } = yield* createManager();
|
||||
@@ -778,6 +804,21 @@ it.layer(NodeServices.layer, { excludeTestServices: true })("TerminalManager", (
|
||||
}).pipe(Effect.provide(TestClock.layer())),
|
||||
);
|
||||
|
||||
it.effect("publishes closed events when terminals are explicitly closed", () =>
|
||||
Effect.gen(function* () {
|
||||
const { manager, getEvents } = yield* createManager();
|
||||
yield* manager.open(openInput({ terminalId: "default" }));
|
||||
yield* manager.open(openInput({ terminalId: "sidecar" }));
|
||||
|
||||
yield* manager.close({ threadId: "thread-1" });
|
||||
|
||||
const closedEvents = (yield* getEvents).filter(
|
||||
(event): event is Extract<TerminalEvent, { type: "closed" }> => event.type === "closed",
|
||||
);
|
||||
expect(closedEvents.map((event) => event.terminalId).sort()).toEqual(["default", "sidecar"]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("evicts oldest inactive terminal sessions when retention limit is exceeded", () =>
|
||||
Effect.gen(function* () {
|
||||
const { manager, ptyAdapter, logsDir, getEvents } = yield* createManager(5, {
|
||||
|
||||
@@ -1484,15 +1484,24 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
|
||||
|
||||
yield* flushPersist(threadId, terminalId);
|
||||
|
||||
yield* modifyManagerState((state) => {
|
||||
const removed = yield* modifyManagerState((state) => {
|
||||
if (!state.sessions.has(key)) {
|
||||
return [undefined, state] as const;
|
||||
return [false, state] as const;
|
||||
}
|
||||
const sessions = new Map(state.sessions);
|
||||
sessions.delete(key);
|
||||
return [undefined, { ...state, sessions }] as const;
|
||||
return [true, { ...state, sessions }] as const;
|
||||
});
|
||||
|
||||
if (removed) {
|
||||
yield* publishEvent({
|
||||
type: "closed",
|
||||
threadId,
|
||||
terminalId,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
if (deleteHistoryOnClose) {
|
||||
yield* deleteHistory(threadId, terminalId);
|
||||
}
|
||||
@@ -1683,11 +1692,19 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
|
||||
const targetCols = input.cols ?? liveSession.cols;
|
||||
const targetRows = input.rows ?? liveSession.rows;
|
||||
const runtimeEnvChanged = !Equal.equals(currentRuntimeEnv, nextRuntimeEnv);
|
||||
const nextWorktreePath =
|
||||
input.worktreePath !== undefined
|
||||
? (input.worktreePath ?? null)
|
||||
: liveSession.worktreePath;
|
||||
const launchContextChanged =
|
||||
liveSession.cwd !== input.cwd ||
|
||||
runtimeEnvChanged ||
|
||||
liveSession.worktreePath !== nextWorktreePath;
|
||||
|
||||
if (liveSession.cwd !== input.cwd || runtimeEnvChanged) {
|
||||
if (launchContextChanged) {
|
||||
yield* stopProcess(liveSession);
|
||||
liveSession.cwd = input.cwd;
|
||||
liveSession.worktreePath = input.worktreePath ?? null;
|
||||
liveSession.worktreePath = nextWorktreePath;
|
||||
liveSession.runtimeEnv = nextRuntimeEnv;
|
||||
liveSession.history = "";
|
||||
liveSession.pendingHistoryControlSequence = "";
|
||||
@@ -1701,7 +1718,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
|
||||
);
|
||||
} else if (liveSession.status === "exited" || liveSession.status === "error") {
|
||||
liveSession.runtimeEnv = nextRuntimeEnv;
|
||||
liveSession.worktreePath = input.worktreePath ?? null;
|
||||
liveSession.worktreePath = nextWorktreePath;
|
||||
liveSession.history = "";
|
||||
liveSession.pendingHistoryControlSequence = "";
|
||||
liveSession.pendingProcessEvents = [];
|
||||
|
||||
Reference in new issue
Block a user