Archived
Prevent terminal replay from sending input
This commit is contained in:
@@ -25,7 +25,7 @@ export function registerTerminalRoutes(app: FastifyInstance, terminals: Terminal
|
||||
let detach: (() => void) | undefined;
|
||||
try {
|
||||
detach = terminals.attach(request.params.terminalId, {
|
||||
output: (data) => { socket.send(JSON.stringify({ type: "output", data })); },
|
||||
output: (data, replay) => { socket.send(JSON.stringify({ type: "output", data, replay })); },
|
||||
exit: (exitCode) => { socket.send(JSON.stringify({ type: "exit", exitCode })); },
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -76,11 +76,11 @@ export class TerminalService {
|
||||
return terminal === undefined ? undefined : toInfo(terminal);
|
||||
}
|
||||
|
||||
attach(id: string, handlers: { output: (data: string) => void; exit: (exitCode: number | undefined) => void }): () => void {
|
||||
attach(id: string, handlers: { output: (data: string, replay: boolean) => void; exit: (exitCode: number | undefined) => void }): () => void {
|
||||
const terminal = this.require(id);
|
||||
if (terminal.buffer !== "") handlers.output(terminal.buffer);
|
||||
if (terminal.buffer !== "") handlers.output(terminal.buffer, true);
|
||||
if (terminal.exited) handlers.exit(terminal.exitCode);
|
||||
const onOutput = (data: string) => { handlers.output(data); };
|
||||
const onOutput = (data: string) => { handlers.output(data, false); };
|
||||
const onExit = (exitCode: number | undefined) => { handlers.exit(exitCode); };
|
||||
terminal.events.on("output", onOutput);
|
||||
terminal.events.on("exit", onExit);
|
||||
|
||||
Reference in New Issue
Block a user