@@ -5,8 +5,15 @@ import { getProcessTty } from '../utils/process';
55const execAsync = promisify ( exec ) ;
66const execFileAsync = promisify ( execFile ) ;
77
8+ export enum TerminalType {
9+ TMUX = 'tmux' ,
10+ ITERM2 = 'iterm2' ,
11+ TERMINAL_APP = 'terminal-app' ,
12+ UNKNOWN = 'unknown' ,
13+ }
14+
815export interface TerminalLocation {
9- type : 'tmux' | 'iterm2' | 'terminal-app' | 'unknown' ;
16+ type : TerminalType ;
1017 identifier : string ; // e.g., "session:window.pane" for tmux, or TTY for others
1118 tty : string ; // e.g., "/dev/ttys030"
1219}
@@ -39,7 +46,7 @@ export class TerminalFocusManager {
3946
4047 // 4. Fallback: we know the TTY but not the emulator wrapper
4148 return {
42- type : 'unknown' ,
49+ type : TerminalType . UNKNOWN ,
4350 identifier : '' ,
4451 tty : fullTty
4552 } ;
@@ -51,11 +58,11 @@ export class TerminalFocusManager {
5158 async focusTerminal ( location : TerminalLocation ) : Promise < boolean > {
5259 try {
5360 switch ( location . type ) {
54- case 'tmux' :
61+ case TerminalType . TMUX :
5562 return await this . focusTmuxPane ( location . identifier ) ;
56- case 'iterm2' :
63+ case TerminalType . ITERM2 :
5764 return await this . focusITerm2Session ( location . tty ) ;
58- case 'terminal-app' :
65+ case TerminalType . TERMINAL_APP :
5966 return await this . focusTerminalAppWindow ( location . tty ) ;
6067 default :
6168 return false ;
@@ -78,7 +85,7 @@ export class TerminalFocusManager {
7885 const [ paneTty , identifier ] = line . split ( '|' ) ;
7986 if ( paneTty === tty && identifier ) {
8087 return {
81- type : 'tmux' ,
88+ type : TerminalType . TMUX ,
8289 identifier,
8390 tty
8491 } ;
@@ -113,7 +120,7 @@ export class TerminalFocusManager {
113120 const { stdout } = await execAsync ( `osascript -e '${ script } '` ) ;
114121 if ( stdout . trim ( ) === "found" ) {
115122 return {
116- type : 'iterm2' ,
123+ type : TerminalType . ITERM2 ,
117124 identifier : tty ,
118125 tty
119126 } ;
@@ -145,7 +152,7 @@ export class TerminalFocusManager {
145152 const { stdout } = await execAsync ( `osascript -e '${ script } '` ) ;
146153 if ( stdout . trim ( ) === "found" ) {
147154 return {
148- type : 'terminal-app' ,
155+ type : TerminalType . TERMINAL_APP ,
149156 identifier : tty ,
150157 tty
151158 } ;
0 commit comments