Detect returns the backend that SpawnTab will use for the current process environment. Exposed so callers (and tests) can inspect the choice without spawning.
()
| 71 | // process environment. Exposed so callers (and tests) can inspect the |
| 72 | // choice without spawning. |
| 73 | func Detect() Backend { |
| 74 | if Override != "" { |
| 75 | return Override |
| 76 | } |
| 77 | if os.Getenv("ZELLIJ") != "" { |
| 78 | return BackendZellij |
| 79 | } |
| 80 | if os.Getenv("KITTY_WINDOW_ID") != "" || os.Getenv("TERM") == "xterm-kitty" { |
| 81 | return BackendKitty |
| 82 | } |
| 83 | if v := os.Getenv("FLOW_TERM"); v != "" { |
| 84 | switch Backend(v) { |
| 85 | case BackendITerm, BackendTerminal, BackendZellij, BackendKitty, BackendWarp, BackendGhostty: |
| 86 | return Backend(v) |
| 87 | } |
| 88 | // Unknown value falls through to TERM_PROGRAM detection. |
| 89 | } |
| 90 | switch os.Getenv("TERM_PROGRAM") { |
| 91 | case "Apple_Terminal": |
| 92 | return BackendTerminal |
| 93 | case "iTerm.app": |
| 94 | return BackendITerm |
| 95 | case "WarpTerminal": |
| 96 | return BackendWarp |
| 97 | case "ghostty": |
| 98 | return BackendGhostty |
| 99 | default: |
| 100 | return BackendITerm |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // SpawnTab opens a tab in the auto-detected backend. The contract |
| 105 | // matches every backend's SpawnTab. |