Skip to content

Commit 9ce5864

Browse files
format
1 parent e068cbc commit 9ce5864

1 file changed

Lines changed: 114 additions & 108 deletions

File tree

src/components/terminal/terminalManager.js

Lines changed: 114 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class TerminalManager {
2323
localStorage.getItem(TERMINAL_SESSION_STORAGE_KEY),
2424
);
2525
if (!Array.isArray(stored)) return [];
26-
if (!await Terminal.isAxsRunning()){
27-
return [];
28-
}
26+
if (!(await Terminal.isAxsRunning())) {
27+
return [];
28+
}
2929
return stored
3030
.map((entry) => {
3131
if (!entry) return null;
@@ -186,52 +186,55 @@ class TerminalManager {
186186
});
187187

188188
// Wait for tab creation and setup
189-
return await new Promise((resolve, reject) => {
190-
setTimeout(async () => {
191-
try {
192-
// Mount terminal component
193-
terminalComponent.mount(terminalContainer);
194-
195-
// Connect to session if in server mode
196-
if (terminalComponent.serverMode) {
197-
await terminalComponent.connectToSession(terminalOptions.pid);
198-
} else {
199-
// For local mode, just write a welcome message
200-
terminalComponent.write(
201-
"Local terminal mode - ready for output\r\n",
202-
);
203-
}
204-
205-
// Use PID as unique ID if available, otherwise fall back to terminalId
206-
const uniqueId = terminalComponent.pid || terminalId;
207-
208-
// Setup event handlers
209-
this.setupTerminalHandlers(
210-
terminalFile,
211-
terminalComponent,
212-
uniqueId,
213-
);
214-
215-
const instance = {
216-
id: uniqueId,
217-
name: terminalName,
218-
component: terminalComponent,
219-
file: terminalFile,
220-
container: terminalContainer,
221-
};
222-
223-
this.terminals.set(uniqueId, instance);
224-
225-
if (terminalComponent.serverMode && terminalComponent.pid) {
226-
await this.persistTerminalSession(terminalComponent.pid, terminalName);
227-
}
228-
resolve(instance);
229-
} catch (error) {
230-
console.error("Failed to initialize terminal:", error);
231-
reject(error);
232-
}
233-
}, 100);
234-
});
189+
return await new Promise((resolve, reject) => {
190+
setTimeout(async () => {
191+
try {
192+
// Mount terminal component
193+
terminalComponent.mount(terminalContainer);
194+
195+
// Connect to session if in server mode
196+
if (terminalComponent.serverMode) {
197+
await terminalComponent.connectToSession(terminalOptions.pid);
198+
} else {
199+
// For local mode, just write a welcome message
200+
terminalComponent.write(
201+
"Local terminal mode - ready for output\r\n",
202+
);
203+
}
204+
205+
// Use PID as unique ID if available, otherwise fall back to terminalId
206+
const uniqueId = terminalComponent.pid || terminalId;
207+
208+
// Setup event handlers
209+
this.setupTerminalHandlers(
210+
terminalFile,
211+
terminalComponent,
212+
uniqueId,
213+
);
214+
215+
const instance = {
216+
id: uniqueId,
217+
name: terminalName,
218+
component: terminalComponent,
219+
file: terminalFile,
220+
container: terminalContainer,
221+
};
222+
223+
this.terminals.set(uniqueId, instance);
224+
225+
if (terminalComponent.serverMode && terminalComponent.pid) {
226+
await this.persistTerminalSession(
227+
terminalComponent.pid,
228+
terminalName,
229+
);
230+
}
231+
resolve(instance);
232+
} catch (error) {
233+
console.error("Failed to initialize terminal:", error);
234+
reject(error);
235+
}
236+
}, 100);
237+
});
235238
} catch (error) {
236239
console.error("Failed to create terminal:", error);
237240
throw error;
@@ -335,46 +338,46 @@ class TerminalManager {
335338
});
336339

337340
// Wait for tab creation and setup
338-
return await new Promise((resolve, reject) => {
339-
setTimeout(async () => {
340-
try {
341-
// Mount terminal component
342-
terminalComponent.mount(terminalContainer);
343-
344-
// Write initial message
345-
terminalComponent.write("🚀 Installing Terminal Environment...\r\n");
346-
terminalComponent.write(
347-
"This may take a few minutes depending on your connection.\r\n\r\n",
348-
);
349-
350-
// Setup event handlers
351-
this.setupTerminalHandlers(
352-
terminalFile,
353-
terminalComponent,
354-
terminalId,
355-
);
356-
357-
// Set up custom title for installation terminal
358-
terminalFile.setCustomTitle(
359-
() => "Installing Terminal Environment...",
360-
);
361-
362-
const instance = {
363-
id: terminalId,
364-
name: terminalName,
365-
component: terminalComponent,
366-
file: terminalFile,
367-
container: terminalContainer,
368-
};
369-
370-
this.terminals.set(terminalId, instance);
371-
resolve(instance);
372-
} catch (error) {
373-
console.error("Failed to create installation terminal:", error);
374-
reject(error);
375-
}
376-
}, 100);
377-
});
341+
return await new Promise((resolve, reject) => {
342+
setTimeout(async () => {
343+
try {
344+
// Mount terminal component
345+
terminalComponent.mount(terminalContainer);
346+
347+
// Write initial message
348+
terminalComponent.write("🚀 Installing Terminal Environment...\r\n");
349+
terminalComponent.write(
350+
"This may take a few minutes depending on your connection.\r\n\r\n",
351+
);
352+
353+
// Setup event handlers
354+
this.setupTerminalHandlers(
355+
terminalFile,
356+
terminalComponent,
357+
terminalId,
358+
);
359+
360+
// Set up custom title for installation terminal
361+
terminalFile.setCustomTitle(
362+
() => "Installing Terminal Environment...",
363+
);
364+
365+
const instance = {
366+
id: terminalId,
367+
name: terminalName,
368+
component: terminalComponent,
369+
file: terminalFile,
370+
container: terminalContainer,
371+
};
372+
373+
this.terminals.set(terminalId, instance);
374+
resolve(instance);
375+
} catch (error) {
376+
console.error("Failed to create installation terminal:", error);
377+
reject(error);
378+
}
379+
}, 100);
380+
});
378381
}
379382

380383
/**
@@ -486,25 +489,28 @@ class TerminalManager {
486489
};
487490

488491
terminalComponent.onTitleChange = async (title) => {
489-
if (title) {
490-
// Format terminal title as "Terminal ! - title"
491-
const formattedTitle = `Terminal ${this.terminalCounter} - ${title}`;
492-
terminalFile.filename = formattedTitle;
493-
494-
if (terminalComponent.serverMode && terminalComponent.pid) {
495-
await this.persistTerminalSession(terminalComponent.pid, formattedTitle);
496-
}
497-
498-
// Refresh the header subtitle if this terminal is active
499-
if (
500-
editorManager.activeFile &&
501-
editorManager.activeFile.id === terminalFile.id
502-
) {
503-
// Force refresh of the header subtitle
504-
terminalFile.setCustomTitle(getTerminalTitle);
505-
}
506-
}
507-
};
492+
if (title) {
493+
// Format terminal title as "Terminal ! - title"
494+
const formattedTitle = `Terminal ${this.terminalCounter} - ${title}`;
495+
terminalFile.filename = formattedTitle;
496+
497+
if (terminalComponent.serverMode && terminalComponent.pid) {
498+
await this.persistTerminalSession(
499+
terminalComponent.pid,
500+
formattedTitle,
501+
);
502+
}
503+
504+
// Refresh the header subtitle if this terminal is active
505+
if (
506+
editorManager.activeFile &&
507+
editorManager.activeFile.id === terminalFile.id
508+
) {
509+
// Force refresh of the header subtitle
510+
terminalFile.setCustomTitle(getTerminalTitle);
511+
}
512+
}
513+
};
508514

509515
terminalComponent.onProcessExit = (exitData) => {
510516
// Format exit message based on exit code and signal

0 commit comments

Comments
 (0)